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
- Load Factor and Rehashing
- C++ program for hashing with chaining
- Index Mapping (or Trivial Hashing) with negatives allowed
- Hash Table vs STL Map
- Union and Intersection of two linked lists | Set-3 (Hashing)
- Top 20 Hashing Technique based Interview Questions
- Count pairs whose products exist in array
- Count pairs with given sum
- Hashing | Set 3 (Open Addressing)
- Hashing | Set 2 (Separate Chaining)
- Find Itinerary from a given list of tickets
- Check if characters of a given string can be rearranged to form a palindrome
- Hashing | Set 1 (Introduction)
- Print a Binary Tree in Vertical Order | Set 2 (Map based Method)
- Find whether an array is subset of another array | Added Method 3
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.