How does a Hash Table work?
Understand the differences between direct address table and hash table, implement a Hashmap from Scratch
A hash table is a dynamic set that supports the dictionary operations of INSERT, SEARCH, and DELETE with average O(1) time complexity.
How does a hash table work under the hood? Let’s figure it out in this post.
Direct Address Table
To understand a hash table, the direct address table is the first concept we should understand.
The direct address table uses the key directly as an index to a slot in an array. The size of universe keys is equal to the size of the array. It is really fast to access this key in O(1) time because an array supports random access operations.
However, there are four considerations before implementing an direct address table:
- To be an valid array index, the keys should be integers
- The universe of the keys is fairly small, otherwise, we will need a giant array.
- Not two different keys are mapped to the same slot in the…