Advanced Algorithms Computer Science, ETH Z¨urich
Mohsen Ghaffari
These notes will be updated regularly. Please read critically; there are typos throughout, but there might also be mistakes. Feedback and comments would be greatly appreciated and should be emailed to ghaff[email protected]. Last update: March 10, 2020
Contents
Notation and useful inequalities
I Approximation algorithms1
1 Greedy algorithms3 1.1 Minimum set cover...... 3
2 Approximation schemes 11 2.1 Knapsack...... 12 2.2 Bin packing...... 14 2.3 Minimum makespan scheduling...... 20
3 Randomized approximation schemes 27 3.1 DNF counting...... 27 3.2 Counting graph colorings...... 32
4 Rounding ILPs 37 4.1 Minimum set cover...... 38 4.2 Minimizing congestion in multi-commodity routing...... 43
5 Probabilistic tree embedding 51 5.1 A tight probabilistic tree embedding construction...... 52 5.2 Application: Buy-at-bulk network design...... 60 5.3 Extra: Ball carving with O(log n) stretch factor...... 61
II Streaming and sketching algorithms 65
6 Warm up 67 6.1 Typical tricks...... 67 6.2 Majority element...... 68 7 Estimating the moments of a stream 71 7.1 Estimating the first moment of a stream...... 71 7.2 Estimating the zeroth moment of a stream...... 73 7.3 Estimating the kth moment of a stream...... 80
8 Graph sketching 89 8.1 Warm up: Finding the single cut...... 90 8.2 Warm up 2: Finding one out of k > 1 cut edges...... 92 8.3 Maximal forest with O(n log4 n) memory...... 93
III Graph sparsification 97
9 Preserving distances 99 9.1 α-multiplicative spanners...... 100 9.2 β-additive spanners...... 102
10 Preserving cuts 111
10.1 Warm up: G = Kn ...... 113 10.2 Uniform edge sampling...... 113 10.3 Non-uniform edge sampling...... 115
IV Online algorithms and competitive analysis 121
11 Warm up: Ski rental 123
12 Linear search 125 12.1 Amortized analysis...... 125 12.2 Move-to-Front...... 126
13 Paging 129 13.1 Types of adversaries...... 130 13.2 Random Marking Algorithm (RMA)...... 131
14 Yao’s Minimax Principle 135 14.1 Application to the paging problem...... 136
15 The k-server problem 137 15.1 Special case: Points on a line...... 138 16 Multiplicative Weights Update (MWU) 143 16.1 Warm up: Perfect expert exists...... 144 16.2 A deterministic MWU algorithm...... 144 16.3 A randomized MWU algorithm...... 145 16.4 Generalization...... 147 16.5 Application: Online routing of virtual circuits...... 147
Notation and useful inequalities
Commonly used notation
•P : class of decision problems that can be solved on a deterministic sequential machine in polynomial time with respect to input size
•NP : class of decision problems that can be solved non-deterministically in polynomial time with respect to input size. That is, decision prob- lems for which “yes” instances have a proof that can be verified in polynomial time.
•A : usually denotes the algorithm we are discussing about
•I : usually denotes a problem instance
• ind.: independent / independently
• w.p.: with probability
• w.h.p: with high probability We say event X holds with high probability (w.h.p.) if
1 Pr[X] ≥ 1 − poly(n)
1 say, Pr[X] ≥ 1 − nc for some constant c ≥ 2. • L.o.E.: linearity of expectation
• u.a.r.: uniformly at random
• Integer range [n] = {1, . . . , n}
• e ≈ 2.718281828459: the base of the natural logarithm Useful distributions
Bernoulli Coin flip w.p. p. Useful for indicators Pr[X = 1] = p E[X] = p Var(X) = p(1 − p)
Binomial Number of successes out of n trials, each succeeding w.p. p; Sample with replacement out of n items, p of which are successes n Pr[X = k] = pk(1 − p)n−k k E[X] = np Var(X) = np(1 − p) ≤ np
Geometric Number of Bernoulli trials until one success Pr[X = k] = (1 − p)n−1p 1 [X] = E p 1 − p Var(X) = p2
Hypergeometric r successes in n draws without replacement when there are K successful items in total K n−k r r−k Pr[X = k] = n r k [X] = r · E n k n − k n − r Var(X) = r · · · n n n − 1
Exponential Parameter: λ; Written as X ∼ Exp(λ) ( λe−λx if x ≥ 0 Pr[X = x] = 0 if x < 0 1 [X] = E λ 1 Var(X) = λ2 Remark If x1 ∼ Exp(λ1), . . . , xn ∼ Exp(λn), then
• min{x1, . . . , xn} ∼ Exp(λ1 + ··· + λn)
λk • Pr[k | xk = min{x1, . . . , xn}] = λ1+···+λn
Useful inequalities
n k n en k • ( k ) ≤ k ≤ ( k ) n k • k ≤ n 1 n −1 • limn→∞(1 − n ) = e
P∞ 1 π2 • i=1 i2 = 6 • (1 − x) ≤ e−x, for any x
• (1 + 2x) ≥ ex, for x ∈ [0, 1]
x x • (1 + 2 ) ≥ e , for x ∈ [−1, 0]
−x−x2 1 • (1 − x) ≥ e , for x ∈ (0, 2 ) 1 1 • 1−x ≤ 1 + 2x for x ≤ 2 Theorem (Linearity of Expectation).
n n X X E( aiXi) = aiE(Xi) i=1 i=1 Theorem (Variance).
2 2 V(X) = E(X ) − E(X) Theorem (Variance of a Sum of Random Variables).
2 2 V(aX + bY ) = a V(X) + b V(Y ) + 2abCov(X,Y )
Theorem (AM-GM inequality). Given n numbers x1, . . . , xn, x + ··· + x 1 n ≥ (x ∗ · · · ∗ x )1/n n 1 n
The equality holds if and only if x1 = ··· = xn. Theorem (Markov’s inequality). If X is a nonnegative random variable and a > 0, then (X) Pr[X ≥ a] ≤ E a Theorem (Chebyshev’s inequality). If X is a random variable (with finite expected value µ and non-zero variance σ2), then for any k > 0,
1 Pr[|X − µ| ≥ kσ] ≤ k2
Theorem (Bernoulli’s inequality). For every integer r ≥ 0 and every real number x ≥ −1, (1 + x)r ≥ 1 + rx
Theorem (Chernoff bound). For independent Bernoulli variables X1,...,Xn, Pn let X = i=1 Xi. Then,
−2 (X) Pr[X ≥ (1 + ) · (X)] ≤ exp( E ) for 0 < E 3 −2 (X) Pr[X ≤ (1 − ) · (X)] ≤ exp( E ) for 0 < < 1 E 2
By union bound, for 0 < < 1, we have
−2 (X) Pr[|X − (X)| ≥ · (X)] ≤ 2 exp( E ) E E 3
Remark 1 There is actually a tighter form of Chernoff bounds:
e ∀ > 0, Pr[X ≥ (1 + ) (X)] ≤ ( )E(X) E (1 + )1+
Remark 2 We usually apply Chernoff bound to show that the probability 2 − E(X) of bad approximation is low by picking parameters such that 2 exp( 3 ) ≤ δ, then negate to get Pr[|X − E(X)| ≤ · E(X)] ≥ 1 − δ.
Theorem (Probabilistic Method). Let (Ω, A,P ) be a probability space,
Pr[ω] > 0 ⇐⇒ ∃ω ∈ Ω Combinatorics taking k elements out of n: