Hashing is an improvement over Direct Access Table. The idea is to use a hash function that converts a given phone number or any other key to a smaller number and uses the small number as the index in a table called a hash table.
Hash Function: A function that converts a given big number to a small practical integer value. The mapped integer value is used as an index in the hash table. In simple terms, a hash function maps a big number or string to a small integer that can be used as an index in the hash table.
In this article, the collision technique, quadratic probing is discussed.
Quadratic Probing: Quadratic probing is an open-addressing scheme where we look for i2‘th slot in i’th iteration if the given hash vale x collides in the hash table.
How Quadratic Probing is done?
Let hash(x) be the slot index computed using the hash function.
- If the slot hash(x) % S is full, then we try (hash(x) + 1*1) % S.
- If (hash(x) + 1*1) % S is also full, then we try (hash(x) + 2*2) % S.
- If (hash(x) + 2*2) % S is also full, then we try (hash(x) + 3*3) % S.
- This process is repeated for all the values of i until an empty slot is found.
Below is the implementation of the above approach:
700 50 85 73 101 92 76
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.
- Implementing own Hash Table with Open Addressing Linear Probing in C++
- Applications of Hashing
- Coalesced hashing
- Double Hashing
- Hashing | Set 1 (Introduction)
- Hashing in Java
- C++ program for hashing with chaining
- Hashing | Set 2 (Separate Chaining)
- Hashing | Set 3 (Open Addressing)
- Practice Problems on Hashing
- Majority Element | Set-2 (Hashing)
- Address Calculation Sort using Hashing
- Password Hashing with MD5 module in Node.js
- Implement Phone Directory using Hashing
- Union and Intersection of two linked lists | Set-3 (Hashing)
- Cuckoo Hashing - Worst case O(1) Lookup!
- Top 20 Hashing Technique based Interview Questions
- Extendible Hashing (Dynamic approach to DBMS)
- Rearrange characters in a string such that no two adjacent are same using hashing
- Convert an array to reduced form | Set 1 (Simple and 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 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 : Rajput-Ji