A table’s cost depends on its load factor, so the load factor has to be kept in a band. Too high and chains grow or probes cluster; too low and most of the memory is empty. The mechanism is to pick thresholds and resize when one is crossed, rehashing every key into the new table.
Definition · Growth and shrink thresholdsA table grows — usually doubling m — when α reaches the growth threshold, and shrinks — usually halving m — when α falls to the shrink threshold. Both resizes rehash all n keys and cost Θ(n).
The standard pair is grow at α = 1 and shrink at α = ¼. The shrink threshold is deliberately far below half the growth threshold, and the next paragraph is why.
Theorem · Doubling gives an amortised constant costUnder a policy that doubles at α = 1 and halves at α = ¼, a sequence of k insertions and deletions on a table starting empty costs O(k) in total, so O(1) amortised per operation.
The potential method: give the table a potential that measures how close it is to its next resize — roughly 2n − m above half full and m/2 − n below. An ordinary operation changes n by one and so changes the potential by a constant. A resize costs n and releases potential that the operations since the last resize have paid in, because the gap between the thresholds guarantees there were at least about n/2 of them. The released potential covers the rehash, and the amortised cost of every operation is constant.
That proof needs the gap. If growth and shrink happen at the same load, then immediately after a resize the table is sitting on the other threshold, no operations have accumulated any potential, and the next operation resizes again. There is nothing to release and the argument has no step to make. The failure is not a worse constant; it is the absence of a bound.
Both policies, on the same forty operations
The lab’s boundary pattern fills a table and then alternates inserting and deleting, which is the mix designed to sit on a threshold. Forty operations from m = 4:
grow at α = 1, shrink at α = 1/4
rehashes 2 at ops 4 (4→8) and 8 (8→16)
keys moved 12
total cost 52 against the 3m line at 120
amortised per op 13/10 = 1.3
final table m = 16 holding 14 keys no thrash detected
grow at α = 1/2, shrink at α = 1/2
rehashes 39 of 40 operations
keys moved 455
total cost 495 against the 3m line at 120
amortised per op 99/8 = 12.375
thrashing detected from operation 2
Read the two rehash counts first. Two resizes in forty operations against thirty-nine. The hysteresis policy resizes twice, early, while the table is growing into its final size, and then never again — the alternating insertions and deletions move α around inside the band and never reach an edge of it. The equal-threshold policy resizes on almost every operation, oscillating between m = 16 and m = 32 from operation 8 onward and moving thirteen or fourteen keys on every resize from operation 13.
The total cost is 52 against 495, and the second one has broken the bound: 3 per operation would be 120. The measured amortised figures are 1.3 and 12.375, and the second is not a constant — it grows with the table, because each thrashing resize costs n and n is proportional to m. Doubling the sequence length on the thrashing policy roughly quadruples its cost.
Example · Growth alone, for the shape of the amortised lineForty insertions and no deletions, same thresholds: four rehashes at m = 4, 8, 16, 32, moving 4 + 8 + 16 + 32 = 60 keys in total, for a cost of 100 against the 120 line. The rehash cost of a table that reaches size n is about 2n whatever the sequence, because the doubling costs form a geometric series — which is the cleanest case of the amortised argument and the one to look at before the boundary pattern.
One caution about the measured amortised figure. 13/10 is the total divided by the number of operations for this sequence, and it is below 3, and that is not the bound holding — it is one sequence coming in under it. A different pattern at the same thresholds could come closer to 3 and none can exceed it, and the reason none can is the potential argument above rather than anything the lab did. The lab is what shows you the thrashing policy, which no amount of reasoning about the good policy would have revealed.