To prevent collisions in Hash table , seperate chaining with linked list is used . Hash table works by hashing the key and storing the value in the bucket.

Assuming 4 keys hash to the same bucket , and the bucket has a linked list which has 4 nodes , how would we know which value belong to the key when we try to search for the value of the key .

For eg : These 4 key-value :a:4 , b:3 , c:2 , d:1 , hash to bucket 23. At bucket 23 , there is a linked list of values : 4 , 3 , 2 , 1 , how would we know which values belong to which key


You don't just store the values, you store them along with the keys. So when you search for a key in the linked list you traverse through the list and look for the key you want.

| cite | improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.