Professional Documents
Culture Documents
Dictionary ADT: Dictionaries 4/1/2003 8:43 AM
Dictionary ADT: Dictionaries 4/1/2003 8:43 AM
Dictionary ADT: Dictionaries 4/1/2003 8:43 AM
1
Dictionaries 4/1/2003 8:43 AM
2
Dictionaries 4/1/2003 8:43 AM
Performance of
Example of Double Hashing Hashing
k h (k ) d (k ) Probes In the worst case, searches,
Consider a hash 18 5 3 5 insertions and removals on a The expected running
table storing integer 41 2 1 2 hash table take O(n) time time of all the dictionary
22 9 6 9
keys that handles 44 5 5 5 10
The worst case occurs when ADT operations in a
collision with double 59 7 4 7 all the keys inserted into the hash table is O(1)
32 6 3 6 dictionary collide
hashing In practice, hashing is
31 5 4 5 9 0 The load factor α = n/N
N = 13 73 8 4 8 affects the performance of a
very fast provided the
h(k) = k mod 13 hash table load factor is not close
d(k) = 7 − k mod 7 Assuming that the hash to 100%
0 1 2 3 4 5 6 7 8 9 10 11 12 values are like random Applications of hash
Insert keys 18, 41, numbers, it can be shown tables:
22, 44, 59, 32, 31, that the expected number of
small databases
73, in this order 31 41 18 32 59 73 22 44 probes for an insertion with
open addressing is compilers
0 1 2 3 4 5 6 7 8 9 10 11 12
1 / (1 − α) browser caches
Dictionaries and Hash Tables 15 Dictionaries and Hash Tables 16
3
Dictionaries 4/1/2003 8:43 AM