Expected collisions of universal hash families #
A hash function h : X → Y sorts a finite key set S into buckets {x ∈ S | h x = j}. The
number orderedCollisionCount h S of ordered pairs of distinct keys sharing a bucket controls
both injectivity and the total squared bucket size:
his injective onSiff no pair collides (orderedCollisionCount_eq_zero_iff), and any collision is counted twice (two_le_orderedCollisionCount);∑ⱼ bⱼ² = |S| + orderedCollisionCount h S, wherebⱼis the size of bucketj(sum_card_filter_sq).
For an ε-universal family (Cslib.Probability.IsUniversalHash) and |S| = n, linearity of
expectation bounds the expected number of ordered collisions by n (n - 1) ε, that is twice the
C(n, 2) ε bound on unordered collisions. With a universal family into m values
(Cslib.Probability.IsTwoUniversal, ε = 1 / m) this gives the two estimates behind
Fredman–Komlós–Szemerédi perfect hashing [FKS84], in the form of [CLRS09],
Section 11.5:
- if
n² ≤ m, the hash is injective onSexcept with probability at most1 / 2(IsTwoUniversal.toOuterMeasure_not_injOn_le); - if
n ≤ m, the expected sum of squared bucket sizes is at most2n - 1(IsTwoUniversal.tsum_sum_card_filter_sq_le), so by Markov's inequality (Cslib.Probability.PMF.mul_toOuterMeasure_le_tsum) it exceeds4nwith probability at most1 / 2(IsTwoUniversal.toOuterMeasure_four_mul_lt_sum_card_filter_sq_le).
CLRS states the two probability bounds for m = n² and m = n, with strict inequalities
(< 1 / 2, and secondary storage ≥ 4n). The forms here allow any m at least that large and
bound the probability by ≤ 1 / 2; they are exactly what the construction's success tests use.
Expectations are ∑' i, seed i * f i in ℝ≥0∞ over an arbitrary seed law, and probabilities are
PMF.toOuterMeasure. These are information-theoretic statements; evaluation cost is separate.
Main definitions #
Cslib.Probability.orderedCollisionCount: ordered pairs of distinct keys with equal hashes.
Main results #
Cslib.Probability.orderedCollisionCount_eq_zero_iff,Cslib.Probability.two_le_orderedCollisionCount: collisions and injectivity.Cslib.Probability.sum_card_filter_sq: squared bucket sizes count collisions.Cslib.Probability.IsUniversalHash.tsum_orderedCollisionCount_le: expected collisions.Cslib.Probability.IsUniversalHash.tsum_sum_card_filter_sq_le: expected squared bucket sizes.Cslib.Probability.IsUniversalHash.toOuterMeasure_not_injOn_le: union bound over pairs on non-injectivity.Cslib.Probability.IsTwoUniversal.toOuterMeasure_not_injOn_le: injectivity inton²cells.Cslib.Probability.IsTwoUniversal.tsum_sum_card_filter_sq_le,Cslib.Probability.IsTwoUniversal.toOuterMeasure_four_mul_lt_sum_card_filter_sq_le: linear total squared bucket size intoncells.Cslib.Probability.IsTwoUniversal.sum_ite_toReal_le_card_div_of_imp: an event forcing a collision of a fixed key with another key ofShas probability at most|S| / |Y|.
References #
The number of ordered pairs (x, y) of distinct elements of S that h maps to the same
value. Each unordered colliding pair is counted twice.
h is injective on S exactly when no ordered pair of distinct elements collides.
A collision of x ≠ y is counted as (x, y) and as (y, x).
The sum of the squared bucket sizes counts each key with itself and every ordered colliding
pair: ∑ⱼ bⱼ² = |S| + #{(x, y) : x ≠ y, h x = h y}.
Expected collisions of an ε-universal family: on a set of n keys the expected number of
ordered colliding pairs is at most n (n - 1) ε, twice the C(n, 2) ε bound for unordered pairs
([CLRS09], Section 11.5).
The expected sum of squared bucket sizes is n plus the expected number of ordered
collisions, so at most n + n (n - 1) ε for an ε-universal family.
Union bound over pairs: an ε-universal family is injective on S except with
probability at most C(|S|, 2) · ε.
Perfect hashing into n² cells ([CLRS09], Section 11.5): a universal family into at
least n² values is injective on a fixed set of n keys except with probability at most 1 / 2.
CLRS states the strict bound < 1 / 2 for exactly n² values; the non-strict form is what the
secondary level of the construction uses.
Linear total secondary space ([CLRS09], Section 11.5): with a universal family into at
least n values, the expected sum of squared bucket sizes is at most 2n - 1.
Markov bound for the top level ([CLRS09], Section 11.5): with a universal family into
at least n values, the sum of squared bucket sizes exceeds 4n with probability at most
1 / 2. CLRS bounds the probability of ≥ 4n by < 1 / 2 for exactly n values; the top-level
test of the construction accepts ≤ 4n, so it needs the form stated here.
If an event on hash seeds forces a collision of x with another key of S, a universal family
into Y bounds its probability by |S| / |Y|.