At its core, Hashing is Dimensionality Reduction:
2026A7PS0123H).Insert, Lookup, Delete) via direct O(1) Word RAM addressing.The Dictionary Problem maintains a dynamic set S \subseteq U of n active elements (n \ll |U|):
Insert(key, value), Delete(key), Lookup(key) -> value.dict, JS objects, and JVM symbol tables.How does Hashing achieve O(1) operations instead of O(\log n) tree traversals?
Why can’t we simply use a direct array indexed by key value?
When multiple keys hash to the same slot, we store them in a linked list:
Why is any fixed deterministic hash (e.g., h(k) = k \bmod m) fatal?
Definition: Universal Hash Family
A collection \mathcal{H} = \{h: U \to \{0, \dots, m-1\}\} is universal if for all distinct x \neq y \in U: \Pr_{h \sim \mathcal{H}}\big[\, h(x) = h(y) \,\big] \le \frac{1}{m}
Theorem: Expected Search Time (Carter & Wegman, 1979)
If h \sim \mathcal{H} is universal, expected search time on n keys with chaining is O(1 + \alpha), where \alpha = n/m.
Choose prime p \ge |U|. The Carter–Wegman linear family: \mathcal{H}_{p,m} = \left\{\, h_{a,b}(x) = ((ax + b) \bmod p) \bmod m \;\mid\; a \in \mathbb{Z}_p^*,\, b \in \mathbb{Z}_p \,\right\}
How does single-hash chaining behave in the worst case?
For static sets (S fixed, no inserts/deletes), can we achieve O(1) worst-case lookup in O(n) space?
Why does secondary table size m_i = n_i^2 guarantee zero collisions?
Expected Collisions at Level 2 (Birthday Paradox): \mathbb{E}[\text{collisions in } S_i] = \binom{n_i}{2} \frac{1}{m_i} = \frac{n_i(n_i-1)}{2 n_i^2} < \frac{1}{2}
Applying Markov’s Inequality: \Pr[\text{collisions} \ge 1] \le \frac{\mathbb{E}[\text{collisions}]}{1} < \frac{1}{2}
Result: With probability \ge 1/2, S_i has zero collisions. A collision-free h_i is found in \le 2 draws on average!
Worst-Case Search Time: Compute i = h(x), then look up S_i[h_i(x)] \implies strictly 2 memory probes (O(1) worst-case)! \quad\blacksquare
Does allocating quadratic secondary tables m_i = n_i^2 blow up total space?
Total Space Formula: \text{Space} = \sum_{i=1}^n n_i^2 = n + 2 \sum_{x < y} I_{x,y}.
Expected Space: By universality of primary hash function h: \mathbb{E}\left[\sum_{i=1}^n n_i^2\right] = n + 2\binom{n}{2}\frac{1}{n} < \mathbf{2n}
Markov Space Guarantee: \Pr\left[\sum n_i^2 \ge 4n\right] \le \frac{2n}{4n} = \frac{1}{2}.
Conclusion: Total space across all secondary tables is strictly < 2n = \mathbf{O(n)}. \quad\blacksquare
| Structure | Lookup | Insert / Delete | Guarantee | Space |
|---|---|---|---|---|
| Skip Lists (L11) | O(\log n) | O(\log n) | High Probability (Ordered) | O(n) |
| Universal Chaining (L12) | O(1) | O(1) | Expected Only (Unordered) | O(n) |
| FKS Perfect Hashing (L13) | O(1) | \times | Worst-Case (Static Only) | O(n) |
Q1: Why is pairwise independence sufficient for universal chaining?
Search time is the sum of pairwise collision indicators \sum_{y \neq x} I_{x,y}. Linearity of expectation requires only that each pair collides with \Pr \le 1/m.
Q2: Why does FKS Level 2 (m_i = n_i^2) achieve zero collisions?
By the Birthday Paradox, \mathbb{E}[\text{coll}] < 1/2. By Markov’s inequality, \Pr[\ge 1 \text{ coll}] < 1/2. A fresh universal draw succeeds in \le 2 tries.
Q3: Why can’t FKS be used efficiently for dynamic sets?
Adding 1 key forces quadratic table reallocation (n_i+1)^2, requiring expensive \Omega(n_i^2) rehashes on updates.
Randomized & Algebraic Shortest Paths (Lecture 14):
CS G526: Advanced Algorithms & ComplexityTulasimohan Molli