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
0 1 --> 27 2 3 4 5 --> 10 6 --> 19 7 8 9 10 --> 36 11 12 --> 64
- 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
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.