Lec 17
Lec 17
0 4 8 12 16
34 0 45 6 23 7 28 12 29 11 30 33
• Put in pairs whose keys are 6, 12, 34, 29, 28, 11,
23, 7, 0, 33, 30, 45
Linear Probing – Remove
0 4 8 12 16
34 0 45 6 23 7 28 12 29 11 30 33
• remove(0)
0 4 8 12 16
34 45 6 23 7 28 12 29 11 30 33
0 4 8 12 16
34 45 6 23 7 28 12 29 11 30 33
Linear Probing – remove(34)
0 4 8 12 16
34 0 45 6 23 7 28 12 29 11 30 33
0 4 8 12 16
0 45 6 23 7 28 12 29 11 30 33
0 4 8 12 16
0 45 6 23 7 28 12 29 11 30 33
Linear Probing – remove(29)
0 4 8 12 16
34 0 45 6 23 7 28 12 29 11 30 33
0 4 8 12 16
34 0 45 6 23 7 28 12 11 30 33
0 4 8 12 16
34 0 45 6 23 7 28 12 29 11 30 33
0 4 8 12 16
34 0 45 6 23 7 28 12 29 11 30 33
• alpha = loading density = (number of pairs)/b.
alpha = 12/17 .
• Sn = expected number of buckets examined in a successful search when n is large
• Un = expected number of buckets examined in a unsuccessful search when n is large
• Time to put and remove governed by Un.
Expected Performance
• Sn ~ ½(1 + 1/(1 – alpha))
• Un ~ ½(1 + 1/(1 – alpha)2)
• Note that 0 <= alpha <= 1.
alpha Sn Un
Sorted Chains
• Put in pairs [4]
whose keys are
6 23
6, 12, 34, 29,
7
28, 11, 23, 7, 0,
33, 30, 45 [8]
• Home bucket =
key % 17. 11 28 45
[12] 12 29
30
[16] 33
Expected Performance
• Unsorted chains.
• Default initial b = divisor = 101
• Default alpha <= 0.75
• When loading density exceeds max permissible
density, rehash with newB = 2b+1.