Hashing is a mechanism for storing, finding, and eliminating items in near real-time. Double Hashing is accomplished by the use of a hash function, which creates an index for a given input, which can then be used to search the items, save an element, or delete that element from that index.
A hash function is a function that maps data components to their positions in the data structure is utilized.
For example, if we use an array to hold the integer elements, the hash function will create a location for each element such that finding, storing, and deleting operations on the array may be performed in constant time regardless of the number of items in the array.
Take a look at the sample below for a better understanding.
Now we have a difficulty if two integers with the same position are created, for example, elements 1 and 14.
1 % 13 = 1
14 % 13 = 1
So, when we obtain 1, we store it in the first slot, but when we receive 14, we find that spot 1 is already occupied, indicating a collision.
We utilize many collision resolution techniques to handle collisions. Here, we utilize double hashing to resolve collision.
In Double Hashing, instead of one hash function, we have two, and we may utilize a combination of these two functions to produce new positions and determine if the new positions discovered are empty or not.
We use the formula below to determine the new Position.
new_Position = (i*h1(element) + h2(element)) % SIZE;
where I is a prime number
SIZE refers to the hash table’s size.
Must Read ➜ Recursion Function in Python