3.3.8 · D3Hashing

Worked examples — Universal hashing — probabilistic guarantee

3,035 words14 min readBack to topic

Parent: Universal hashing — probabilistic guarantee

This page is a drill through every case universal hashing can throw at you. We do not introduce new theory — we exercise the theory of the parent note until no scenario surprises you. If a symbol here is not obvious, it was built in the parent; we re-anchor the important ones as we go.

Before anything, let us re-fix the two objects we compute with, in plain words:


The scenario matrix

Think of every problem as landing in exactly one cell. Here is the full grid we must cover.

Cell Case class What is special about it Hit by
A Normal load, not yet inserted use Ex 1, Ex 3(cont.)
B Normal load, already inserted use Ex 2
C Degenerate: empty table () limiting value Ex 3
D Degenerate: single key () & tiny table () boundary of the formula Ex 3
E Overloaded: (rehash trigger) , cost still Ex 4
F Compute — generic key the two-mod pipeline Ex 5
G Compute — edge keys: , , and zero / wraparound inputs Ex 5
H Collision probability when (exactly universal) bound is exactly Ex 6
I Collision probability when (almost universal) bound is Ex 6
J Real-world word problem choosing for a target cost Ex 7
K Exam twist: adversary + "why can't he win?" conceptual, no arithmetic Ex 8

Read the table top-to-bottom once. Every row below is a worked example that nails that cell.


Group 1 — Expected chain length (cells A–E)

The engine for all of these is one line from the parent, re-stated (recall from the definition above):

Figure — Universal hashing — probabilistic guarantee

The picture above shows the straight line . Every example in this group is just one point on that line — look at where each lands.


Group 2 — Computing (cells F–G)


Group 3 — Collision probability, both regimes (cells H–I)

This is the sharpest distinction on the page: exactly universal vs almost universal.

The figure below draws exactly this evenness argument. Each bar is a table slot; its height is how many of the residues land in that slot after the outer . Read the left panel (): all bars are the same height, so the buckets are perfectly balanced and the collision bound tightens to a clean (green). Read the right panel (): the bars are uneven — some reach , one is shorter — and that lopsidedness (orange) is precisely the gap that forces the extra . Look at how the tallest orange bar is one unit above the shortest: that single-unit imbalance is the "".

Figure — Universal hashing — probabilistic guarantee

Group 4 — Word problem & exam twist (cells J–K)


Recall Self-test across the matrix

Cell A vs B — which uses ? ::: A (x not inserted) uses ; B (x already inserted) uses . In Cell D (), what is the collision probability bound, and does it break the theory? ::: — collision is certain, and this is correct: a one-slot table always collides. The formula degrades gracefully, never breaking. Cell E: does break universality? ::: No; is untouched. Only the constant grows; rehash to fix. Cell H vs I: when is the bound exactly ? ::: Only when ; otherwise carry (bound ). Cell J: must the table size be prime? ::: No — only must be prime; can be any size (e.g. a power of two). Cell K: why can't the adversary win? ::: He commits keys before the random is chosen, and the bound holds for every pair.


Connections