A second, unrelated way to exploit having two hash functions — the last hashing topic of the course (43:34, 44:13).
Baseline: hashing with chaining / balls into bins
- Hash table of
mcells, each cell a pointer to a doubly linked list of the items hashing there (44:37). - Query time = length of that list (
46:53). - With
m = nand a perfectly randomh, this isnballs intonbins; the heaviest bin holds Θ(log n / log log n) balls — better thanlog n, but not much better (45:14,46:26). - With a merely 2-wise independent
h, expected query time isO(1), and w.h.p. the worst case is at mostlog n / log log n(46:53,47:10). - Goal: keep the constant expectation and get a much better worst case (
47:10).
The scheme — Azar, Broder, Karlin, Upfal (SICOMP '99)
(47:27)
- Pick two random hash functions
gandh. - Insert
x: place it in the least loaded ofA[g(x)]andA[h(x)]. - Query
x: search both locations (48:45). - In balls-and-bins terms: sample two bins per ball, drop it into the smaller (
48:45).
The result
- W.h.p. the heaviest bin has
ln ln n / ln 2 + Θ(1)items (49:39). - The distribution is tightly concentrated: that value ± a constant (
50:23). - This is an exponential improvement — roughly
log ndown tolog log n— from a trivially simple change (50:23).
Power of d choices — diminishing returns
- Natural extension: hash to
dlocations, insert into the least loaded; query cost rises by a factor ofdin expectation (50:52). - Result:
ln ln n / ln d(51:17). - The jump is all in the first extra choice: 1 → 2 goes
log→log log; 2 →donly changes the base of the log, i.e. a constant factor (51:17,51:57).
Vöcking's variant — asymmetry beats randomness
Stated without proof (52:19, 52:40):
- Split the bins into
dgroups ofn/dbins each. - Probe one random location per group (not
dfree random locations) (53:25). - Insert into the least loaded, breaking ties by taking the leftmost bin — counter-intuitively not a random tie-break (
53:25,54:12).
- Heaviest load becomes
ln ln n / d, with the exact constant proved (54:44). - Interpretation: the effective log base goes from
dtoe^d— an exponential gain over plain power-of-d, purely from the group structure plus the deterministic tie-break (54:44,55:10).
| Scheme | Max load w.h.p. |
|---|---|
| 1 choice (plain chaining) | Θ(log n / log log n) (46:26) |
| 2 choices | ln ln n / ln 2 + Θ(1) (49:39) |
d choices | ln ln n / ln d (51:17) |
Vöcking (d groups, leftmost tie-break) | ln ln n / d (54:44) |