1 Hashing
Hashing
A form of narcotic intake? A side order for your eggs? A combination of the two?
Hashing Hashing What is it? A form of narcotic intake? A side - - PDF document
Hashing Hashing What is it? A form of narcotic intake? A side order for your eggs? A combination of the two? Hashing 1 Problem RT&T is a large phone company, and they want to provide caller ID capability: - given a phone number,
1 Hashing
A form of narcotic intake? A side order for your eggs? A combination of the two?
2 Hashing
provide caller ID capability:
space -- huge amount of wasted space
(you want fancy pictures here too? so read the slides from the RedBlack help session). 000-0000 000-0001 863-7639 ... 999-9999 ... ... ... Roberto (null) (null) (null) 863-9350 Gordon 863-7639 Roberto
3 Hashing
time, O(N+M) space, where M is table size
the large range into one which we can manage
small) size of the array, and use that as an index
say, five slots
in slot 4 of the hash table
then check the array at that slot
example! 1 Roberto (null) (null) (null) (null) 2 3 4
4 Hashing
spot in the array?
keys, to lists of items with the same key
2 4 2 2
1
2 3 4
5 Hashing
constructor:
init insert find remove
create table of M lists
index = h(K) insert into table[index]
index = h(K) walk down list at table[index], looking for a match return what was found (or error)
index = h(K) walk down list at table[index], lookiing for a match remove what was found (or error)
6 Hashing
string
significant bits of K
7 Hashing
= 21526 4436 17100
= 526447 3522 151420
= 13454 2361 7100
= 10 100 01
= 11 110 01
= 101 010 01
8 Hashing
location
Man, that’s a lot of hash! Watch out for the legal probe
9 Hashing
location
linear_probing_insert(K) if (table is full) error probe = h(K) while (table[probe] occupied) probe = (probe + 1) mod M table[probe] = K
slot is found
10 Hashing
1 2 3 4 5 6 7 8 9 10 11 12
11 Hashing
position in the table
double_hash_insert(K) if(table is full) error probe = h1(K)
while (table[probe] occupied) probe = (probe + offset) mod M table[probe] = K
does
12 Hashing
h2(K) = 8 - K mod 8
1 2 3 4 5 6 7 8 9 10 11 12
13 Hashing
index
Expected Number of Probes 1 α + 1 α 2
Chaining Linear Probing 1 2
2 1 α – ( )2
1 2
2 1 α – ( )
Double Hashing 1 1 α – ( )
α
1 1 α –
found
14 Hashing
0.5 1.0 Successful Unsuccessful Linear Probing Chaining Double Hashing
1.0
Number of Probes α