TExcelTAD
Home › Randomized Algorithms & Probabilistic Analysis › Randomized Algorithms: What This Course Covers

Randomized Algorithms: What This Course Covers

Part I of the track used randomness in a few places: randomized quicksort and quickselect, universal hashing, Rabin-Karp and Miller-Rabin. This course, the second of Part II, treats randomness as an algorithmic resource in its own right. It answers three questions. How do we prove that a randomized algorithm is fast or correct with high probability, not just on average? Which problems become simpler, faster, or possible at all with random bits? And when can the randomness be removed again?

The topic order follows the two standard graduate texts, Randomized Algorithms by Motwani and Raghavan (1995) and Probability and Computing by Mitzenmacher and Upfal (2005; second edition 2017). Every explanation, example, program and exercise here is written from scratch. Good companions for single sections are Markov Chains and Mixing Times by Levin, Peres and Wilmer for the Markov-chain lessons, The Probabilistic Method by Alon and Spencer for the local lemma and derandomization, and Concentration of Measure for the Analysis of Randomized Algorithms by Dubhashi and Panconesi for tail bounds.

A taste in one program

Three of the course's algorithms, each in a few lines: checking a matrix product without recomputing it, finding a minimum cut by contracting random edges, and balancing load with two random choices.

python · try it yourself
import random

rng = random.Random(1)

# 1. Freivalds: is A B = C?  Three matrix-vector products instead of a matrix product.
n = 30
A = [[rng.randrange(10) for _ in range(n)] for _ in range(n)]
B = [[rng.randrange(10) for _ in range(n)] for _ in range(n)]
C = [[sum(A[i][k] * B[k][j] for k in range(n)) for j in range(n)] for i in range(n)]
C[17][4] += 1                                         # one wrong entry
mv = lambda M, v: [sum(a * b for a, b in zip(row, v)) for row in M]
caught = 0
for _ in range(20):
    r = [rng.randrange(2) for _ in range(n)]
    caught += mv(A, mv(B, r)) != mv(C, r)
print(f"Freivalds: wrong product caught in {caught} of 20 rounds (each round catches it w.p. 1/2)")

# 2. Karger: contract random edges of two 5-cliques joined by one edge until 2 vertices remain.
edges = [(u + s, v + s) for s in (0, 5) for u in range(5) for v in range(u + 1, 5)] + [(0, 5)]
def contract(edges):
    parent = list(range(10))
    def find(x):
        while parent[x] != x:
            x = parent[x]
        return x
    order, groups = edges[:], 10
    rng.shuffle(order)
    for u, v in order:
        if groups > 2 and find(u) != find(v):
            parent[find(u)] = find(v)
            groups -= 1
    return sum(find(u) != find(v) for u, v in edges)
results = [contract(edges) for _ in range(200)]
print(f"Karger: minimum cut 1 found in {results.count(1)} of 200 runs (guaranteed rate >= 2/(n(n-1)) = 0.022)")

# 3. Balls into bins: one random bin, or the less loaded of two?
bins = 10000
one, two = [0] * bins, [0] * bins
for _ in range(bins):
    a, b = rng.randrange(bins), rng.randrange(bins)
    one[a] += 1
    two[a if two[a] <= two[b] else b] += 1
print(f"{bins} balls in {bins} bins: fullest bin {max(one)} with one choice, {max(two)} with two")
Freivalds: wrong product caught in 11 of 20 rounds (each round catches it w.p. 1/2)
Karger: minimum cut 1 found in 91 of 200 runs (guaranteed rate >= 2/(n(n-1)) = 0.022)
10000 balls in 10000 bins: fullest bin 7 with one choice, 3 with two

What the course covers

Section Topics Main results
Foundations Las Vegas and Monte Carlo algorithms, amplification, expectation tools ZPP = RP ∩\cap co-RP; majority votes and the median trick decay exponentially
Tail bounds Markov, Chebyshev, Chernoff, Hoeffding, the union bound, the Lovász Local Lemma, Moser-Tardos Pr⁡[X≥(1+δ)μ]≤e−δ2μ/3\Pr[X \ge (1+\delta)\mu] \le e^{-\delta^2\mu/3}; set balancing within 4nln⁡n\sqrt{4n\ln n}; e p (d+1)≤1e\,p\,(d+1) \le 1 suffices; m/dm/d expected resamplings
Graph and algebraic algorithms Karger, Karger-Stein, Freivalds, Schwartz-Zippel, Tutte matrices min cut w.p. ≥2/(n(n−1))\ge 2/(n(n-1)) per run, O(n2log⁡3n)O(n^2 \log^3 n) overall; PIT error ≤d/∣S∣\le d/\lvert S \rvert
Hashing and load balancing kk-wise independence, FKS perfect hashing, maximum load, two choices O(n)O(n) space and O(1)O(1) worst-case lookups; max load Θ(ln⁡n/ln⁡ln⁡n)\Theta(\ln n/\ln\ln n) vs ln⁡ln⁡n/ln⁡2+O(1)\ln\ln n/\ln 2 + O(1)
Markov chains and random walks 2-SAT and 3-SAT walks, mixing time, coupling, conductance, MCMC n2n^2 expected steps for 2-SAT; (4/3)n(4/3)^n for 3-SAT; tmix≤nln⁡n+O(n)t_{\text{mix}} \le n \ln n + O(n) on the hypercube; Cheeger
Derandomization conditional expectations, pairwise independence, small sample spaces deterministic m/2m/2 cuts and 7m/87m/8 for MAX-3SAT

The mini project builds a minimum-cut finder with Karger and Karger-Stein and measures their success rates over seeded trials. The Exercises collect problems from every section.

Conventions

  • "With high probability" (w.h.p.) means with probability at least 1−n−c1 - n^{-c} for some constant c>0c > 0, usually c=1c = 1, where nn is the input size. Every bound in the course says whether it holds in expectation or w.h.p., and which independence it needs.
  • Pseudocode is 0-based and in the track's style (How to read pseudocode); lg⁡n=log⁡2n\lg n = \log_2 n and ln⁡n\ln n is the natural logarithm.
  • Every random choice in a program comes from a generator with a fixed seed (random.Random(seed) in Python, std::mt19937 in C++), so the printed numbers are reproducible and match the text exactly. The C++ examples use a different generator from Python's, so their measured rates differ slightly from the Python ones; the text says so each time. Indices are drawn as rng() % n, which has a negligible bias and gives identical results on every standard library.
  • Costs are counted (steps, probes, multiplications, resamplings), never timed.
  • Theorems that are only stated or sketched are marked as such, with a reference for the full proof.

What you should know first

The course assumes Probability, especially expectation, independence, variance, Markov's and Chebyshev's Inequalities, Moment Generating Functions and Markov Chains. From Part I it uses Indicator Random Variables, Randomized Quicksort, Universal Hashing, union-find, Miller-Rabin and the NP-completeness of 3-CNF-SAT. Later Part II courses build on this one, above all Streaming, Sketching & Sublinear Algorithms and the randomized-rounding parts of Approximation Algorithms.

Test yourself

In this course, what does "with high probability" mean?

  1. With probability at least 1/21/2
  2. With probability at least 1−n−c1 - n^{-c} for a constant c>0c > 0
  3. With probability 1
  4. In expectation

Why do the C++ examples print slightly different measured rates than the Python ones?

  1. C++ is less accurate
  2. They use a different pseudo-random generator, so the random choices differ, although both are seeded and reproducible
  3. Python rounds differently
  4. Compiler Explorer adds noise

Which of these is a Monte Carlo algorithm with one-sided error?

  1. Randomized quicksort
  2. Freivalds' matrix-product check
  3. FKS perfect hashing
  4. Randomized quickselect