Quadratic probing resolves hash-table collisions by stepping in quadratically increasing offsets from the initial bucket:
Typically , giving the simple sequence (step sizes — the differences between successive values).
The non-linear step spreads probes further apart, eliminating the primary clustering that plagues linear probing.
What it fixes vs. doesn’t
Fixed: primary clustering. Two keys with adjacent initial hashes ( and ) follow probe sequences that immediately diverge — they no longer pile up into a contiguous run.
Not fixed: secondary clustering. Two keys with the same initial hash () share the entire probe sequence — they collide forever. They take longer to find than uniformly-random probe paths would predict.
For real-world hash distributions where is fairly uniform, secondary clustering is much milder than primary clustering. Quadratic probing performance lies between linear probing and ideal uniform hashing.
The -must-be-prime catch
A subtle issue: with , the probe sequence may not visit every bucket. In particular, only half the buckets are reachable when is even. Even with prime, the standard sequence visits only buckets — meaning the table can refuse insertion at even though the table is half empty.
The standard guarantees:
- is prime, , , and → the probe sequence finds an empty slot.
In practice, implementations either (a) use a power-of-two with the triangular numbers sequence (which provably visits every bucket when is a power of 2), or (b) use a prime and accept the limitation.
Probe-count behaviour
No clean closed form for quadratic probing’s average probe count, but empirical measurements consistently land between linear and uniform-hashing levels:
| Linear (unsuccessful) | Quadratic (unsuccessful) | Uniform / double-hash (unsuccessful) | |
|---|---|---|---|
| 0.5 | 2.5 | 2.0 | |
| 0.7 | 6.06 | 3.33 | |
| 0.9 | 50.5 | 10 |
Quadratic probing’s main appeal: it captures most of the speedup over linear probing without the per-probe cost of computing a second hash function (as Double hashing does).
Cache cost
The downside compared to linear probing: probes touch non-adjacent memory cells. The first probe is one cache line; the second is somewhere – cache lines away; later probes scatter further. So even though quadratic probing has a better probe count than linear, each probe is more likely to be a cache miss.
For modern CPUs where cache misses dominate, this often makes linear probing faster than quadratic in absolute terms — even at moderate-to-high load factors where quadratic’s probe count looks better on paper.
That’s why production hash tables almost universally use linear probing (with Robin Hood / hopscotch variants) rather than quadratic. Quadratic probing is more often a textbook intermediate step than a deployed choice.
Deletion
Same tombstone trick as linear: deleted slots get a tombstone marker so probe chains aren’t broken. Lookups skip tombstones, insertions can reuse them.
In context
Quadratic probing sits between Linear probing (cheapest probes, worst clustering) and Double hashing (best probe count, two hashes per lookup). All three are open-addressing schemes; the closed-address alternative is Separate chaining.
For comparison and full analysis, see Hash table.