Neocortex 🧠

Search

Search IconIcon to open search

Hash Collision Handling

Last updated Dec 31, 2021 Edit Source

Since we apply Hash Compression in Hash Tables, hash collisions may occur often, so handling the collisions becomes critical in order to sustain an efficient time complexity.

# Seperate Chaining

In this method, each entry in an array points to a linked list. This method works, but it makes this implementation susceptible to running in $O(n)$ time if every element added to the map has the same hash value. In order to prevent this, the $\lambda$ of this map, ($\lambda = n/N$) where $n$ is the number of elements in an array, and $N$ is the size of the map. In order to sustain an efficient hash map, the load factor must be kept under 1.

# Open Addressing

In order to avoid using buckets, we can instead use the array itself to store the colliding elements. Even though it is not as easy as seperate chaining, it uses less space.


Interactive Graph