2. AGENDA
• Why hashing?
• What is hashing?
• Hashing functions
• Collision resolution techniques
3. WHY HASHING?
We are going to Direct Address Table to reduce the search time
In DMA there is wastage of storage
In order to organize the storage we are moving for Hashing
4. • HASHING:
• HASH TABLE: It is a simple data structure ,which stores the keys in table in it’s
corresponding position
• HASH FUNCTION: It is a mathematical formula inorder to get the index to
store keys
6. DIVISION METHOD
• Let the keys are k1,k2,k3…….kn
• Formula: Ki%m,
• where m is the size of the hash table
• n =1,2,3,4…….n
7. MULTIPLICATIVE METHOD
• Choose value between 0 &1
• Let the value be ‘A’
• R<-(A*k)mod (l)
• where l is
• k is the key
• Take the fractional part
• Apply hash function on result
• H(R)<-R%m
• where m is size of hash table
•
8. MID SQUARE METHOD
• Take middle key depending on the hashtable size
• K=k^2
• Apply normal hash function(division method)
9. FOLDED METHOD
• Divide the values into parts
• Add the digits
• Apply normal hash function(division method)
• Ex :123450
• 12 | 34 |50
• 375
10. COLLISION RESOLUTION TECHNIQUES
• While applying hash functions ,collisions will occur. In order to manage
collisions we are going to follow below techniques
11. CHAINING
• Hash table contains the pointers pointing to the linked lists
Disadvantage: In worst case we require O(n) to search an element
We are using pointers ,which require much memory
In order to overcome this we are moving for open addressing
12. OPEN ADDRESSING
• When collision occurs ,we go for probe new sequence
• We search for next free location
• Overflow: It occurs when hash table was filled (we couldn’t find any free
location)
13. LINEAR PROBING
Linear Probing resolves collisions by placing the data
into the next open slot in the table
h(k,i)=(h’(k)+i)%m
h’(k)=h(k)%m
14. QUADRATIC PROBING
• Quadratic probing is an open addressing scheme for resolving collisions in
hash tables—when an incoming data's hash value indicates it should be
stored in an already-occupied slot or bucket
• Formula:(h’(k)+C1(i)+C2 (i^2))%m
15. DOUBLE HASHING
• Double hashing is one of the best methods for dealing with collisions.
• If the slot is full, then a second hash function is calculated and combined with
the first hash function.
• H(k, i) = (H1(k) + i H2(k) ) % m
16. REHASHING
• Rehashing: Means hashing again. ... So to overcome this, the size of the array
is doubled and all the values are hashed again and stored in the new
double sized array to maintain a low load factor and low complexity.