Double hashing is a collision resolving technique in Open Addressed Hash tables. Double hashing uses the idea of applying a second hash function to key when a collision occurs.
Double hashing can be done using :
(hash1(key) + i * hash2(key)) % TABLE_SIZE
Here hash1() and hash2() are hash functions and TABLE_SIZE
is size of hash table.
(We repeat by increasing i when collision occurs)
First hash function is typically hash1(key) = key % TABLE_SIZE
A popular second hash function is : hash2(key) = PRIME – (key % PRIME) where PRIME is a prime smaller than the TABLE_SIZE.
A good second Hash function is:
- It must never evaluate to zero
- Must make sure that all cells can be probed
36 found 100 does not exist 0 1 --> 27 2 3 4 5 --> 10 6 --> 19 7 8 9 10 --> 36 11 12 --> 64
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Convert an array to reduced form | Set 1 (Simple and Hashing)
- Cuckoo Hashing - Worst case O(1) Lookup!
- Top 20 Hashing Technique based Interview Questions
- Hashing | Set 1 (Introduction)
- Hashing | Set 2 (Separate Chaining)
- Hashing | Set 3 (Open Addressing)
- Union and Intersection of two linked lists | Set-3 (Hashing)
- Index Mapping (or Trivial Hashing) with negatives allowed
- Practice Problems on Hashing
- C++ program for hashing with chaining
- Coalesced hashing
- Majority Element | Set-2 (Hashing)
- Applications of Hashing
- Hashing in Java
- Address Calculation Sort using Hashing
- Rearrange characters in a string such that no two adjacent are same using hashing
- Extendible Hashing (Dynamic approach to DBMS)
- Area of the largest square that can be formed from the given length sticks using Hashing
- Quadratic Probing in Hashing
- Implement Phone Directory using Hashing
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : rahuliitkgp