Understand how hash collisions occur and how Separate Chaining, Linear Probing, Quadratic Probing and Double Hashing solve them. Learn with simple examples, diagrams, a C program and university exam questions.
Hashing is useful in Data Structure because it helps us store and search for data quickly. Instead of checking every element one by one, a hash function calculates the position where a value should be stored.
However, students often become confused when two different values receive the same position in a hash table. They understand the basic hash function but get stuck when the teacher asks where the second value will go.
This problem is called a hash collision. Collision Resolution techniques help us handle it without losing the values. In this chapter, we will understand each method using the same example, so the differences are easy to remember.
Collision Resolution in Data Structure is the process of handling a situation where two or more different keys produce the same hash table index. The main techniques are Separate Chaining and Open Addressing. Open Addressing commonly uses Linear Probing, Quadratic Probing and Double Hashing.
What Is a Collision in Hashing?

A collision occurs when two different keys are mapped to the same index by a hash function.
Suppose we have a hash table containing seven positions, numbered from 0 to 6. We use this hash function:
Here, the percentage symbol (%) represents the remainder operator.
Now insert the values 10 and 17.
Both values want to use index 3. The value 10 is already stored there, so inserting 17 creates a collision.
Key 17 also wants index 3, but that position is occupied.
Why Do Collisions Occur?
- Different keys may produce the same hash value.
- A hash table has a limited number of positions.
- A poor hash function may distribute keys unevenly.
- More stored elements increase the chance of collisions.
Important: A collision does not mean that both keys are equal. Keys 10 and 17 are different, but their hash values are the same.
Why Is Collision Resolution Important?
Without a proper collision-handling method, inserting a new element could overwrite another element or fail. Collision Resolution allows the hash table to keep different keys and retrieve them correctly.
It is important for dictionary-like structures, symbol tables, caches and other systems that use hash tables for fast key-based access.
Types of Collision Resolution Techniques
Collision Resolution techniques are commonly divided into two main categories.
1. Separate Chaining
Multiple keys with the same hash index are stored together in a bucket, often using a linked list.
2. Open Addressing
When the calculated position is occupied, the algorithm searches for another position inside the hash table.
Bucket / Linked List
Linear Probing
Quadratic Probing
Double Hashing
We will use the following values throughout the examples:
Every key gives remainder 3 when divided by 7. This makes the example useful for comparing all four techniques.
Separate Chaining in Hashing
Separate Chaining is one of the simplest ways to handle collisions. Instead of finding another position in the main table, it keeps all keys belonging to the same hash index in a collection associated with that index.
A linked list is a common implementation. Each hash table entry stores a pointer to the first node of its list.
Example of Separate Chaining
Take the keys 10, 17, 24 and 31. All four keys have hash index 3.
Other hash table positions remain empty in this example. The diagram shows insertion at the end of the chain.
How Separate Chaining Works
- Calculate the hash index of the new key.
- Go to the bucket at that index.
- If it is empty, create its first node.
- If another key is present, add a new node to the chain.
- During searching, visit the nodes in that bucket until the key is found or the chain ends.
If linked lists are new to you, read Linked List in Data Structure: Types, Operations and Examples . It explains nodes, pointers, insertion and traversal.
Advantages of Separate Chaining
- It is easy to understand and implement.
- The number of keys can exceed the number of table buckets.
- Deletion is straightforward once the required node is located.
- It does not suffer from the probing clusters found in Open Addressing.
Disadvantages of Separate Chaining
- Linked-list nodes require additional memory.
- Long chains increase searching time.
- Dynamic memory allocation adds some overhead.
- Scattered nodes may reduce cache efficiency.
Exam Tip: Separate Chaining stores colliding keys in the same bucket using a separate structure. Open Addressing searches for another position within the table.
Open Addressing in Hashing
Open Addressing handles collisions by finding another available slot in the hash table itself.
Unlike Separate Chaining, it does not require a linked list for every bucket. Each stored key occupies one position inside the table.
The process of checking possible positions is called probing. The sequence of positions checked is known as the probe sequence.
How Open Addressing Works
- Calculate the hash index of the key.
- Check whether the calculated position is empty.
- If it is empty, insert the key.
- If the position is occupied, calculate another position using a probing method.
- Continue according to the probing sequence until an available position is found or insertion cannot proceed.
The three important Open Addressing methods are Linear Probing, Quadratic Probing and Double Hashing.
Linear Probing in Data Structure
Linear Probing is the easiest Open Addressing technique. When a collision occurs, it checks the next position in the hash table.
If that position is occupied, it continues checking the following positions until an empty one is found. After the last index, checking continues from index 0.
Linear Probing Formula
Here, m is the table size and i starts from 0 and increases by 1 for each probe.
Linear Probing Example
Insert 10, 17, 24 and 31 into a table of size 7.
| Key | Original Index | Checking | Final Index |
|---|---|---|---|
| 10 | 3 | 3 is empty | 3 |
| 17 | 3 | 3 occupied → 4 empty | 4 |
| 24 | 3 | 3, 4 occupied → 5 empty | 5 |
| 31 | 3 | 3, 4, 5 occupied → 6 empty | 6 |
Colliding values occupy consecutive positions.
Primary Clustering in Linear Probing
The main problem with Linear Probing is primary clustering. This happens when occupied positions form a continuous group.
In our example, indices 3, 4, 5 and 6 form a cluster. A new key whose probe sequence reaches this group may need to check several positions.
Remember: Linear Probing is simple and can use every slot, but large clusters may make searching and insertion slower.
Quadratic Probing in Data Structure
Quadratic Probing tries to reduce the continuous clusters formed by Linear Probing.
Instead of checking only the next position, it uses a quadratic expression to calculate the next index.
Quadratic Probing Formula
This is one simple form of Quadratic Probing.
More generally, an implementation may use
constants in the expression
(h(key) + c1*i + c2*i²) % m.
Quadratic Probing Example
Use the same keys and table size as before.
Each new key first checks index 3. If the position is already occupied, it follows the quadratic probe sequence.
| Key | Probe Sequence Checked | Final Index |
|---|---|---|
| 10 | 3 | 3 |
| 17 | 3 → 4 | 4 |
| 24 | 3 → 4 → 0 | 0 |
| 31 | 3 → 4 → 0 → 5 | 5 |
Keys are distributed across different positions.
Advantages of Quadratic Probing
- It reduces primary clustering compared with Linear Probing.
- It stores data directly inside the hash table.
- It does not require linked-list nodes.
Limitations of Quadratic Probing
Quadratic Probing may still suffer from secondary clustering because different keys having the same starting index follow the same probe sequence.
Another limitation is that a particular quadratic formula may not visit every table position. Insertion can therefore fail even when some positions are empty.
Exam Tip: Do not assume Quadratic Probing always finds an empty position. The table size, formula and load factor matter.
Double Hashing in Data Structure
Double Hashing uses two hash functions to handle collisions. The first hash function calculates the starting index. The second decides how far to move when a collision occurs.
The main idea is to give different keys different probe steps, even when their first hash index is the same.
Double Hashing Formula
For our example, we use:
The second hash function gives a non-zero step. Here, the table size is prime and each possible step is relatively prime to 7.
Double Hashing Example
| Key | h1(key) | h2(key) | Final Index |
|---|---|---|---|
| 10 | 3 | 1 | 3 |
| 17 | 3 | 3 | 6 |
| 24 | 3 | 5 | 1 |
| 31 | 3 | 2 | 5 |
Step-by-Step Calculation
Key 10: Index 3 is empty, so store 10 at index 3.
Key 17: Index 3 is occupied.
Index 6 is empty, so store 17 there.
Key 24: Its second hash value is 5.
Index 1 is empty, so store 24 there.
Key 31: Its second hash value is 2.
Index 5 is empty, so store 31 there.
Advantages of Double Hashing
- Different keys can have different probe sequences.
- It greatly reduces clustering problems with suitable hash functions.
- It can provide efficient table utilisation.
Limitations of Double Hashing
- Two hash calculations can add computational overhead.
- The second hash function must never produce a zero step.
- The step should be relatively prime to the table size to reach every slot.
- Performance still becomes weaker at high load factors.
Try Collision Resolution Yourself
Reading a formula is useful, but trying the values makes it easier to remember. Choose a technique below and see how the hash table changes.
Table size: 7. Initial keys: 10, 17, 24, 31. All examples use key % 7. Quadratic Probing uses i²; Double Hashing uses 1 + (key % 5).
Practice: Start with Linear Probing and insert 38. Then reset the table and try the same key using Quadratic Probing and Double Hashing. Notice how the final index changes.
Difference Between Collision Resolution Techniques
The table below compares the major methods. This is useful for semester exams and technical interviews.
| Technique | How Collision Is Handled | Main Advantage | Main Limitation |
|---|---|---|---|
| Separate Chaining | Stores colliding keys in a bucket or linked list | Flexible growth | Extra node memory |
| Linear Probing | Checks consecutive positions | Simple and cache-friendly | Primary clustering |
| Quadratic Probing | Uses quadratic offsets | Reduces primary clustering | Secondary clustering and limited probe coverage |
| Double Hashing | Uses a second hash function for step size | Better probe distribution | Careful hash function design needed |
Final Positions for the Same Four Keys
| Key | Linear | Quadratic | Double Hashing |
|---|---|---|---|
| 10 | 3 | 3 | 3 |
| 17 | 4 | 4 | 6 |
| 24 | 5 | 0 | 1 |
| 31 | 6 | 5 | 5 |
All four keys originally wanted index 3. The final positions are different because each method follows a different collision resolution rule.
Load Factor and Rehashing in Hash Tables
The load factor tells us how full a hash table is. It is an important concept because collisions and probing costs generally increase as more elements are inserted.
Load Factor Formula
Our table has 4 keys and 7 positions.
This means approximately 57% of the table's positions are occupied when Open Addressing is used.
In Separate Chaining, the same formula represents the average number of keys per bucket, not necessarily the percentage of buckets containing keys. Its load factor can exceed 1.
What Is Rehashing?
Rehashing means rebuilding the hash table, usually with a larger capacity, and reinserting the existing keys using the new table size.
For example, a table may grow from 7 positions to 17 positions. The existing keys are then placed again according to the updated hash function.
A table size increase is not just adding empty positions at the end. The keys must be placed according to the new table's hash calculations.
Time Complexity of Collision Resolution Techniques
Hash tables are popular because they can provide very fast insertion, searching and deletion. However, their performance depends on the hash function, load factor and collision-handling method.
| Technique | Expected Time* | Worst-Case Time |
|---|---|---|
| Separate Chaining | O(1) | O(n) |
| Linear Probing | O(1) | O(m) |
| Quadratic Probing | O(1) | O(m) |
| Double Hashing | O(1) | O(m) |
*Expected constant time assumes good hashing and a controlled load factor, with suitable probing design. Here n is the number of keys and m is the table capacity. Worst-case bounds refer to search, insertion or deletion work and include possible probing or chain traversal.
Space Complexity
- Separate Chaining: O(m + n) total storage for bucket references and n stored nodes.
- Open Addressing: O(m) total storage for the fixed-capacity table.
- Auxiliary space: A typical iterative single-key probing operation uses O(1) extra working space.
Common Exam Mistake: Do not write that hashing always takes O(1) time. This is an expected or average-case result under suitable conditions. The worst case can require checking many keys or positions.
Deletion in Open Addressing: Why Tombstones Matter
Deletion is a little tricky in Open Addressing. Suppose Linear Probing stores 10, 17 and 24 at indices 3, 4 and 5.
Now delete 17 from index 4. If we simply mark index 4 as a position that has never been used, searching for 24 may stop there and incorrectly report that the key is missing.
To avoid this, implementations often use a tombstone, also called a deleted marker.
Search must continue past DEL. A later insertion may reuse the deleted position.
An empty-never-used slot can stop an unsuccessful search in a normal probe sequence. A deleted slot must not stop it.
C Program for Collision Resolution Using Linear Probing
The following C program demonstrates insertion, searching and deletion in a hash table using Linear Probing.
It also handles deleted positions properly. The program accepts non-negative integer keys and rejects duplicate keys.
#include <stdio.h>
#define SIZE 7
enum SlotState {
EMPTY,
OCCUPIED,
DELETED
};
int table[SIZE];
enum SlotState state[SIZE];
int hashKey(int key) {
return key % SIZE;
}
int search(int key) {
if (key < 0)
return -1;
int start = hashKey(key);
for (int i = 0; i < SIZE; i++) {
int index = (start + i) % SIZE;
if (state[index] == EMPTY)
return -1;
if (state[index] == OCCUPIED
&& table[index] == key)
return index;
}
return -1;
}
int insert(int key) {
if (key < 0 || search(key) != -1)
return 0;
int start = hashKey(key);
int deletedIndex = -1;
for (int i = 0; i < SIZE; i++) {
int index = (start + i) % SIZE;
if (state[index] == DELETED
&& deletedIndex == -1)
deletedIndex = index;
if (state[index] == EMPTY) {
if (deletedIndex != -1)
index = deletedIndex;
table[index] = key;
state[index] = OCCUPIED;
return 1;
}
}
if (deletedIndex != -1) {
table[deletedIndex] = key;
state[deletedIndex] = OCCUPIED;
return 1;
}
return 0;
}
int deleteKey(int key) {
int index = search(key);
if (index == -1)
return 0;
state[index] = DELETED;
return 1;
}
void display(void) {
for (int i = 0; i < SIZE; i++) {
if (state[i] == OCCUPIED)
printf("Index %d: %d\n",
i, table[i]);
else if (state[i] == DELETED)
printf("Index %d: DELETED\n", i);
else
printf("Index %d: EMPTY\n", i);
}
}
int main(void) {
int keys[] = {10, 17, 24, 31};
for (int i = 0; i < 4; i++)
insert(keys[i]);
printf("After insertion:\n");
display();
printf("Search 24: index %d\n",
search(24));
deleteKey(17);
printf("Search 24 after deletion: index %d\n",
search(24));
insert(38);
printf("After inserting 38:\n");
display();
return 0;
}
Output of the C Program
After insertion:
Index 0: EMPTY
Index 1: EMPTY
Index 2: EMPTY
Index 3: 10
Index 4: 17
Index 5: 24
Index 6: 31
Search 24: index 5
Search 24 after deletion: index 5
After inserting 38:
Index 0: EMPTY
Index 1: EMPTY
Index 2: EMPTY
Index 3: 10
Index 4: 38
Index 5: 24
Index 6: 31
Explanation of the Program
hashKey(): Calculates the starting position using the remainder operator.
insert(): Finds a suitable empty or deleted slot by checking positions in Linear Probing order. It also prevents duplicate keys.
search(): Checks the probe sequence until the value is found, an unused position is reached, or all positions have been checked.
deleteKey(): Marks the selected position as deleted without breaking future searches.
display(): Shows the current status of all seven table positions.
Why does 38 go to index 4? Its original hash index is 3. That position contains 10, but index 4 was deleted earlier. Linear Probing can reuse the deleted position.
Collision Resolution Algorithms
Algorithm: Separate Chaining
1. Read the key.
2. Calculate index = hash(key).
3. Go to the bucket at index.
4. If the bucket is empty:
Create its first node.
5. Otherwise:
Add the key to its chain.
6. Stop.
Algorithm: Linear Probing
1. Calculate index = hash(key).
2. Set i = 0.
3. Calculate:
position = (index + i) % m
4. If the position is available:
Insert the key and stop.
5. Otherwise increase i.
6. Repeat while valid positions remain.
Algorithm: Quadratic Probing
1. Calculate index = hash(key).
2. Set i = 0.
3. Calculate:
position = (index + i*i) % m
4. If the position is available:
Insert the key and stop.
5. Otherwise increase i.
6. Stop if the allowed probe
sequence has been exhausted.
Algorithm: Double Hashing
1. Calculate h1(key).
2. Calculate a valid non-zero h2(key).
3. Set i = 0.
4. Calculate:
position = (h1(key) + i*h2(key)) % m
5. If the position is available:
Insert the key and stop.
6. Otherwise increase i.
7. Repeat up to m probes.
These are simplified insertion algorithms for revision. Full implementations must also handle duplicate keys, deletion markers, capacity and resizing correctly.
Common Mistakes in Collision Resolution
| Common Mistake | Correct Explanation |
|---|---|
| Assuming a good hash function prevents every collision | A good function reduces collisions but does not eliminate all of them. |
| Confusing Separate Chaining with Linear Probing | Chaining stores colliding keys in a bucket; Linear Probing searches another table slot. |
| Using i instead of i² in Quadratic Probing | Apply the exact quadratic formula given in the question. |
| Allowing h2(key) = 0 in Double Hashing | The probe step must be non-zero and should cover the table appropriately. |
| Writing that Quadratic Probing always checks every slot | Some quadratic probe sequences visit only part of the table. |
| Making a deleted slot completely empty | Use a tombstone or a correct deletion-repair procedure. |
| Assuming O(1) worst-case time | Long chains or probe sequences may require linear work. |
Important Collision Resolution Questions and Answers
The following questions are useful for Data Structure semester examinations, practical preparation and viva. The marks are suggested answer formats, not claims about a particular university's previous-year paper.
2 Marks: Define Collision Resolution.
Collision Resolution is a technique used to handle two or more different keys that map to the same hash table index. Separate Chaining and Open Addressing are the main methods.
2 Marks: What Is Linear Probing?
Linear Probing is an Open Addressing method in which
the next table position is checked when a collision
occurs. Its formula is
(h(key) + i) % m.
5 Marks: Explain Collision Resolution Techniques.
Collision Resolution techniques are used when different keys produce the same hash index. The two main categories are:
- Separate Chaining: Stores colliding keys in the same bucket, commonly using a linked list.
- Open Addressing: Searches for another position inside the hash table. Its major methods are Linear Probing, Quadratic Probing and Double Hashing.
Linear Probing checks consecutive positions, Quadratic Probing uses quadratic offsets, and Double Hashing uses a second hash function to calculate the step size.
10 Marks: Explain Collision Resolution with an Example.
For a complete 10-mark answer, begin with the definition of collision and Collision Resolution. Explain the need for handling collisions, then describe Separate Chaining and the three Open Addressing techniques.
Use a hash table of size 7 with keys 10, 17, 24 and 31. Explain that all keys initially map to index 3. Show their final positions using Linear Probing, Quadratic Probing and Double Hashing.
Include the relevant formulas, a clear table diagram, advantages and limitations. End with a short comparison and the importance of load factor.
Exam Writing Tip: In numerical questions, show each probe calculation. Writing only the final hash table may not show how you reached the answer.
Collision Resolution Practice Questions
Practice Numerical
A hash table has 7 positions and uses
h(key) = key % 7.
Insert 14, 21, 28 and 35 using Linear Probing.
Find the final positions.
Show Solved Answer
All four keys map to index 0. Therefore, Linear Probing stores 14 at index 0, 21 at index 1, 28 at index 2 and 35 at index 3.
MCQ 1
Which technique is affected by primary clustering?
A. Separate Chaining
B. Linear Probing
C. Both A and B equally
D. None
Answer and Explanation
B. Linear Probing. Consecutive occupied positions can form clusters that increase the number of probes.
MCQ 2
Which collision method uses two hash functions?
A. Linear Probing
B. Separate Chaining
C. Double Hashing
D. Direct Addressing
Answer and Explanation
C. Double Hashing. The first function selects the home position, while the second determines the probing step.
MCQ 3
Which statement about Separate Chaining is correct?
A. It always prevents collisions
B. It uses only one element per bucket
C. Its load factor can exceed 1
D. It requires quadratic offsets
Answer and Explanation
C. Its load factor can exceed 1. Multiple keys can be stored in the same bucket, so the total number of keys may be greater than the number of buckets.
FAQs About Collision Resolution in Data Structure
What are the four common Collision Resolution techniques?
Separate Chaining, Linear Probing, Quadratic Probing and Double Hashing are four common techniques. The last three belong to Open Addressing.
Which Collision Resolution technique is best?
There is no single best technique for every situation. Separate Chaining is flexible, Linear Probing is simple, and Double Hashing can reduce clustering. The right choice depends on memory, performance, key distribution and implementation requirements.
What is the difference between Linear and Quadratic Probing?
Linear Probing checks consecutive positions using increasing offsets of 1. Quadratic Probing calculates positions using a quadratic expression, which reduces primary clustering.
Can a hash collision be completely avoided?
Not in general when the possible key values are more numerous than the table positions. Good hash functions reduce collisions, while Collision Resolution techniques handle them.
What is the difference between hashing and collision resolution?
Hashing calculates a position for a key using a hash function. Collision Resolution decides what to do when that position is already occupied by another key.
Collision Resolution Quick Revision Notes
Easy Memory Trick
Remember these four rules and practise at least one insertion example for every method. This will help you solve most basic collision resolution numericals.
Related Data Structure Concepts
Separate Chaining becomes easier when you understand linked-list nodes and pointers. You can revise Linked List in Data Structure before implementing a chained hash table.
For a deeper understanding of storing and connecting nodes, study Linked List Representation Using Arrays and Pointers .
