3.3.8 · D5Hashing
Question bank — Universal hashing — probabilistic guarantee
Symbols you need (read this first)
Before the traps, here is every symbol used on this page, in plain words. Nothing below assumes anything not listed here.

The next figure shows where the extra comes from when does not divide — the trap in several questions below.

True or false — justify
A family is universal if each single key lands in a uniformly random slot.
False. Universality is a statement about pairs colliding, not about one key's marginal distribution. A family can spread single keys perfectly yet still fail the pair bound. See Universal hashing — probabilistic guarantee for the exact definition.
"Universal hashing assumes the input keys are random."
False. The keys may be fully adversarial; the only randomness is our secret choice of from . Read the definition as "for fixed , over random ."
If for one specific pair, the family is universal.
False. The bound must hold for every distinct pair in the universe simultaneously; one good pair proves nothing.
The indicator (recall: if collide, else ) can be added across all only if the collisions are independent.
False — adding 0/1 indicators is always allowed. What we then take the expectation of uses linearity, which also needs no independence. Independence is never required anywhere in this analysis.
Linearity of expectation was used because the collision events are independent.
False — it was used precisely because they are not independent. Linearity needs no independence, which is why it fits here. See Linearity of expectation.
With , worst-case search time in a universal-hashed chained table is .
False. Expected time is (with constant); the worst case (all keys chain into one slot) is still . The guarantee is over coin flips, not adversarial inputs.
The family is exactly universal for any .
False. It is exactly universal () only when ; otherwise buckets are uneven and it is almost-universal, . See Modular arithmetic and primes.
Allowing in is harmless.
False. With we get — a constant ignoring the key, so every pair collides with probability 1. That is why .
Because is huge, the extra in the almost-universal bound can be ignored in practice.
True. For a realistic prime , is astronomically smaller than , so the guarantee is effectively . The caveat matters for proofs, not performance.
Expected chain length seen by a key already in the table is .
False. If is present it also counts itself: expected length is . The bare (or ) is for a key not yet inserted.
Spot the error
"Random hashing means collisions never happen, so search is always ."
Collisions certainly still happen; universality only makes their expected count small (). It bounds an average, not a guarantee of zero.
"Since , some search must cost at most ."
The average being small does not bound the maximum of a fixed run — an adversary could still be unlucky-for-you on a bad coin flip. Expectation bounds the long-run average over the random .
" only if is independent of other indicators."
No independence is needed. For any 0/1 variable, .
"We do then just to be safe; one mod would do."
The (with prime) is the universality engine: it makes a bijection so distinct keys get distinct residues. Dropping it destroys the collision bound. The merely fits the answer into the table slots.
" can be any number bigger than the largest key."
It must be a prime larger than the max key. Primality is what makes a field so the linear map is invertible; a composite breaks the bijection argument. See Modular arithmetic and primes.
"The load factor can safely grow without bound."
Then expected cost grows too. To keep operations we rehash into a larger table once exceeds a threshold. See Load factor and rehashing.
"Open addressing makes universal hashing unnecessary."
The choice of hash function and the collision-resolution scheme are independent concerns; open addressing still needs a good , and adversaries still exist. See Hashing — chaining vs open addressing.
Why questions
Why can a fixed hash function always be defeated?
Once the adversary knows , they compute a set of keys that all map to one slot, forcing per operation. Knowledge of is the weapon. See Adversarial inputs and randomized algorithms.
Why does hiding the random choice of actually help?
The adversary must fix their keys before seeing your coin flips, so they can't tailor collisions to your specific — the pair-collision bound then holds regardless of their keys.
Why is the guarantee stated over pairs rather than over the whole key set?
Because the analysis sums indicators over other keys , and each term only needs the pairwise bound — a per-pair fact is enough to bound the total via linearity.
Why does add exactly the term?
The residues split into buckets that cannot all be equal, so some buckets hold residues instead of . The collision chance becomes , which upper-bounds to — the is the "leftover" from uneven splitting (see figure s02).
Why must be prime specifically (not just large)?
In with prime, every nonzero has an inverse, making a bijection; this is what guarantees distinct keys stay distinct mod . Composite moduli have zero divisors that ruin this.
Why does keeping give operations?
Then is a constant, so expected cost . It's the ratio of keys to slots, not itself, that controls chain length.
Why is universal hashing a building block for perfect hashing?
Perfect hashing (FKS) uses a universal family at two levels, choosing functions with few/zero collisions, to get worst-case lookup on a static set. See Perfect hashing (FKS) — uses universal hashing as a building block.
Edge cases
What happens to the collision bound when (same key)?
Undefined/irrelevant — universality only speaks of distinct keys . A key never "collides with itself"; it just maps where it maps.
When we insert the very first key into an empty table, how many collisions does it expect?
Zero. Here "" means keys already present ( before this insert), so the bound ... — be careful: use the not-yet-inserted form . The first key always lands in an empty slot.
When exactly, what does the bound become?
The buckets are perfectly even ( residues each), so the extra term vanishes and the family is exactly universal: .
If (a single slot), is the family still "universal"?
Trivially yes: always holds, but the table is useless since every key shares one chain. Universality is a ceiling, not a promise of usefulness.
As with fixed, what happens to expected collisions?
The bound , so expected chain length approaches 1 — you're paying huge memory to almost eliminate collisions.
What if the adversary sees your after it's chosen (e.g. via a side channel)?
The guarantee collapses — universality assumes the choice stays secret. A leaked reduces you to the fixed-function case they can defeat.
Connections
- Universal hashing — probabilistic guarantee
- Linearity of expectation
- Modular arithmetic and primes
- Load factor and rehashing
- Hashing — chaining vs open addressing
- Adversarial inputs and randomized algorithms
- Perfect hashing (FKS) — uses universal hashing as a building block