Professional Documents
Culture Documents
30 20 11 28 16 13 55 52 26 50 87
30 20 30 11 20 30
20
11 28 30
20
11 16 28 30
20
11 13 16 28 30
20
11 13 16 28 30 55
20 30
11 13 16 28 52 55
20 30
11 13 16 26 28 52 55
20 30
11 13 16 26 28 50 52 55
20 30 52
11 13 16 26 28 50 55 87
4) Given the input {3823, 8806, 8783, 2850, 3593, 8479, 1941, 4290, 8818, 7413}
and a hash function h(x) = x mod 13, show the resulting separate chaining table.
h(x) = x mod
x 13
3823 1
8806 5
8783 8
2850 3
3593 5
8479 3
1941 4
4290 0
8818 4
7413 3
) Repeat #4 using open addressing with linear probing.
In linear probing, we have ,h(x,i) = (x+i) (mod k) and given Table Size k = 13
H(3593,0) = 3593 mod 13 = 5 , Collision occurs, increment the value i to 1. h((3593+1 )mod 13) = 6
H(8479,0) = 8479 mod 13 = 3, Collision occurs. Increment the value i to 1. h(8479 + 1) mod 13 = 4
H(1941,0) = 1941 mod 13 = 4 Collision occurs. Increment the value i to 1. h(1941 + 1) mod 13 = 5,
(8818 +1) mod 13 = 5 , (8818+2) mod 13 = 6, (8818 +3) mod 13 = 7, (8818 +4 ) mod 13 = 8
0 4290
1 3823
2
3 2850
4 8479
5 8806
6 3593
7 1941
8 8783
9 8818
10 7413
11
12
{3823, 8806, 8783, 2850, 3593, 8479, 1941, 4290, 8818, 7413}
Collision Occurs
Collision occurs
Collision Occurs
Collision occurs
Collision Occurs
Collision Occurs
Collision occurs
Collision occurs
Collision occurs
Collision occurs
Collision occurs
Collision occurs
Collision occurs
11 - (x mod 11).
Hash Table
Suppose these names have the following hash values. Insert them into the extendible hash
table shown below. Each leaf can only hold 4 entries. Note that the first two names
Bob 0100
Sue 1000
Tim 1110
Ron 0010
Ann 1010
Jan 1101
Ben 0001
Don 0101
Tom 1111
Sam 1011
---------------
| 0 | 1 |
---------------
---------- ----------
| (1) | | (1) |
| | | |
| | | |
| | | |
---------- ----------
0 1
0 1
0 1
0 1
0 1
0 1
0 1
Here if “Tom 1111” data is inserted then the overflow occurs at leaf 1 in the table. The reason is that,
each leaf can only hold 4 entries. Then, it requires additional bits to avoid the problem. So, use 4
bits(00,01, 10 and 11) instead of 2 bits ( 0 and 1)
00 01 10 11
A: 2,0
B: 0,0
C: 4,1
D: 0,1
E: 2,3
10 points
10) Using Hopscotch hashing with a max hop of 4, hash the following keys.
A: 6
B: 7
C: 9
D: 7
E: 6
F: 7
G: 8
In hopscotch hashing, neighborhoods can be stored using bitmaps. Each bucket requires a bitmap
in addition to all the data already needed for that bucket. Each bit in that bitmap shows if the
current bucket or one of its following (H-1) buckets are holding an entry which belongs to the
neighborhood of the current bucket.