You are on page 1of 9

CSD201 – Data Structures and Algorithms (In

C++)

Chapter10: Hashing

http://www.fpt.edu.vn/ 1
Chapter topics
• Hash functions
• Collision resolution techniques
• Hashing in java.util

http://www.fpt.edu.vn/ 2
Hash functions

de x
in
key K h(K)

http://www.fpt.edu.vn/ 3
Hash functions (cont.)

K = 123456789

division 123456789 % TSize

shift folding (123 + 456 + 789) % TSize

boundary folding (123 + 654 + 789) % TSize

extraction 5478 % TSize

http://www.fpt.edu.vn/ 4
Collision resolution: linear probing
h(K) = K % 10
33 16 27 23 26 79 88

0
1
2
3
4
5
6
7
8
9

http://www.fpt.edu.vn/ 5
Collision resolution: linear probing and clustering

0 0.1 0 0.1
1 0.1 1 0.1
2 0.1 2 0.1
3 0.1 3 33 0
4 0.1 4 0.2
5 0.1 5 0.1
6 0.1 6 0.1
7 0.1 7 0.1
8 0.1 8 0.1
9 0.1 9 0.1

http://www.fpt.edu.vn/ 6
Collision resolution: chaining
h(K) = K % 10
33 16 27 23 26 79 88

0
1
2
3
4
5
6
7
8
9

http://www.fpt.edu.vn/ 7
Collision resolution: coalesced hashing
h(K) = K % 10
33 16 27 23 26 79 88

0 -1
1 -1
2 -1
3 4
-1
4 -1
5 -1
6 8
-1
7 -1
8 -1
0
9 -1

http://www.fpt.edu.vn/ 8
Q&A

Thank you for your listening!

http://www.fpt.edu.vn/ 9

You might also like