educative.io

Some words didn't understand

Hi i read this explanation but i want someone to clear is there an error by using word ‘linked list’ instead of hash map because we are in hash map section!!

In case of collision, it checks if the existing key in the bucket is equal to the key that we are trying to store. If yes, then the value of the key is updated. If the key is different, then it is added at the end of the existing key in the bucket to form a LinkedList.

There is one improvement made in Java 8. If the size of the LinkedList in a particular bucket becomes more than TREEIFY_THRESHOLD, then the LinkedList is converted to a red-black tree. TREEIFY_THRESHOLD is a constant with a default value of 8. This value can’t be changed as it is a final variable. This means that if the size of the Linked List becomes more than 8, then it is converted into a tree.


Course: https://www.educative.io/collection/6650775272947712/6368023997317120
Lesson: https://www.educative.io/collection/page/6650775272947712/6368023997317120/5062093120733184

Hi @ayman,

Just to clarify, Linkedlist is not a mistake or error in this lesson.

When a hash function maps multiple keys to the same index in the hash table, a collision occurs. To handle collisions, one common approach is to use a technique called separate chaining.

In separate chaining, each slot in the hash table contains a linked list of all the key-value pairs that hash to that slot. When a collision occurs, a new key-value pair is added to the linked list for that slot. To look up a key in the hash table, we first compute its hash code, then traverse the linked list at the corresponding slot to find the key-value pair with the matching key.

I hope this helps.

1 Like