6.006 Intro to Algorithms Recitation 07 February 25, 2011
On average, since the number of elements is proportional to the size of the table at all times,
each of the
m
2
inserts before resizing will still take O(1) time. The last insert will take O(2m)
time as we need to factor in the time it takes to resize the table. We can use amortized analysis to
argue that the average runtime of all the insertions is O(1). The last insert before resizing costs
O(2m) time, but we needed
m
2
inserts before actually paying that cost. We can imagine spreading
the O(2m) cost across the
m
2
inserts evenly, which adds an additional average amortized cost of
O(
2m
0.5m
) per insert, or O(1) per insert. Since the cost of insertion before was O(1), adding an
additional O(1) amortized cost to each insert doesn’t affect the asymptotic runtime and insertions
on average take O(1) time still.
Decreasing Table Size
Similarly, after halving the table size due to an deletion, n =
m
2
. We will need at least
m
4
delete
operations before the next time we halve the size of the hash table. The cost of the next halving is
O(
m
2
) to make a size
m
2
table.
The
m
4
deletes take O(1) time and the resizing cost of O(
m
2
) can be split evenly across those
m
4
deletes. Each deletion has an additional average amortized cost of O(
0.5m
0.25m
) or O(1). This results
in maintaining the O(1) average cost per deletion.
Performance of Open Addressing
Recall that searching, inserting, and deleting an element using open addressing required a probe
sequence (e.g. linear probing, quadratic probing, double hashing). To analyze the performance of
operations in open addressing, we must determine on average how many probes does it take before
we execute the operation. Before, we made the simple uniform hashing assumption (SUHA),
which meant a hash function mapped to any slot from 0 to m − 1 with equal probability. Now, we
make the uniform hashing assumption (UHA), which is a slight extension from SUHA. UHA
assumes that the probe sequence is a random permutation of the slots 0 to m − 1. In other words,
each probe looks likes we’re examining a random slot that we havent examined before.
If the table has load balance α, that means there is a p = 1 − α probability that the first probe
will find an empty slot under UHA. If the first probe is a collision, note that the probability that the