Professional Documents
Culture Documents
Hashing
Hashing
Data Structures
Basic idea
2
3
Example applications
Hashing
The process of accessing a record, stored in a table,
by mapping the value of its key to a position in the
table.
Hash function
A function that maps key values to table positions.
Hash table
The array where the records are stored.
Hash value
The value returned by the hash function. It usually
corresponds to a position in the hash table.
Example of Hashing
Perfect hashing Hash
table
0
1
H(key)=key
2
Key 8 Hash 3
function: 4
… H(8)=8 5
… 6
Record
7
Key 8 8
7
9
…Perfect hashing
8
Insert 13 and 23
0 1 2 3 4 5 6 7 8 9
13
23
12
Collision Resolution
13
Data Structures
Open-addressing vs. chaining
14
0 H(key)=key mod
1 tableSize
2 Insert 13
3 13 23
Insert 23
4
5 Insert 18
6 Collision is resolved
7 by inserting the
8 elements in a linked-
18 list.
9
15