As
most of you are aware, when 2 keys hash to a same index in HashMap,
JAVA internally creates a Linked List internally to store the values in
JAVA 7.
The performance of the HashMap suffers a lot when the Hash Algorithm is poor or most of the data hash to the same index. If the bucket has got 100 values and the value we are trying to retrieve is in the 100th location or say greater than 50 th index, the performance of the hashmap suffers.
In-order to overcome this performance issue, JAVA 8 replaces Linked List with Balanced Tree(BST). As you are aware, in a BST , the elements that are present in the left of the root are smaller than the root and the elements that are on the right of the root are larger than the root. The time complexity to find the element in a BST is O(log n). Hence, the performance of the HashMap under worst case is increased in JAVA 8.
The performance of the HashMap suffers a lot when the Hash Algorithm is poor or most of the data hash to the same index. If the bucket has got 100 values and the value we are trying to retrieve is in the 100th location or say greater than 50 th index, the performance of the hashmap suffers.
In-order to overcome this performance issue, JAVA 8 replaces Linked List with Balanced Tree(BST). As you are aware, in a BST , the elements that are present in the left of the root are smaller than the root and the elements that are on the right of the root are larger than the root. The time complexity to find the element in a BST is O(log n). Hence, the performance of the HashMap under worst case is increased in JAVA 8.
No comments :
Post a Comment