DSA Java Hashing (M 26)
DSA Java Hashing (M 26)
The Hash table data structure stores elements in key-value pairs where
This video is sole property of Talent Battle Pvt. Ltd. Strict penal action will be taken against unauthorized piracy of this video
Hash Table
Hashing (Hash
Function)
In a hash table, a new
index is processed using
the keys.
And, the element
corresponding to that key
is stored in the index.
This process is
called hashing.
Let k be a key
and h(x) be a hash
function.
Here, h(k) will Thisgive us a
video is sole property of Talent Battle Pvt. Ltd. Strict penal action will be taken against unauthorized piracy of this video
Hash Collision
When the hash function generates the same index for multiple keys, there will be
a conflict (what value to be stored in that index). This is called a hash collision.
We can resolve the hash collision using one of the following techniques.
This video is sole property of Talent Battle Pvt. Ltd. Strict penal action will be taken against unauthorized piracy of this video
Hash Collision
1. Collision resolution by
chaining
In chaining, if a hash function
produces the same index for
multiple elements, these
elements are stored in the same
index by using a doubly-linked
list.
where
i = {0, 1, ….}
h'(k) is a new hash function
If a collision occurs at h(k, 0), then h(k, 1) is checked. In this way, the value of i is incremented
linearly.
This video is sole property of Talent Battle Pvt. Ltd. Strict penal action will be taken against unauthorized piracy of this video
Hash Collision
It works similar to linear probing but the spacing between the slots is increased
(greater than one) by using the following relation.
where,
This video is sole property of Talent Battle Pvt. Ltd. Strict penal action will be taken against unauthorized piracy of this video
Hash Collision
This video is sole property of Talent Battle Pvt. Ltd. Strict penal action will be taken against unauthorized piracy of this video
Good Hash Function
A good hash function may not prevent the collisions completely however it
can reduce the number of collisions.
This video is sole property of Talent Battle Pvt. Ltd. Strict penal action will be taken against unauthorized piracy of this video