Documentation

CslibFrontier.DataStructure.Dictionary.WordRAM.LinearProbing.FiveWise

Constant-independence cluster bounds for linear probing #

This file proves the probabilistic core of constant-time linear probing under $5$-wise independent hashing, adapting Pagh, Pagh and Ružić, Linear Probing with Constant Independence, SIAM J. Comput. 39(3):1107–1120, 2009, Section 2.3 (Lemma 2.1, pp. 1110–1111) and Section 4 (Lemma 4.1, Theorem 4.3, and Theorem 4.5, pp. 1114–1118); see also Cormen, Leiserson, Rivest and Stein, Introduction to Algorithms, Section 11.4 and Vadhan, Pseudorandomness, Section 3.5.

Source statement and proof adaptation #

In [PaghPaghRuzic2009], Lemma 2.1 (Section 2.3, pp. 1110–1111) shows that for a stored key set $S \subseteq U$ of size $n$, a $5$-wise independent hash family $\mathcal{H} : U \to [r]$ with maximum load $\bar{\alpha} < 1$, any subset $Q \subset [r]$ of size $q$, any $d > 0$, and any fixed $x \in U \setminus S$, conditioning on $h(x) = \rho$ leaves a $4$-wise independent family on $U \setminus \{x\}$ and the centered fourth-moment Markov bound gives $\Pr[|\{y \in S : h(y) \in h(x) + Q\}| \ge \bar{\alpha} q + d] < 4 \bar{\alpha} q^2 / d^4$. Combining Lemma 2.1 with the occupied-run witness in Lemma 4.1 (Section 4, p. 1114), Theorem 4.3 (Section 4.1, pp. 1115–1116) and Theorem 4.5 (Section 4.2, p. 1118) bound the expected number of probes per operation by $O((1 - \bar{\alpha})^{-5/2})$ and $O((1 - \bar{\alpha})^{-13/6})$ for any maximum load $\bar{\alpha} < 1$.

Our formalization specializes to a power-of-$2$ table of size $m = 2^M \ge 8 n_{\max}$ (exact uniform load factor $\bar{\alpha} = \alpha = \#S / 2^M \le 1/8$) and an exact uniform $5$-wise independent family $h : \iota \to X \to \mathrm{Fin}(2^M)$ (IsKWiseIndependentHash 5 h), using an original simplified dyadic-window proof adaptation in place of the interval-grid decompositions of Lemmas 4.2 and 4.4 in [PaghPaghRuzic2009]:

  1. Left-anchored cluster witness (HasClusterWitness, adapting the proof of Lemma 4.1, p. 1114): If probing key $u$ from $b = h_i(u)$ steps over $t \ge 1$ occupied slots belonging to $S = \mathrm{dom}(s) \setminus \{u\}$, walking backwards from $b$ to the nearest preceding empty slot yields a contiguous cyclic interval $J(b, a, \ell)$ (cyclicInterval M b a ℓ) of length $\ell = a + t \in [t, \#S]$ containing $b$ into which at least $\ell$ keys of $S$ hash.
  2. Centered dyadic-scale window (scaleWindow, original proof adaptation at load $\le 1/8$): For the dyadic scale $j = \lfloor \log_2 \ell \rfloor + 1 \in \{1, \dots, M\}$, we have $2^{j-1} \le \ell < 2^j$. Every cyclic interval $J(b, a, \ell)$ containing $b$ is contained in a single centered window $W_j(b)$ (scaleWindow M b j) of size at most $2^{j+1}$ (cyclicInterval_subset_scaleWindow, card_scaleWindow_le). Consequently, at least $2^{j-1}$ keys of $S$ hash into $W_j(b)$, whereas at load $\#S \le 2^M / 8$ the expected load of $W_j(b)$ is $\mu_{j,b} \le \#S \cdot 2^{j+1} / 2^M \le 2^{j-2}$, leaving deviation slack $2^{j-1} - \mu_{j,b} \ge 2^{j-2}$.
  3. Conditioned fourth-moment tail bound (expect_indicator_mul_sum_pow_four_le and expect_scaleOverload_le, adapting Lemma 2.1, pp. 1110–1111): Conditioning on $h_i(u) = b$ consumes $1$ degree of independence, leaving $4$-wise independence on $S$. Expanding the fourth central moment via IsKWiseIndependentHash.expect_prod on sets $\mathrm{insert}\ u\ (\mathrm{image}\ t)$ of size at most $5$ bounds the scale-$j$ overload probability (scaleOverload) by $18 / (2^{j-2})^2 = 288 / 4^j$, and summing $\sum_{j=1}^M 2^j \cdot (288 / 4^j)$ yields the original explicit constant upper bound $288 = O(1)$ on the expected number of skipped occupied slots (expect_probe_le_of_cluster_witness, tsum_uniform_probe_le_of_cluster_witness).

Main definitions #

Main results #

References #

Section 1: Table size parameters and load-factor bounds #

Base-2 logarithm $M = \lceil \log_2 \max(8 n_{\max}, 8) \rceil$ of the linear-probing table size, ensuring $M \ge 3$ and $8 n_{\max} \le 2^M < 16 \max(n_{\max}, 1)$.

Power-of-$2$ table size $m = 2^{\mathrm{tableLog}(n_{\max})}$.

The table size is at least $8 n_{\max}$ (load factor $\le 1/8$).

n_max is strictly less than tableSize n_max, so at least $7/8$ of the table slots are always empty.

tableSize n_max is strictly less than $16 \max(n_{\max}, 1)$.

tableSize n_max is at most $16 \max(n_{\max}, 1) = O(n_{\max})$.

Section 2: Fourth central moment under $5$-wise independence conditioned on $h_i(u) = b$ #

Centered indicator of a bucket subset W ⊆ Y: 1 - #W / |Y| on W and - #W / |Y| outside W.

The uniform expectation of bucketCentered W over a nonempty finite type Y is 0.

The second moment of bucketCentered W is at most p = #W / |Y|.

Any moment of degree c ≥ 2 of bucketCentered W has absolute value at most p = #W / |Y|.

theorem Cslib.DataStructure.Dictionary.WordRAM.LinearProbing.expect_indicator_mul_sum_pow_four_le {ι : Type u_1} {X : Type u_2} {Y : Type u_3} [Fintype ι] [Fintype Y] [DecidableEq Y] [Nonempty Y] {h : ι → X → Y} (hh : Probability.IsKWiseIndependentHash 5 h) (S : Finset X) {u : X} (hu : u ∉ S) (b : Y) (W : Finset Y) :
have p := ↑W.card / ↑(Fintype.card Y); (Finset.univ.expect fun (i : ι) => (if h i u = b then 1 else 0) * (∑ x ∈ S, bucketCentered W (h i x)) ^ 4) ≤ (Finset.univ.expect fun (y : Y) => if y = b then 1 else 0) * (↑S.card * p + 16 * (↑S.card * p) ^ 2)

Conditioned fourth-moment bound under $5$-wise independence: for a $5$-wise independent family h : ι → X → Y, a finite set S ⊆ X, a query point u ∉ S, a target bucket b : Y, and a window W ⊆ Y of density p = #W / |Y|, the expectation of (if h i u = b then 1 else 0) * (∑ x ∈ S, bucketCentered W (h i x)) ^ 4 is at most (𝔼 y, if y = b then 1 else 0) * (#S * p + 16 * (#S * p) ^ 2).

Section 3: Cyclic intervals, scale windows, and expected probe bound #

Slot in Fin (2 ^ M) corresponding to natural number x modulo 2 ^ M.

Contiguous cyclic interval of length len starting a slots before b in Fin (2 ^ M): $\{(b - a + \mathrm{idx}) \bmod 2^M \mid 0 \le \mathrm{idx} < \mathrm{len}\}$.

Slot probed at offset d from starting bucket b : Fin (2 ^ M): (b.val + d) mod 2 ^ M.

Slot located a positions cyclically before b : Fin (2 ^ M): (b.val - a) mod 2 ^ M.

theorem Cslib.DataStructure.Dictionary.WordRAM.LinearProbing.probeSlot_add {M : ℕ} (b : Fin (2 ^ M)) (d₁ d₂ : ℕ) :
probeSlot M (probeSlot M b d₁) d₂ = probeSlot M b (d₁ + d₂)
theorem Cslib.DataStructure.Dictionary.WordRAM.LinearProbing.probeSlot_backSlot_eq {M : ℕ} (b : Fin (2 ^ M)) (a idx : ℕ) :
probeSlot M (backSlot M b a) idx = cyclicSlotMod M (↑b + 2 ^ M * (a + 1) - a + idx)
theorem Cslib.DataStructure.Dictionary.WordRAM.LinearProbing.probeSlot_backSlot_sub {M : ℕ} (b : Fin (2 ^ M)) {a idx : ℕ} (hidx : idx ≤ a) :
probeSlot M (backSlot M b a) idx = backSlot M b (a - idx)
theorem Cslib.DataStructure.Dictionary.WordRAM.LinearProbing.backSlot_backSlot {M : ℕ} (b : Fin (2 ^ M)) (a₁ a₂ : ℕ) :
backSlot M (backSlot M b a₁) a₂ = backSlot M b (a₁ + a₂)
theorem Cslib.DataStructure.Dictionary.WordRAM.LinearProbing.card_cyclicInterval {M : ℕ} (b : Fin (2 ^ M)) (a : ℕ) {len : ℕ} (hlen : len ≤ 2 ^ M) :
(cyclicInterval M b a len).card = len

Centered dyadic-scale window $W_j(b)$ of width $2^{j+1}$ around $b$ in Fin (2 ^ M): $\{(b - 2^j + d) \bmod 2^M \mid 0 \le d < 2^{j+1}\}$.

The scale window scaleWindow M b j has at most 2 ^ (j + 1) elements.

theorem Cslib.DataStructure.Dictionary.WordRAM.LinearProbing.cyclicInterval_subset_scaleWindow {M : ℕ} (b : Fin (2 ^ M)) {a len j : ℕ} (ha : a < 2 ^ j) (hlen : len ≤ 2 ^ j) :
cyclicInterval M b a len ⊆ scaleWindow M b j

Every cyclic interval cyclicInterval M b a len with a < 2 ^ j and len ≤ 2 ^ j is a subset of the centered window scaleWindow M b j.

def Cslib.DataStructure.Dictionary.WordRAM.LinearProbing.scaleOverload {ι : Type u_1} {X : Type u_2} (M : ℕ) (h : ι → X → Fin (2 ^ M)) (S : Finset X) (u : X) (j : ℕ) (i : ι) :

Scale-$j$ window overload event: at least $2^{j-1}$ keys of $S$ hash into the centered window scaleWindow M (h i u) j around $h_i(u)$.

Instances For
    @[instance_reducible]
    instance Cslib.DataStructure.Dictionary.WordRAM.LinearProbing.instDecidablePredScaleOverload {ι : Type u_1} {X : Type u_2} (M : ℕ) (h : ι → X → Fin (2 ^ M)) (S : Finset X) (u : X) (j : ℕ) :
    theorem Cslib.DataStructure.Dictionary.WordRAM.LinearProbing.expect_scaleOverload_le {ι : Type u_1} {X : Type u_2} [Fintype ι] {M n_max j : ℕ} {h : ι → X → Fin (2 ^ M)} (hh : Probability.IsKWiseIndependentHash 5 h) (S : Finset X) {u : X} (hu : u ∉ S) (hS : S.card ≤ n_max) (hM : 8 * n_max ≤ 2 ^ M) :
    (Finset.univ.expect fun (i : ι) => if scaleOverload M h S u j i then 1 else 0) ≤ 288 / (2 ^ j) ^ 2

    Scale-$j$ overload probability bound: when 8 * n_max ≤ 2 ^ M, #S ≤ n_max, u ∉ S and hh : IsKWiseIndependentHash 5 h, the probability of scaleOverload M h S u j is at most 288 / (2 ^ j : ℝ) ^ 2. At j = 0 this is the trivial bound 288.

    def Cslib.DataStructure.Dictionary.WordRAM.LinearProbing.HasClusterWitness {ι : Type u_1} {X : Type u_2} {M : ℕ} (h : ι → X → Fin (2 ^ M)) (S : Finset X) (u : X) (i : ι) (t : ℕ) :

    Left-anchored cluster witness predicate for hash family h at (S, u, i, t): if 1 ≤ t, there is a cyclic interval cyclicInterval M (h i u) a ℓ of length ℓ ∈ [t, #S] with a < ℓ into which at least ℓ keys of S hash.

    Instances For
      theorem Cslib.DataStructure.Dictionary.WordRAM.LinearProbing.le_sum_scaleOverload_of_cyclicInterval {ι : Type u_1} {X : Type u_2} {M : ℕ} (h : ι → X → Fin (2 ^ M)) (S : Finset X) (u : X) (i : ι) {x a len k : ℕ} (hx : 1 ≤ x) (hxM : x < 2 ^ M) (ha : a < 2 ^ (Nat.log 2 x + 1)) (hlen : len ≤ 2 ^ (Nat.log 2 x + 1)) (hcard : 2 ^ Nat.log 2 x ≤ {y ∈ S | h i y ∈ cyclicInterval M (h i u) a len}.card) (hk : k ≤ 2 ^ (Nat.log 2 x + 1)) :
      ↑k ≤ ∑ j ∈ Finset.Icc 1 M, 2 ^ j * if scaleOverload M h S u j i then 1 else 0

      Dyadic scale bound. Let j = Nat.log 2 x + 1 be the dyadic scale of 1 ≤ x < 2 ^ M. If a cyclic interval cyclicInterval M (h i u) a len with a < 2 ^ j and len ≤ 2 ^ j holds at least 2 ^ (j - 1) keys of S, the scale-j window is overloaded, so every k ≤ 2 ^ j is bounded by the dyadic scale-overload sum.

      theorem Cslib.DataStructure.Dictionary.WordRAM.LinearProbing.expect_probe_le_of_cluster_witness {ι : Type u_1} {X : Type u_2} [Fintype ι] {M n_max : ℕ} {h : ι → X → Fin (2 ^ M)} (hh : Probability.IsKWiseIndependentHash 5 h) (S : Finset X) {u : X} (hu : u ∉ S) (hS : S.card ≤ n_max) (hM : 8 * n_max ≤ 2 ^ M) (probe : ι → ℕ) (hwit : ∀ (i : ι), HasClusterWitness h S u i (probe i)) :
      (Finset.univ.expect fun (i : ι) => ↑(probe i)) ≤ 288

      If a nonnegative probe count probe : ι → ℕ satisfies the left-anchored cluster witness property — every seed i with 1 ≤ probe i has an occupied cyclic interval cyclicInterval M (h i u) a ℓ of length ℓ ∈ [probe i, #S] with 0 ≤ a < ℓ into which at least ℓ keys of S hash — then under a 5-wise independent hash family at load factor 8 * n_max ≤ 2 ^ M and #S ≤ n_max, the expected probe count is at most 288.

      theorem Cslib.DataStructure.Dictionary.WordRAM.LinearProbing.sum_probe_le_of_cluster_witness {ι : Type u_1} {X : Type u_2} [Fintype ι] {M n_max : ℕ} {h : ι → X → Fin (2 ^ M)} (hh : Probability.IsKWiseIndependentHash 5 h) (S : Finset X) {u : X} (hu : u ∉ S) (hS : S.card ≤ n_max) (hM : 8 * n_max ≤ 2 ^ M) (probe : ι → ℕ) (hwit : ∀ (i : ι), HasClusterWitness h S u i (probe i)) :
      ∑ i : ι, probe i ≤ 288 * Fintype.card ι

      Natural-number sum form of expect_probe_le_of_cluster_witness: the sum of probe i over all seeds i : ι is at most 288 * Fintype.card ι.

      theorem Cslib.DataStructure.Dictionary.WordRAM.LinearProbing.tsum_uniform_probe_le_of_cluster_witness {ι : Type u_1} {X : Type u_2} [Fintype ι] [Nonempty ι] {M n_max : ℕ} {h : ι → X → Fin (2 ^ M)} (hh : Probability.IsKWiseIndependentHash 5 h) (S : Finset X) {u : X} (hu : u ∉ S) (hS : S.card ≤ n_max) (hM : 8 * n_max ≤ 2 ^ M) (probe : ι → ℕ) (hwit : ∀ (i : ι), HasClusterWitness h S u i (probe i)) :
      ∑' (i : ι), (Probability.PMF.uniformOfFintype ι) i * ↑(probe i) ≤ 288

      ℝ≥0∞ expectation form of expect_probe_le_of_cluster_witness under PMF.uniformOfFintype: ∑' i, (PMF.uniformOfFintype ι) i * (probe i : ℝ≥0∞) ≤ 288.