Collision Resolution Techniques
Last Updated :
10 Mar, 2025
In Hashing, hash functions were used to generate hash values. The hash value is used to create an index for the keys in the hash table. The hash function may return the same hash value for two or more keys. When two or more keys have the same hash value, a collision happens. To handle this collision, we use Collision Resolution Techniques.

Collision Resolution Techniques
There are mainly two methods to handle collision:
- Separate Chaining
- Open Addressing

1) Separate Chaining
The idea behind Separate Chaining is to make each cell of the hash table point to a linked list of records that have the same hash function value. Chaining is simple but requires additional memory outside the table.
Example: We have given a hash function and we have to insert some elements in the hash table using a separate chaining method for collision resolution technique.
Hash function = key % 5,
Elements = 12, 15, 22, 25 and 37.
Let’s see step by step approach to how to solve the above problem:
Please You Own Hash Table with Chaining for implementation of this technique
2) Open Addressing
In open addressing, all elements are stored in the hash table itself. Each table entry contains either a record or NIL. When searching for an element, we examine the table slots one by one until the desired element is found or it is clear that the element is not in the table.
2.a) Linear Probing
In linear probing, the hash table is searched sequentially that starts from the original location of the hash. If in case the location that we get is already occupied, then we check for the next location.
Algorithm:
- Calculate the hash key. i.e. key = data % size
- Check, if hashTable[key] is empty
- store the value directly by hashTable[key] = data
- If the hash index already has some value then
- check for next index using key = (key+1) % size
- Check, if the next index is available hashTable[key] then store the value. Otherwise try for next index.
- Do the above process till we find the space.
Example: Let us consider a simple hash function as “key mod 5” and a sequence of keys that are to be inserted are 50, 70, 76, 85, 93.
Please refer Your Own Hash Table with Linear Probing in Open Addressing for implementation details.
2.b) Quadratic Probing
Quadratic probing is an open addressing scheme in computer programming for resolving hash collisions in hash tables. Quadratic probing operates by taking the original hash index and adding successive values of an arbitrary quadratic polynomial until an open slot is found.
An example sequence using quadratic probing is:
H + 1 2 , H + 2 2 , H + 3 2 , H + 4 2 …………………. H + k 2
This method is also known as the mid-square method because in this method we look for i2-th probe (slot) in i-th iteration and the value of i = 0, 1, . . . n – 1. We always start from the original hash location. If only the location is occupied then we check the other slots.
Let hash(x) be the slot index computed using the hash function and n be the size of the hash table.
If the slot hash(x) % n is full, then we try (hash(x) + 1 2 ) % n.
If (hash(x) + 1 2 ) % n is also full, then we try (hash(x) + 2 2 ) % n.
If (hash(x) + 2 2 ) % n is also full, then we try (hash(x) + 3 2 ) % n.
This process will be repeated for all the values of i until an empty slot is found
Example: Let us consider table Size = 7, hash function as Hash(x) = x % 7 and collision resolution strategy to be f(i) = i 2 . Insert = 22, 30, and 50
Please refer Your Own Hash Table with Quadratic Probing in Open Addressing for implementation.
2.c) Double Hashing
Double hashing is a collision resolving technique in Open Addressed Hash tables. Double hashing make use of two hash function,
- The first hash function is h1(k) which takes the key and gives out a location on the hash table. But if the new location is not occupied or empty then we can easily place our key.
- But in case the location is occupied (collision) we will use secondary hash-function h2(k) in combination with the first hash-function h1(k) to find the new location on the hash table.
This combination of hash functions is of the form
h(k, i) = (h1(k) + i * h2(k)) % n
where
- i is a non-negative integer that indicates a collision number,
- k = element/key which is being hashed
- n = hash table size.
Complexity of the Double hashing algorithm:
Time complexity: O(n)
Example: Insert the keys 27, 43, 692, 72 into the Hash Table of size 7. where first hash-function is h1(k) = k mod 7 and second hash-function is h2(k) = 1 + (k mod 5)
Please refer Double Hashing for Implementation.
Similar Reads
First collision point of two series
Given five numbers a, b, c, d and n (where a, b, c, d, n > 0). These values represent n terms of two series. The two series formed by these four numbers are b, b+a, b+2a....b+(n-1)a and d, d+c, d+2c, ..... d+(n-1)c These two series will collide when at any single point summation values becomes ex
7 min read
Types of Collisions
Collisions are an everyday phenomenon that occurs when two or more objects come into contact with each other, often resulting in a transfer of energy. They are classified into different types based on how energy is conserved or transformed, including elastic, inelastic, and perfectly inelastic colli
10 min read
Inelastic Collision
Inelastic Collision is a type of collision where momentum is conserved, but kinetic energy is not. In such collisions, the colliding objects stick together, and some kinetic energy is transformed into other forms like vibrational energy or heat. This results in a loss of kinetic energy, which may tr
9 min read
Elastic vs Inelastic Collision in one Dimension
During the game, you may have witnessed two billiard balls collide with each other. A collision is the violent coming together of two distinct bodies. What happens when two objects collide? Can we identify the colliding bodies' velocity or trajectory? Let us investigate! A collision occurs when two
11 min read
Collisions in Two Dimensions
A Collision occurs when a powerful force strikes on two or more bodies in a relatively short period of time. Collision is a one-time occurrence. As a result of the collision, the involved particles' energy and momentum change. The collision may occur as a result of actual physical contact between th
9 min read
Elastic Collision Formula
Elastic Collision is the collision in which the kinetic energy of the system is conserved. A collision occurs when two or more object comes in direct contact with each other. the collision can be of two types that includes, Elastic Collision and Inelastic Collision. In this article, we will learn ab
9 min read
Open Addressing Collision Handling technique in Hashing
Open Addressing is a method for handling collisions. In Open Addressing, all elements are stored in the hash table itself. So at any point, the size of the table must be greater than or equal to the total number of keys (Note that we can increase table size by copying old data if needed). This appro
7 min read
Beam Penetration Technique in Computer Graphics
Pre-requisites: CRT, Refresh type output devices in Computer Graphics The cathode ray tube (CRT) monitor displays with the help of a combination of phosphorus, as phosphorus exists in multi-color. Beam penetration is a method for producing color displays with CRT. The beam penetration technique uses
2 min read
Collision Theory
Collision Theory says that when particles collide (strike) each other, a chemical reaction occurs. However, this is necessary but may not be a sufficient condition for the chemical reaction. The collision of molecules must be sufficient to produce the desired products following the chemical reaction
7 min read
Collision Course | TCS MockVita 2020
Problem Description On a busy road, multiple cars are passing by. A simulation is run to see what happens if brakes fail for all cars on the road. The only way for them to be safe is if they don't collide and pass by each other. The goal is to identify whether any of the given cars would collide or
8 min read