Professional Documents
Culture Documents
Hash Table: Aad Cse Srm-Ap 1
Hash Table: Aad Cse Srm-Ap 1
Hash Table: Aad Cse Srm-Ap 1
k1
k4
K
(actual k2 k6
k5 k5 k2 k6
keys)
k8 k7
k3
k7 k3
k8
m–1
AAD CSE SRM-AP 10
Hashing with Chaining
Dictionary Operations:
Chained-Hash-Insert (T, x)
Insert x at the head of list T[h(key[x])].
Chained-Hash-Delete (T, x)
Delete x from the list T[h(key[x])].
12
Linear Probing Example
insert(14) insert(8) insert(21) insert(2)
14%7 = 0 8%7 = 1 21%7 =0 2%7 = 2
0 0 0 0
14 14 14 14
1 1 1 1
8 8 8
2 2 2 2
21 12
3 3 3 3
2
4 4 4 4
5 5 5 5
6 6 6 6
1 1 3 2
probes:
13
Drawbacks of Linear Probing
Works until array is full, but as number of items N
approaches TableSize ( 1), access time approaches
O(N)
Very prone to cluster formation (as in our example)
If a key hashes anywhere into a cluster, finding a free
cell involves going through the entire cluster – and
making it grow!
Primary clustering – clusters grow when keys hash to
values close to each other
Can have cases where table is empty except for a few
clusters
Does not satisfy good hash function criterion of
distributing keys uniformly
14
Basic Operations
Search − Searches an element in a
hash table.
Insert − inserts an element in a hash
table.
delete − Deletes an element from a
hash table.