Simple Algorithm
Algorithms & Data Structures · Optimal · 28 min

Open Addressing in Depth

Linear probing’s analysis, Robin Hood hashing, and the 2025 disproof of Yao’s conjecture.

In 1963 Knuth worked out exactly how many probes linear probing needs, and his 12(1+1/(1−α)2)\tfrac12\big(1 + 1/(1-\alpha)^2\big) has shaped hash tables ever since. In 1985 Yao proved that uniform probing is optimal on average among the natural "greedy" tables, and conjectured that it is optimal in the worst case too. In 2025 that conjecture fell: a greedy table can fill to load 1−δ1 - \delta with every insertion costing O(log⁡2δ−1)O(\log^2 \delta^{-1}) expected probes, where uniform probing's last insertions cost about δ−1\delta^{-1}.

What you’ll learn

  • State Knuth's exact and asymptotic costs for linear probing, prove that every slot is empty with probability exactly 1−α1 - \alpha, and derive the successful-search cost from the unsuccessful one.
  • Prove that the mean probe length of linear probing does not depend on how collisions are resolved, and explain why Robin Hood hashing shrinks the variance and the maximum.
  • Define greedy open addressing without reordering, and state Yao's theorem, Yao's conjecture and the 2025 bounds of funnel hashing and elastic hashing.
  • Explain how Swiss tables use control bytes and SIMD comparisons, and what tombstones do to primary clustering.

Linear probing, exactly

Fix mm slots and insert nn keys by linear probing, each key's home slot uniform and independent (a truly random hash function). A run is a maximal block of occupied slots. An unsuccessful search starting at slot ss costs one probe per occupied slot from ss to the end of its run, plus the empty slot that stops it.

Runs feed themselves. A run of LL slots, flanked by empty slots, grows on the next insertion with probability (L+2)/m(L+2)/m: when the key hashes anywhere inside it or into either neighbor. Long runs grow faster and merge with their neighbors. That is primary clustering, and Knuth measured its exact price.

DerivationProof sketch
  1. #{hash sequences leaving slot j empty}=m−nm⋅mn=(m−n) m n−1\#\{\text{hash sequences leaving slot } j \text{ empty}\} = \frac{m-n}{m} \cdot m^n = (m-n)\,m^{\,n-1}

    Every slot is empty with probability exactly 1−α1 - \alpha. Adding 1 (mod mm) to every hash value rotates the final table by one slot, and it permutes the mnm^n hash sequences. So all slots are empty equally often, and every outcome has exactly m−nm - n empty slots. Counting:

  2. Cn′=∑k≥0(1+k) Pr⁡[run of exactly k from s]=12(1+Q1(m,n))C'_n = \sum_{k \ge 0} (1+k)\,\Pr[\text{run of exactly } k \text{ from } s] = \tfrac12\big(1 + Q_1(m, n)\big)

    Unsuccessful search. From ss, the search costs 1+k1 + k probes when slots s,…,s+k−1s, \dots, s+k-1 are occupied and slot s+ks+k is empty. Knuth counts these hash sequences by applying the lemma separately to the keys inside that stretch and to the rest of the table; summing over kk gives Q1Q_1:

  3. Cn=1n∑i=0n−1Ci′C_n = \frac1n \sum_{i=0}^{n-1} C'_i

    Successful search. With no deletions, the search for the key inserted (i+1)(i+1)-st retraces its insertion, which was an unsuccessful search in a table of ii keys. This identity is exact for any open-addressing scheme that never moves keys:

  4. Cn≈1α∫0α12(1+1(1−t)2) dt=12(1+11−α)C_n \approx \frac1\alpha \int_0^\alpha \frac12\Big(1 + \frac{1}{(1-t)^2}\Big)\,dt = \frac12\Big(1 + \frac{1}{1-\alpha}\Big)

    Asymptotics. With α=n/m\alpha = n/m, the average becomes an integral over the load at insertion time:

Predict before you look

A linear-probing table has m=1001m = 1001 slots and holds 1,000 keys, so exactly one slot is empty. How many probes does an unsuccessful search make on average, over a uniformly random starting slot?

Show the answer

501 probes

Wherever the empty slot is, a random start lies at a distance dd before it that is uniform on 0,1,…,10000, 1, \dots, 1000, and the search makes d+1d + 1 probes: (m+1)/2=501(m+1)/2 = 501 on average, half the table. Knuth's formula agrees, since Q1(m,m−1)=mQ_1(m, m-1) = m exactly. Uniform probing gives the same here, (m+1)/(m−n+1)=501(m+1)/(m-n+1) = 501: with one free slot left, both schemes search half the table on average. The asymptotic formulas show how much earlier linear probing degrades.

Knuth's analysis assumes a truly random hash function. Real functions use a few random words, and linear probing is unusually sensitive to their quality: Pagh, Pagh & Ružić (2007) proved that every 5-independent family gives expected O(1)O(1) operations at any constant load below 1, while Pătraşcu & Thorup (2010) built 4-independent families that make them Θ(log⁡n)\Theta(\log n). The Optimal lesson k-Independence & Tabulation Hashing proves these thresholds, and shows that simple tabulation, only 3-independent, still suffices.

Robin Hood hashing

When an arriving key reaches a slot that is already occupied, one of the two keys must move on. The textbook policy is first come, first served (FCFS): the resident stays. Last come, first served (LCFS) keeps the newcomer. Robin Hood hashing (Celis, Larson & Munro, 1985) keeps whichever key is farther from its home slot, taking from the rich (keys near home) to give to the poor. Surprisingly, for linear probing the choice cannot change the average.

DerivationProof, and why Robin Hood shrinks the variance
  1. new occupied slot=first empty slot in h(x),h(x)+1,…\text{new occupied slot} = \text{first empty slot in } h(x), h(x)+1, \dots

    Occupancy. Whatever is swapped, some key keeps moving forward through occupied slots until it reaches the first empty slot at or after the new key's home. So each insertion fills the same slot under every policy, and by induction the occupied sets agree.

  2. cj=#{x:h(x)∈[s,j]}−(j−s+1)c_j = \#\{x : h(x) \in [s, j]\} - (j - s + 1)

    Keys passing a slot. Let slot jj lie in a run that starts at slot ss, so slot s−1s-1 is empty. No key ever passed slot s−1s - 1, so the keys stored in s,…,js, \dots, j all have homes in s,…,js, \dots, j, and the number of keys that pass over slot jj is fixed by the homes and the occupied set:

  3. ∑x(pos(x)−h(x)) mod m=∑jcj\sum_x \big(\mathrm{pos}(x) - h(x)\big) \bmod m = \sum_{j} c_j

    Total displacement. A key's displacement is the number of slots it passed, so summing over slots counts every pass once. Every term is policy-free:

  4. (dx2+(dy+t)2)−(dy2+(dx+t)2)=2t (dy−dx)\big(d_x^2 + (d_y + t)^2\big) - \big(d_y^2 + (d_x + t)^2\big) = 2t\,(d_y - d_x)

    The exchange behind the name. At a collision between xx, displaced dxd_x so far, and yy, displaced dyd_y, the key that moves on travels some t≥1t \ge 1 further slots. Keeping xx instead of yy changes the sum of squared displacements by 2t(dy−dx)2t(d_y - d_x), which is negative when dx>dyd_x > d_y. Robin Hood always keeps the more displaced key, the locally best choice for the variance:

python
import random, statistics

def fill(homes, m, policy):                  # linear probing; returns each key's probe count
    slot = [None] * m                        # slot[j] = home of the key stored at j
    for h in homes:
        j, cur = h, h                        # cur = home of the key looking for a slot
        while slot[j] is not None:
            res = slot[j]
            if policy == 'lcfs' or (policy == 'robinhood' and (j - cur) % m > (j - res) % m):
                slot[j], cur = cur, res      # the newcomer stays, the resident moves on
            j = (j + 1) % m
        slot[j] = cur
    return [(j - h) % m + 1 for j, h in enumerate(slot) if h is not None]

random.seed(2025)
m = 1 << 16
homes = [random.randrange(m) for _ in range(int(0.9 * m))]   # alpha = 0.9
for policy in ('fcfs', 'lcfs', 'robinhood'):
    p = fill(homes, m, policy)
    print(policy, round(statistics.mean(p), 2), round(statistics.pvariance(p), 1), max(p))

On CPython this prints means of 5.30 for all three policies, as the theorem demands, but variances of 239.2 (FCFS), 21.6 (LCFS) and 18.2 (Robin Hood), and longest probe sequences of 486, 32 and 28. Other seeds give the same picture: Robin Hood's variance and maximum are more than ten times smaller than FCFS's.

Robin Hood's order pays off twice more. Within a run, keys sit in order of their home slots, so an unsuccessful search can stop at the first resident that is closer to its home than the searched key would be, without reaching an empty slot. And a deletion can shift the following keys of the run back by one slot until it meets a key at its home or an empty slot, so no tombstones are needed.

With random probing instead of linear probing, the guarantee on the maximum becomes very strong: Devroye, Morin & Viola (2004) proved that at any fixed load factor α<1\alpha < 1 the longest probe sequence of a Robin Hood table is log⁡2log⁡n±O(1)\log_2 \log n \pm O(1) with probability tending to 1, whereas with FCFS the expected longest probe sequence grows like log⁡1/αn\log_{1/\alpha} n (Gonnet, 1981).

Is uniform probing optimal? Yao’s conjecture and its fall

Uniform probing, the idealized greedy scheme, has amortized cost 1αln⁡11−α≈ln⁡δ−1\frac1\alpha\ln\frac{1}{1-\alpha} \approx \ln \delta^{-1} at α=1−δ\alpha = 1 - \delta. Its last insertions are far worse: they look for one of the last δn\delta n free slots by sampling slots at random, which takes about δ−1\delta^{-1} probes, a coupon-collector effect.

Funnel hashing. Set aside a small special array of between δn/2\delta n/2 and 3δn/43\delta n/4 slots. Split the rest into about 4log⁡δ−14\log \delta^{-1} levels whose sizes shrink by a factor of about 3/43/4, each cut into buckets of β≈2log⁡δ−1\beta \approx 2\log \delta^{-1} slots. A key hashes to one random bucket at level 1 and takes its first free slot; if that bucket is full, it tries one random bucket at level 2, and so on, falling into the special array only if every level fails. The probe sequence is fixed in advance and the first free slot wins, so the scheme is greedy, and its probe complexity is at most (levels) × (bucket size) =O(log⁡2δ−1)= O(\log^2 \delta^{-1}) plus the rare special-array probes. Each level only has to absorb the overflow of the one before, so no level is ever asked to find one free slot among millions by blind sampling.

Elastic hashing. The array is split into subarrays of halving sizes, filled in batches. An insertion may look a bounded distance into its probe sequence in one subarray, find nothing it likes, and settle in the next subarray instead: it does not always take the first free slot of its sequence. Spending a little more at insertion time (at most O(log⁡δ−1)O(\log \delta^{-1}) expected) keeps the average search cost O(1)O(1) even as the table fills, below Yao's bound, which applies only to greedy schemes.

Check your understanding

Which statement about open addressing without reordering is correct, as of 2025?

  1. Uniform probing remains optimal in the worst case among greedy schemes, as Yao conjectured
  2. Elastic hashing beats Yao's amortized lower bound while remaining greedy
  3. Some greedy scheme achieves O(log⁡2δ−1)O(\log^2 \delta^{-1}) worst-case expected probes, and no greedy scheme does asymptotically better
  4. Funnel and elastic hashing reach their bounds by moving keys after insertion
Show the answer

C. Some greedy scheme achieves O(log⁡2δ−1)O(\log^2 \delta^{-1}) worst-case expected probes, and no greedy scheme does asymptotically better

Funnel hashing is greedy and achieves O(log⁡2δ−1)O(\log^2 \delta^{-1}), and the same paper proves Ω(log⁡2δ−1)\Omega(\log^2 \delta^{-1}) for every greedy scheme. Uniform probing's Θ(δ−1)\Theta(\delta^{-1}) is exponentially worse in terms of log⁡δ−1\log \delta^{-1}.

Engineering: control bytes, SIMD and tombstones

Theory counts probes; hardware counts cache misses and branches. The Swiss table design, presented by Google engineers in 2017 and open-sourced in the Abseil C++ library in 2018, attacks both. It is now also the design of Rust's standard HashMap and, since Go 1.24 (2025), of Go's maps.

  • The slots are split into groups of 16 (8 in portable code and in Go), and a separate array holds one control byte per slot: empty, deleted (a tombstone), or full together with 7 bits of the key's hash.
  • The hash splits in two: 57 bits (H1H_1) choose the first group, the other 7 bits (H2H_2) are the tag.
  • A lookup loads a group's 16 control bytes into one SIMD register and compares them all with H2H_2 in a single instruction. Only the slots whose tag matches are compared with the full key, and a wrong key matches a 7-bit tag with probability 1/1281/128.
  • If the group holds the key or an empty slot, the search ends; otherwise it moves to another group, in a quadratic sequence over groups. Abseil grows the table at load 7/87/8.

So most lookups read one group of control bytes and one slot: the cost of a probe sequence is paid 16 slots at a time.

Tombstones, revisited. Textbooks treat tombstones as a nuisance that lengthens searches. Bender, Kuszmaul & Kuszmaul (FOCS 2021) showed that under a steady mix of insertions and deletions at load 1−1/x1 - 1/x, the tombstones left by deletions have an anti-clustering effect: they break up runs, and the amortized expected cost per operation becomes O~(x)\tilde O(x) instead of the Θ(x2)\Theta(x^2) that primary clustering costs insertions at that load. Their graveyard hashing plants tombstones deliberately during rebuilds and achieves O(x)O(x) expected per operation for every sequence of operations, which removes primary clustering altogether.

Key takeaways

  • Knuth (1963): linear probing costs about 12(1+1/(1−α)2)\tfrac12(1 + 1/(1-\alpha)^2) probes per miss and 12(1+1/(1−α))\tfrac12(1 + 1/(1-\alpha)) per hit; every slot is empty with probability exactly 1−α1 - \alpha, and a hit costs the average of the misses that built the table.
  • Linear probing needs more than pairwise independence from its hash function: 5-independence suffices, some 4-independent families fail.
  • The mean probe length of linear probing is the same for every collision policy; Robin Hood only redistributes displacement, which cuts the variance and the maximum (log⁡2log⁡n±O(1)\log_2 \log n \pm O(1) under random probing).
  • Yao (1985) proved uniform probing optimal on average among greedy schemes; in 2025 funnel hashing (greedy, O(log⁡2δ−1)O(\log^2 \delta^{-1}) worst-case expected probes) disproved his worst-case conjecture, and elastic hashing (non-greedy) reached O(1)O(1) amortized and O(log⁡δ−1)O(\log \delta^{-1}) worst case, all with matching lower bounds.
  • In practice, Swiss tables filter 16 slots at once with 7-bit tags and SIMD, and tombstones can fight primary clustering instead of causing it (graveyard hashing).

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

A table is 90% full. In expectation, how many probes does an unsuccessful search make with linear probing (Knuth's estimate), and with uniform probing?

  1. 5.5 and 2.56
  2. 10 and 10
  3. 50.5 and 10
  4. 50.5 and 2.56
Show the answer

C. 50.5 and 10

Linear probing: 12(1+1/0.12)=50.5\tfrac12\big(1 + 1/0.1^2\big) = 50.5. Uniform probing: 1/(1−0.9)=101/(1 - 0.9) = 10. Primary clustering costs a factor of about 1/(2(1−α))1/(2(1-\alpha)), here five.

Question 2

The same keys are inserted in the same order into two linear-probing tables, one resolving collisions FCFS and the other with Robin Hood. Which quantity can differ between the two tables?

  1. The set of occupied slots
  2. The average number of probes of a successful search
  3. The total displacement of the keys
  4. The largest number of probes any single successful search needs
Show the answer

D. The largest number of probes any single successful search needs

Occupancy and total displacement, hence the mean, are policy-invariant. How the displacement is shared among the keys is not: Robin Hood evens it out, so its maximum and variance are much smaller.

Question 3

A greedy open-addressing table that never moves keys is filled to load 1−δ1 - \delta. As of 2025, what is the best possible worst-case expected probe complexity of an insertion?

  1. Θ(δ−1)\Theta(\delta^{-1}), achieved by uniform probing, as Yao conjectured
  2. Θ(log⁡2δ−1)\Theta(\log^2 \delta^{-1}), achieved by funnel hashing
  3. Θ(log⁡δ−1)\Theta(\log \delta^{-1}), achieved by elastic hashing
  4. O(1)O(1), achieved by cuckoo hashing
Show the answer

B. Θ(log⁡2δ−1)\Theta(\log^2 \delta^{-1}), achieved by funnel hashing

Farach-Colton, Krapivin and Kuszmaul (2025) gave a greedy scheme with O(log⁡2δ−1)O(\log^2 \delta^{-1}) worst-case expected probes and proved that no greedy scheme does better. Uniform probing's Θ(δ−1)\Theta(\delta^{-1}) is therefore far from optimal, disproving Yao's conjecture.

Question 4

In a Swiss table, why does storing 7 bits of each key's hash in a separate control byte speed up lookups?

  1. It lets the table use 7-bit keys instead of full keys
  2. It replaces the probe sequence, so every lookup touches exactly one slot
  3. It makes deleted slots unnecessary
  4. The tags of a whole group are compared at once with one SIMD instruction, and a wrong key passes the tag test only with probability 1/128, so full key comparisons are rare
Show the answer

D. The tags of a whole group are compared at once with one SIMD instruction, and a wrong key passes the tag test only with probability 1/128, so full key comparisons are rare

The control bytes filter candidates cheaply: one vector comparison checks 16 tags, and almost only the right slot survives to the expensive full comparison. The probe sequence still exists, but it advances a whole group at a time.

Further reading

  • D. E. Knuth, The Art of Computer Programming, vol. 3, Sorting and Searching, 2nd ed. (Addison-Wesley, 1998), section 6.4.
  • P. Celis, P.-Å. Larson & J. I. Munro, "Robin Hood hashing," Proceedings of the 26th IEEE Symposium on Foundations of Computer Science (1985), 281–288.
  • L. Devroye, P. Morin & A. Viola, "On worst-case Robin Hood hashing," SIAM Journal on Computing 33(4) (2004).
  • A. C. Yao, "Uniform hashing is optimal," Journal of the ACM 32(3) (1985), 687–693.
  • M. Farach-Colton, A. Krapivin & W. Kuszmaul, "Optimal Bounds for Open Addressing Without Reordering" (2025; arXiv:2501.02305).