top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How would you implement a hash table ? How do you deal with collisions?

+3 votes
456 views
How would you implement a hash table ? How do you deal with collisions?
posted Nov 27, 2015 by Mohammed Hussain

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Hash tables deal with collisions in one of two ways.

Option 1: By having each bucket contain a linked list of elements that are hashed to that bucket. This is why a bad hash function can make lookups in hash tables very slow.

Option 2: If the hash table entries are all full then the hash table can increase the number of buckets that it has and then redistribute all the elements in the table. The hash function returns an integer and the hash table has to take the result of the hash function and mod it against the size of the table that way it can be sure it will get to bucket. so by increasing the size it will rehash and run the modulo calculations which if you are lucky might send the objects to different buckets.

Java uses both option 1 and 2 in its hash table implementations

answer Nov 30, 2015 by Manikandan J
Similar Questions
+2 votes

Guys can someone help me by describing the skip-list and why someone should use it over BST.

+1 vote

I need a fully functional hash table with time complexity for search O(n). Can someone please help me?

...