

















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


















...
0 1 2 3 1000
hash table
buckets
applications have key ranges that are too large to have 1- mapping between buckets and keys!
Example:
unsigned int)
h(k 1 ) = β = h(k 2 ): k 1 and k 2 have collision at slot β
h(k) = k%D, where D number of buckets in hash table
h(k) = k%
80 → 3 (80%11= 3), 40 → 7, 65 → 10
58 → 3 collision! Docsity.com
“If we try to place x in bucket h(x) and find it occupied, find alternative location h 1 (x) , h 2 (x) , etc. Try each in order, if none empty table is full,”
h (^) i (x) = (h(x) + i) % D
sequence of hash table slots (probe sequence) that can hold the record; test each slot until find empty one (probing)
h(d)=
0 2 3 4 5 6 7 1
b
a c
Where do we insert d? 3 already filled Probe sequence using linear hashing: h 1 (d) = (h(d)+1)%8 = 4%8 = 4 h 2 (d) = (h(d)+2)%8 = 5%8 = 5* h 3 (d) = (h(d)+3)%8 = 6%8 = 6 etc. 7, 0, 1, 2 Wraps around the beginning of the table!
d
0 1 2 3 4 5 6 7 8 9
10
1001 9537 3016
9874 2009 9875
h(k) = k%
0 1 2 3 4 5 6 7 8 9
10
1001 9537 3016
9874 2009 9875
I
II insert 1052 (h.b. 7)
1052
next element in bucket 3 with p = 8/11Docsity.com
r =D (a base-D digit)
static long hashCode(String key, int D) { int h=0; for (int i=0, i<key.length(); i++){ h = (h << 4) | ( h >> 27); h += (int) key.charAt(i); } return h%D; }