World's most popular travel blog for travel bloggers.

How to tell which value belongs to the key during hashing

, , No Comments
Problem Detail: 

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

Asked By : Computernerd
Answered By : Priyatham

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.

Best Answer from StackOverflow

Question Source :

3200 people like this

 Download Related Notes/Documents


Post a Comment

Let us know your responses and feedback