I recently found out that Java 8 hash maps use a binary tree instead of a linked list, and the hash code is used as a branching factor. I understand that in the event of a high collision, the search is reduced to O (log n) from O (n) using binary trees. My question is what does this well, since the amortized time complexity is still O (1), and maybe if you force all the records to be stored in the same bucket by providing the same hash code for all keys we see a significant time difference, but no one in their right mind will do this.
The binary tree also uses more space than a singly linked list, since it stores both the left and right nodes. Gradually increase the complexity of the space when there is absolutely no improvement in temporal complexity, with the exception of some false test cases.
java hashmap java-8 theory
user1613360
source share