How should I implement the search function for all the keys that exists if I have a Hash Table that uses Linear Probing to handle collisions?

78 views Asked by At

According to my understanding of linear probing, if I don't find the key:value that I'm looking for, I should just go on to the next spot in the hash table. So I can stop at the first key that matches the result I've found and return that result and it would be somewhat efficient.

But what if there's multiple identical keys that I need to retrieve? Then I couldn't just stop at the first result that's matching the key. I would have to iterate through the entire hash table which defeats the point of having a hash table.

What's the best way to do this? Is this possible with linear probing? or would I absolutely have to use a different way to handle collisions like chaining so that the results are all on the same linked list?

0

There are 0 answers