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?
Does allocating quadratic secondary tables m_i = n_i^2 blow up total space?
| 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 Graph Algorithms (Lecture 14):
CS G526: Advanced Algorithms & ComplexityTulasimohan Molli