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
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- 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)
- 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
- String hashing using Polynomial rolling hash function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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