1.4 Chernoff and Hoeffding Bounds

Exercise 1.4.1 (Exercise 4.9 [MU17]).

Suppose that we can obtain independent samples {Xi}i∈[1,n] of a random variable X and that we want to use these samples to estimate 𝔼[X]. Using t samples, we use (∑i∈[1,t]Xi)/t for our estimate of 𝔼[X]. We want the estimate to be within ε⁢𝔼[X] from the true value of 𝔼[X] with probability at least 1−δ. We may not be able to use Chernoff’s bound directly to bound how good our estimate is if X is not a 0-1 random variable, and we do not know its moment generating function. We develop an alternative approach that requires only having a bound on the variance of X. Let r=Var⁢[X]/𝔼[X].

  • •

    Show using Chebyshev’s inequality that O⁢(r2/ε2⁢δ) samples are sufficient to solve the problem.

  • •

    Suppose that we need only a weak estimate that is within ε⁢𝔼[X] of 𝔼[X] with probability at least 3/4. Argue that O⁢(r2/ε2) samples are enough for this weak estimate.

  • •

    Show that, by taking the median of O⁢(log⁡(1/δ)) independent weak estimates, we can obtain an estimate within ε⁢𝔼[X] of 𝔼[X] with probability at least 1−δ. Conclude that we need only O⁢((r2⁢log⁡(1/δ))/ε2) samples.

Proof.

Let Y=∑i∈[1,t]Xi, then 𝔼[Y]=t⋅𝔼[X] and Var⁢[Y]=Var⁢[∑i∈[1,t]Xi]=t⋅Var⁢[X].

By Chebyshev’s inequality,

Pr⁡[|1t⋅Y−𝔼[X]|≥ε⁢𝔼[X]] =Pr⁡[|Y−𝔼[Y]|≥ε⁢𝔼[Y]]
≤Var⁢[Y]ε2𝔼[Y]2=Var⁢[X]tε2𝔼[X]2=r2t⁢ε2≤δ.

Now that t≥r2/δ⁢ε2, thus t=O⁢(r2/δ⁢ε2).

Suppose δ≤1/4, then t≥4⁢r2/ε2, and thus t=O⁢(r2/ε2).

When it comes to using a median of s weak estimates to boost the confidence in estimation, we have a trick called Median of Mean (MoM) [JVV86]. The key idea is to take advantage of the “structure” of median value, that half of the weak estimates are smaller, while the other half are greater.

Since we hope with probability at least 1−δ, the median of weak estimates is within ε⁢𝔼[X] range, then we say the bad event is the median of weak estimates is out of ε⁢𝔼[X] range. Equivalently, a bad event occurs when more than half of the weak estimates are above (1+ε)⁢𝔼[X], or more than half of them are below (1−ε)⁢𝔼[X].

Form each weak estimate from an independent batch of O⁢(r2/ε2) samples, so the weak estimates are independent. In this sense, we introduce independent 0-1 random variables (indicators) {1L,i}i∈[1,s] and {1R,i}i∈[1,s] where

  • •

    1L,i=1 only when ith weak estimate is smaller than (1−ε)⁢𝔼[X],

  • •

    1R,i=1 only when ith weak estimate is greater than (1+ε)⁢𝔼[X],

and 1L=∑i∈[1,s]1L,i, 1R=∑i∈[1,s]1R,i. Since a weak estimate is within ε⁢𝔼[X] range with probability at least 3/4, we have both Pr⁡[1L,i=1] and Pr⁡[1R,i=1] upper bounded by 1/4, and thus both 𝔼[1L] and 𝔼[1R] are at most s/4.

We first bound 1L, and derive 1R by symmetry. By Chernoff’s bound,

Pr⁡[1L≥s2]≤𝔼[exp⁡(t⋅1L)]/exp⁡(s2⋅t)≤exp⁡(s4⋅(et−1)−s2⋅t)=exp⁡(φ⁢(t)).

Then we have φ′⁢(t)=s4⋅et−s2, and derive that φ⁢(t) min by t=ln⁡2 for a positive t. Now that

exp⁡((14−ln⁡22)⋅s)≤δ2,

we have s≥((ln⁡2)/2−1/4)−1⋅ln⁡(2/δ), thus s=O⁢(log⁡(1/δ)).

We thus conclude that we need O⁢(r2⁢log⁡(1/δ)/ε2) samples in total. ∎

Exercise 1.4.2 (Exercise 4.12 [MU17]).

Consider a collection {Xi}i∈[1,n] of n independent geometrically distributed random variables with mean 2. Let X=∑i∈[1,n]Xi and δ>0.

  • •

    Derive a bound on Pr⁡[X≥(1+δ)⋅2⁢n] by applying Chernoff’s bound to a sequence of (1+δ)⋅2⁢n fair coin tosses.

  • •

    Directly derive a Chernoff’s bound on Pr⁡[X≥(1+δ)⋅2⁢n] using the MGF for geometric random variables.

  • •

    Compare these 2 bounds derived above.

Proof.

A way to model the “Coupon Collection” alike problem for bounding the sum of geometrically distributed random variables is transforming to an upper bound to the sum of a sequence of Bernoulli trials.

Since a geometrically distributed random variable can be seen as the number of Bernoulli trials until one success, then for event X≥(1+δ)⋅2⁢n, there are at most n successes among (1+δ)⋅2⁢n independent Bernoulli trials (in the worst case, the last trial must be success among n successes in total (1+δ)⋅2⁢n trials).

We write Yi as ith independent Bernoulli trial with success probability being 1/2 among (1+δ)⋅2⁢n trials, we write Y=∑i∈[1,(1+δ)⋅2⁢n]Yi, and 𝔼[Y]=(1+δ)⋅n. We thus can upper bound Pr⁡[X≥(1+δ)⋅2⁢n] by Pr⁡[Y≤n], as we can loosen the boundary condition on the worst case, where last trial must be successful among n successes.

By Chernoff’s bound for bounding the deviation below the mean, we have

Pr⁡[X≥(1+δ)⋅2⁢n] ≤Pr⁡[Y≤n]
≤𝔼[exp⁡(t⁢Y)]exp⁡(n⋅t)
≤exp⁡((1+δ)⋅n⋅(et−1))exp⁡(n⋅t)
=exp⁡((1+δ)⋅n⋅(et−1)−n⋅t)=exp⁡(φ⁢(t))

with t<0, and min by t=−ln⁡(1+δ) deriving a upper bound ((1+δ)⋅e−δ)n.

If we brute force for a bound on X=∑i∈[1,n]Xi, the MGF of Xi is MXi⁢(t)=∑k≥1exp⁡(k⁢t)⋅2−k=∑k≥1(et/2)k. When 0<t<ln⁡2, MXi⁢(t)=et/(2−et). Again by Chernoff’s bound for bounding the deviation above the mean,

Pr⁡[X≥(1+δ)⋅2⁢n] ≤(MXi⁢(t)exp⁡((1+δ)⋅2⁢t))n
=((2−et)⁢exp⁡((2⁢δ+1)⋅t))−n
=(2⁢exp⁡((2⁢δ+1)⋅t)−exp⁡((2⁢δ+2)⋅t))−n=φ⁢(t)−n,

and φ′⁢(t)=(4⁢δ+2)⁢exp⁡((2⁢δ+1)⋅t)−(2⁢δ+2)⁢exp⁡((2⁢δ+2)⋅t), and thus φ⁢(t) max by t=ln⁡(2⁢δ+1)−ln⁡(δ+1),

Pr⁡[X≥(1+δ)⋅2⁢n]≤(1δ+1⋅(2⁢δ+1δ+1)2⁢δ+1)−n=((1+δ)⋅(δ+12⁢δ+1)2⁢δ+1)n.

By section 1.5.1, we know the first one is looser. ∎

Exercise 1.4.3 (Exercise 4.8 [MU17]).

We show how to construct a random permutation π on [1,n], given a black box that outputs numbers independently and uniformly at random from [1,k] where k≥n. If we compute a function f:[1,n]→[1,k] with f⁢(i)≠f⁢(j) for i≠j, this yields a permutation, by outputting [1,n] according to the order of {f⁢(i)}i∈[1,n]. To construct such a function f, do the following for i∈[1,n]: choose f⁢(i) by repeatedly drawing number from the black box and set f⁢(i) to the first number that is f⁢(i)≠f⁢(j) for j<i.

Prove that this approach gives a permutation chosen uniformly at random for all permutations. Find the expected number of calls to the black box that are needed when k=n and k=2⁢n. For the case k=2⁢n, argue that the probability that each call to the black box assigns a value of f⁢(j) to some j is at least 1/2. Based on this, use a Chernoff bound to bound the probability that the number of calls to the black box is at least 4⁢n.

Proof.

At the first sight, this is a “Coupon Collection” problem, where we can introduce n independent geometrically distributed random variables {Xi}i∈[1,n] each with success probability pi=(k+1−i)/k, and we write X=∑i∈[1,n]Xi. When k=2⁢n, each pi≥1/2 as pn=(n+1)/2⁢n.

For expectation of X, 𝔼[X]=∑i∈[1,n]𝔼[Xi] by linearity of expectation. For 𝔼[Xi], by conditional expectation and memoryless of geometric distribution,

𝔼[Xi] =𝔼[Xi∣Xi,0=1]⋅Pr⁡[Xi,0=1]+𝔼[Xi∣Xi,0=0]⋅Pr⁡[Xi,0=0]
=1⋅pi+(1+𝔼[Xi])⋅(1−pi),

𝔼[Xi]=pi−1=k/(k−i+1). Thus 𝔼[X]=n⁢ln⁡n+Θ⁢(n) when k=n, 𝔼[X]=2⁢n⁢(ln⁡2⁢n−ln⁡n)+Θ⁢(n) when k=2⁢n.

For upper bounding Pr⁡[X≥4⁢n], we first upper bound by Pr⁡[Y≥4⁢n], where {Yi}i∈[1,n] are n independent geometrically distributed random variables, each with success probability 1/2, and we write Y=∑i∈[1,n]Yi. Then we upper bound Pr⁡[Y≥4⁢n] by Pr⁡[Z≤n] through the previous trick of turning sum of geometrically distributed random variables into sum of a sequence of Bernoulli trials. We introduce 4⁢n independent Bernoulli distributed random variables {Zi}i∈[1,4⁢n] with Pr⁡[Zi=1]=1/2, and we write Z=∑i∈[1,4⁢n]Zi.

By Chernoff’s bound, we have

Pr⁡[X≥4⁢n] ≤Pr⁡[Y≥4⁢n]
≤Pr⁡[Z≤n]
≤exp⁡(2⁢n⁢(et−1)−n⁢t)=exp⁡(φ⁢(t)),

with φ⁢(t) min at t=−ln⁡2, thus derives an upper bound by (2/e)n. ∎

Exercise 1.4.4 (Exercise 4.13 [MU17]).

Let {Xi}i∈[1,n] be independent Poisson trials such that Pr⁡[Xi=1]=p. Let X=∑i∈[1,n]Xi so that 𝔼[X]=p⁢n. Let

F⁢(x,p)=x⁢ln⁡xp+(1−x)⁢ln⁡1−x1−p.
  • •

    Show that, for 1≥x>p,

    Pr⁡[X≥x⁢n]≤e−n⁢F⁢(x,p).
  • •

    Show that, when 0<x,p<1, we have F⁢(x,p)−2⁢(x−p)2≥0.

  • •

    Argue that

    Pr⁡[X≥(p+ε)⁢n] ≤e−2⁢n⁢ε2,
    Pr⁡[X≤(p−ε)⁢n] ≤e−2⁢n⁢ε2,
    Pr⁡[|X−p⁢n|≥ε⁢n] ≤2⁢e−2⁢n⁢ε2.
Proof.

For Chernoff’s bound on Pr⁡[Xi≥x], we typically turn to 1+k⁢x≤ek⁢x for k>0, then

𝔼[exp⁡(t⁢Xi)]exp⁡(x⁢t) =p⋅et+1−pexp⁡(x⁢t)=1+p⋅(et−1)exp⁡(x⁢t)
≤exp⁡(p⋅(et−1)−x⁢t)=exp⁡(φ⁢(t)),

to derive an upper bound by choosing t. A different bound can be derived by avoiding the trick we often apply,

𝔼[exp⁡(t⁢Xi)]exp⁡(x⁢t)=p⋅exp⁡((1−x)⋅t)+(1−p)⋅exp⁡(−x⁢t)=φ⁢(t),

then we have

φ′⁢(t)=p⁢(1−x)⋅exp⁡((1−x)⋅t)−x⁢(1−p)⋅exp⁡(−x⁢t).

When t=ln⁡(1−p)+ln⁡x−ln⁡(1−x)−ln⁡p>0, φ⁢(t) min by

mint⁡φ⁢(t) =p⋅((1−p)⁢x(1−x)⁢p)1−x+(1−p)⋅((1−p)⁢x(1−x)⁢p)−x
=(p⋅(1−p)⁢x(1−x)⁢p+1−p)⋅((1−p)⁢x(1−x)⁢p)−x
=1−p1−x⋅((1−p)⁢x(1−x)⁢p)−x.

By taking ln both sides, we have

ln⁡mint⁡φ⁢(t) =ln⁡1−p1−x−x⁢ln⁡(1−p)⁢x(1−x)⁢p
=(1−x)⁢ln⁡1−p1−x+x⁢ln⁡px=−F⁢(x,p),

thus deriving a bound for Pr⁡[Xi≥x]≤exp⁡(−F⁢(x,p)). Finally, when bounding Pr⁡[X≥x⁢n],

Pr⁡[X≥x⁢n] ≤𝔼[exp⁡(t⁢X)]exp⁡(x⁢n⁢t)
=∏i∈[1,n]𝔼[exp⁡(t⁢Xi)]exp⁡(x⁢n⁢t)=(𝔼[exp⁡(t⁢Xi)]exp⁡(x⁢t))n
≤exp⁡(−n⁢F⁢(x,p)).

Taking partial derivative against x in F⁢(x,p), we have

∂∂x⁢F⁢(x,p)=ln⁡xp+x⋅px⋅1p−ln⁡1−x1−p+(1−x)⋅1−p1−x⋅−11−p=ln⁡xp−ln⁡1−x1−p,

and it is 0 when x=p, taking second order partial derivative against x, we have

∂2∂x2⁢F⁢(x,p)=1x−1−p1−x⋅−11−p=1x+11−x≥4,

and therefore F⁢(x,p)≥F⁢(p,p)+2⁢(x−p)2=2⁢(x−p)2 by Taylor expansion.

We can plug in the result F⁢(x,p)≥2⁢(x−p)2, and derive

Pr⁡[X≥(p+ε)⁢n]≤exp⁡(−n⁢F⁢(p+ε,p))≤exp⁡(−2⁢n⁢ε2).

When x<p and we upper bound Pr⁡[Xi≤x], t=ln⁡(1−p)+ln⁡x−ln⁡(1−x)−ln⁡p<0 gives ln⁡mint⁡φ⁢(t)=−F⁢(x,p), then Pr⁡[Xi≤x]≤exp⁡(−F⁢(x,p)). Thus,

Pr⁡[X≤(p−ε)⁢n]≤exp⁡(−n⁢F⁢(p−ε,p))≤exp⁡(−2⁢n⁢ε2).

Eventually, we derive bounds on both sides by

Pr⁡[|X−p⁢n|≥ε⁢n]≤2⁢exp⁡(−2⁢n⁢ε2).
Remark 1.4.5.

F⁢(x,p) is exactly the KL divergence [KL51] between Bernoulli distributions with parameters x and p.

∎

Exercise 1.4.6 (Exercise 4.14 [MU17]).

Let {Xi}i∈[1,n] be independent Poisson trials such that Pr⁡[Xi]=pi, and let {ai}i∈[1,n] be real numbers in [0,1]. Let X=∑i∈[1,n]ai⁢Xi and μ=𝔼[X]. Then the following Chernoff bound holds: for any δ>0,

Pr⁡[X≥(1+δ)⁢μ]≤(eδ(1+δ)1+δ)μ.

Prove a similar bound for the probability that X≤(1−δ)⁢μ for 0<δ<1.

Proof.

By Jensen’s inequality over concave functions,

𝔼[exp(taiXi)]≤𝔼[exp(tXi)]ai

for all t, as f⁢(x)=xai is concave if 0≤ai≤1.

By Chernoff’s upper tail and lower tail bound,

Pr⁡[Xi≥(1+δ)⁢pi] ≤𝔼[exp⁡(t⁢Xi)]exp⁡((1+δ)⁢pi⋅t)≤exp⁡(pi⋅(et−1))exp⁡((1+δ)⁢pi⋅t), min by t=ln⁡(1+δ)>0 by⁢(eδ(1+δ)1+δ)pi,
Pr⁡[Xi≤(1−δ)⁢pi] ≤𝔼[exp⁡(t⁢Xi)]exp⁡((1−δ)⁢pi⋅t)≤exp⁡(pi⋅(et−1))exp⁡((1−δ)⁢pi⋅t), min by t=ln⁡(1−δ)<0 by⁢(e−δ(1−δ)1−δ)pi.

By Chernoff’s bound and Jensen’s inequality, for upper tail bound, given t>0 and δ>0,

Pr⁡[X≥(1+δ)⁢μ] ≤𝔼[exp⁡(t⁢X)]exp⁡((1+δ)⁢μ⋅t)=∏i∈[1,n](𝔼[exp⁡(t⁢ai⁢Xi)]exp⁡((1+δ)⁢ai⁢pi⋅t))
≤∏i∈[1,n](𝔼[exp⁡(t⁢Xi)]exp⁡((1+δ)⁢pi⋅t))ai
≤∏i∈[1,n](exp⁡(pi⋅(et−1))exp⁡((1+δ)⁢pi⋅t))ai=(exp⁡(et−1)exp⁡((1+δ)⋅t))μ,

and right hand side is minimized by

mint>0(exp⁡(et−1)exp⁡((1+δ)⋅t))μ=(eδ(1+δ)1+δ)μ.

Symmetrically, for lower tail bound, given t<0 and 0<δ<1,

Pr⁡[X≤(1−δ)⁢μ] ≤𝔼[exp⁡(t⁢X)]exp⁡((1−δ)⁢μ⋅t)=∏i∈[1,n](𝔼[exp⁡(t⁢ai⁢Xi)]exp⁡((1−δ)⁢ai⁢pi⋅t))
≤∏i∈[1,n](𝔼[exp⁡(t⁢Xi)]exp⁡((1−δ)⁢pi⋅t))ai
≤∏i∈[1,n](exp⁡(pi⋅(et−1))exp⁡((1−δ)⁢pi⋅t))ai=(exp⁡(et−1)exp⁡((1−δ)⋅t))μ,

with right hand side minimized by

mint<0(exp⁡(et−1)exp⁡((1−δ)⋅t))μ=(e−δ(1−δ)1−δ)μ.

∎

Exercise 1.4.7 (Exercise 4.7 [MU17]).

Let X=∑i∈[1,n]Xi, where {Xi}i∈[1,n] are independent 0-1 random variables. Let μ=𝔼[X]. Choose any μL and μH such that μL≤μ≤μH. Then, for any δ>0,

Pr⁡[X≥(1+δ)⁢μH]≤(eδ(1+δ)1+δ)μH.

Similarly, for any 0<δ<1,

Pr⁡[X≤(1−δ)⁢μL]≤(e−δ(1−δ)1−δ)μL.
Proof.

The MGF of X can be relaxed in following manner

𝔼[exp⁡(t⁢X)]=∏i∈[1,n]𝔼[exp⁡(t⁢Xi)]≤∏i∈[1,n]exp⁡(pi⋅(et−1))=exp⁡(μ⋅(et−1)).

Given μL≤μ≤μH,

  • •

    When t>0, exp⁡(μ⋅(et−1))≤exp⁡(μH⋅(et−1)).

  • •

    When t<0, exp⁡(μ⋅(et−1))≤exp⁡(μL⋅(et−1)).

Then for upper tail with t>0 and δ>0,

Pr⁡[X≥(1+δ)⁢μH]≤exp⁡(μ⋅(et−1))exp⁡((1+δ)⁢μH⋅t)≤exp⁡(μH⋅(et−1))exp⁡((1+δ)⁢μH⋅t)=(exp⁡(et−1)exp⁡((1+δ)⋅t))μH,

the right hand side is minimized by

mint>0(exp⁡(et−1)exp⁡((1+δ)⋅t))μH=(eδ(1+δ)1+δ)μH.

For lower tail with t<0 and 0<δ<1,

Pr⁡[X≤(1−δ)⁢μL]≤exp⁡(μ⋅(et−1))exp⁡((1−δ)⁢μL⋅t)≤exp⁡(μL⋅(et−1))exp⁡((1−δ)⁢μL⋅t)=(exp⁡(et−1)exp⁡((1−δ)⋅t))μL,

the right hand side is minimized by

mint<0(exp⁡(et−1)exp⁡((1−δ)⋅t))μL=(e−δ(1−δ)1−δ)μL.

Moreover, for lower tail bound,

Pr⁡[X≤(1−δ)⁢μL]≤Pr⁡[X≤(1−δ)⁢μ]≤(e−δ(1−δ)1−δ)μ≤(e−δ(1−δ)1−δ)μL.

The first inequality holds from μL≤μ, the second one holds from Chernoff’s bound, and the third one holds from the fact that for 0<δ<1,

e−δ(1−δ)1−δ≤exp⁡(−δ22)≤1.

This chain of inequality comes in handy when we cannot compute the exact expectation, yet we can still derive a lower bound for the expectation, and give a looser version of tail bound. The sandwiched inequality chain can even be applied with previous weighted version of Chernoff bound with weights {ai}i∈[1,n] in (0,1). ∎

1.4.1 Hoeffding’s Bound

Hoeffding’s bound says that a sum of independent bounded random variables concentrates around the sum of their expectations. The probability of being far deacays exponentially fast in the squared deviation, namely exp⁡(−O⁢(ε2)).

Lemma 1.4.8 (Hoeffding’s Lemma [Hoe63]).

Let X be a random variable with X∈[a,b] and 𝔼[X]=0, then for any λ,

𝔼[exp⁡(λ⁢X)]≤exp⁡(λ2⁢(b−a)28).
Proof.

Since f⁢(x)=exp⁡(λ⁢x) is convex, then

f⁢(α⁢a+(1−α)⁢b)≤α⁢f⁢(a)+(1−α)⁢f⁢(b).

For x∈[a,b], let x=α⁢a+(1−α)⁢b, then α=(b−x)/(b−a).

Since 𝔼[X]=0, then by linearity of expectation,

𝔼[exp⁡(λ⁢X)]≤𝔼[b−Xb−a⁢exp⁡(λ⁢a)+X−ab−a⁢exp⁡(λ⁢b)]=bb−a⁢exp⁡(λ⁢a)−ab−a⁢exp⁡(λ⁢b).

Let θ=−a/(b−a)∈[0,1], and

φ⁢(t)=−θ⁢t+ln⁡(1−θ+θ⁢exp⁡(t)),

then when t=λ⁢(b−a),

exp⁡(φ⁢(λ⁢(b−a))) =exp⁡(−θ⁢λ⁢(b−a))⋅(1−θ+θ⁢exp⁡(λ⁢(b−a)))
=(1−θ)⋅exp⁡(−θ⁢λ⁢(b−a))+θ⋅exp⁡((1−θ)⁢λ⁢(b−a))
=(1−θ)⋅exp⁡(λ⁢a)+θ⋅exp⁡(λ⁢b)
=bb−a⁢exp⁡(λ⁢a)−ab−a⁢exp⁡(λ⁢b).

Since φ⁢(0)=0,

φ′⁢(t)=−θ+θ⁢exp⁡(t)1−θ+θ⁢exp⁡(t)

means φ′⁢(0)=0, and

φ′′⁢(t)=θ⁢exp⁡(t)1−θ+θ⁢exp⁡(t)−(θ⁢exp⁡(t)1−θ+θ⁢exp⁡(t))2≤14.

By the Taylor expansion and the Taylor remainder theorem in Lagrange form, there is t′ between 0 and t such that

φ⁢(t)=φ⁢(0)+φ′⁢(0)⋅t+φ′′⁢(t′)2⋅t2≤t28.

Therefore,

𝔼[exp⁡(λ⁢X)]≤exp⁡(φ⁢(λ⁢(b−a)))≤exp⁡(λ2⁢(b−a)28).

∎

Theorem 1.4.9 (Hoeffding’s Bound [Hoe63]).

Let X1,…,Xn be independent random variables such that for all 1≤i≤n, 𝔼[Xi]=μ and Xi∈[a,b]. Then

Pr⁡[|1n⁢∑i∈[1,n]Xi−μ|≥ε]≤2⁢exp⁡(−2⁢n⁢ε2(b−a)2).
Proof.

Let Zi=(Xi−μ)/n, then 𝔼[Zi]=0 and Zi∈[(a−μ)/n,(b−μ)/n] for i∈[1,n]. Let Z=∑i∈[1,n]Zi. For λ≥0,

Pr⁡[Z≥ε] =Pr⁡[exp⁡(λ⁢Z)≥exp⁡(λ⁢ε)]
≤1exp⁡(λ⁢ε)⋅𝔼[exp⁡(λ⁢Z)]=1exp⁡(λ⁢ε)⋅∏i∈[1,n]𝔼[exp⁡(λ⁢Zi)]
≤1exp⁡(λ⁢ε)⋅(exp⁡(λ2⁢(b−a)28⁢n2))n=exp⁡((b−a)28⁢n⋅λ2−ε⋅λ)
≤exp⁡(−2⁢n⁢ε2(b−a)2),

where the second inequality is from Markov inequality over MGF, the third equality is from X1,… being independent, the fourth inequality is from lemma 1.4.8, and the last inequality is by minimizing at λ=4⁢n⁢ε/(b−a)2.

The lower bound argument is similar, for λ<0,

Pr⁡[Z≤−ε] =Pr⁡[exp⁡(λ⁢Z)≥exp⁡(−λ⁢ε)]
≤1exp⁡(−λ⁢ε)⋅𝔼[exp⁡(λ⁢Z)]=exp⁡(λ⁢ε)⋅∏i∈[1,n]𝔼[exp⁡(λ⁢Zi)]
≤exp⁡((b−a)28⁢n⋅λ2+ε⋅λ)≤exp⁡(−2⁢n⁢ε2(b−a)2),

where the last inequality is by minimizing at λ=−4⁢n⁢ε/(b−a)2. ∎

Theorem 1.4.10 (Generalized Hoeffding’s Bound [Hoe63]).

Let X1,…,Xn be independent random variables such that for all 1≤i≤n, 𝔼[Xi]=μi and Xi∈[ai,bi], then

Pr⁡[|∑i∈[1,n]Xi−∑i∈[1,n]μi|≥ε]≤2⁢exp⁡(−2⁢ε2∑i∈[1,n](bi−ai)2).
Proof.

Let Zi=Xi−μi, then 𝔼[Zi]=0 and Zi∈[ai−μi,bi−μi] for i∈[1,n]. Let Z=∑i∈[1,n]Zi. For λ≥0,

Pr⁡[Z≥ε] =Pr⁡[exp⁡(λ⁢Z)≥exp⁡(λ⁢ε)]
≤1exp⁡(λ⁢ε)⋅𝔼[exp⁡(λ⁢Z)]=1exp⁡(λ⁢ε)⋅∏i∈[1,n]𝔼[exp⁡(λ⁢Zi)]
≤1exp⁡(λ⁢ε)⋅∏i∈[1,n]exp⁡(λ2⁢(bi−ai)28)=exp⁡(∑i∈[1,n](bi−ai)28⋅λ2−ε⋅λ)
≤exp⁡(−2⁢ε2∑i∈[1,n](bi−ai)2),

where the last inequality is by minimizing at 4⁢ε/∑i∈[1,n](bi−ai)2.

The lower bound argument is similar, for λ<0,

Pr⁡[Z≤−ε] =Pr⁡[exp⁡(λ⁢Z)≥exp⁡(−λ⁢ε)]
≤1exp⁡(−λ⁢ε)⋅𝔼[exp⁡(λ⁢Z)]=exp⁡(λ⁢ε)⋅∏i∈[1,n]𝔼[exp⁡(λ⁢Zi)]
≤exp⁡(λ⁢ε)⋅∏i∈[1,n]exp⁡(λ2⁢(bi−ai)28)≤exp⁡(−2⁢ε2∑i∈[1,n](bi−ai)2),

where the last inequality is by minimizing at −4⁢ε/∑i∈[1,n](bi−ai)2. ∎

1.4.2 Quicksort Runtime Analysis

Exercise 1.4.11 (Exercise 4.21 [MU17]).

We prove that the Randomized Quicksort algorithm sorts a set of n numbers in time O⁢(n⁢log⁡n) with high probability. Consider the following view of Randomized Quicksort. Every point in the algorithm where it decideds on a pivot element is called a node. Suppose the size of the set to be sorted at a particular node is s. The node is called good if the pivot element divides the set into two parts, each of size not exceeds 2⁢s/3. Otherwise the node is called bad. The nodes can be thought of as forming a tree in which the root node has the whole set to be sorted and its children have the two sets formed after the first pivot step and so on.

  • •

    Show that the number of good nodes in any path from the root to a leaf in this tree is not greater than c⁢log2⁡n, where c is some positive constant.

  • •

    Show that, w.h.p. (greater than 1−1/n2), the number of nodes in a given root to leaf path of the tree is not greater than c′⁢log2⁡n, where c′ is another constant.

  • •

    Show that, w.h.p. (greater than 1−1/n), the number of nodes in the longest root to leaf path is not greater than c′⁢log2⁡n.

  • •

    Show that the running time of Quicksort is O⁢(n⁢log⁡n) with probability at least 1−1/n.

Proof.

Suppose a given node with all the internal nodes being good nodes, then the longest such path gives the upper bound on the number of good nodes in any path of the tree. This can be proven by contradiction.

Suppose the path with the largest number of good nodes is not with all good nodes, looking like 𝐮=𝐯0⁢‖c‖⁢𝐯1, where c is a not good node. Then the suffix path c∥𝐯1 has to be the path with the largest number of good nodes among the subtree with root c; otherwise there exists a path 𝐬 in subtree with root c with more good nodes, then 𝐮 has less good nodes than 𝐯0∥𝐬, contradicting with 𝐮 being the path with the most good nodes among the tree.

We assume c∥𝐯1 being the path with the largest number of good nodes among the subtree rooted by c, then the largest number of good nodes under subtree rooted by c is |𝐯1|, so is the subtree rooted by v1,0. Since the subtree rooted by c as strictly more nodes than the subtree rooted by v1,0, then the largest number of good nodes of subtree rooted by c is lower bounded by |𝐯1|. Thus we complete the proof that the largest number of good nodes from a tree is from the longest path with all nodes being good nodes.

The longest path full of good nodes has length log32⁡n=log2⁡n⋅(log2⁡3−1)−1=c⁢log2⁡n, by partition on boundary of good node condition, and choose the big piece side.

One observation: a path has at most c⁢log2⁡n good nodes.

Let Y be the length of a path, and we want to upper bound Pr⁡[Y≥c′⁢log2⁡n]. By prior observation, the path can have at most c⁢log2⁡n good nodes, and we can turn the bound on path length into the bound on the number of good nodes. If the path survives ℓ levels, then among those first ℓ levels we have seen at most c⁢log2⁡n good nodes (since too many of good nodes stops a path from growing). Therefore Pr⁡[Y≥c′⁢log2⁡n]≤Pr⁡[X≤c⁢log2⁡n], where {Xi}i∈[1,c′⁢log2⁡n] are independent Bernoulli trials with parameter 1/3, and X=∑i∈[1,c′⁢log2⁡n]Xi.

We want c<c′/3 for lower tail bounding, and c′ sufficiently large. By Chernoff’s bound,

Pr⁡[Y≥c′⁢log2⁡n] ≤Pr⁡[X≤c⁢log2⁡n]
≤exp⁡(−12⋅μ⋅δ2)=n−Θ⁢(1),

where μ=13⁢c′⁢log2⁡n and δ=1−3⁢cc′.

For bounding the longest path is no longer than c′⁢log2⁡n, we union bound against all leaves (at most n), that the probability of existing a path longer than c′⁢log2⁡n is at most n⋅1/n2, hence the path is at most c′⁢log2⁡n long with probability 1−1/n2⋅n=1−1/n.

Each row of partition is dominated by runtime in O⁢(n), and the tree height is at most c′⁢log2⁡n with probability at least 1−1/n, hence that the runtime of the algorithm is O⁢(n⁢log⁡n) with probability greater than 1−1/n. ∎

1.4.3 Network Routing Problems

Exercise 1.4.12 (Exercise 4.22 [MU17]).

Consider the bit-fixing routing algorithm for routing a permutation on the n-cube. Suppose that n is even. Write each source node as as∥bs, with as and bs of length n/2. Let the destination of s’s packet be bs∥as. Show that this permutation causes the bit-fixing routing algorithm to take Ω⁢(N) steps.

Proof.

Since the permutation is as∥bs↦bs∥as, we can view the algorithm as 2 phases by fixing as and bs. WLOG we analyze the property from phase 1, as the 2 phases are symmetric.

We write address format as∥bs in as,0⁢‖as,1‖⁢bs,0∥bs,1, where as=as,0∥as,1 and bs=bs,0∥bs,1. During the bit fixing, the packet from as∥bs traverses to bs,0⁢‖as,1‖⁢bs,0∥bs,1. Eventually, when all as bits are fixed to bs, the packet arrives bs∥bs.

We notice that there are up to N such intermediate addresses bs∥bs, yet in the n-cube there are N=2n packets. Thus, nodes with addresses bs∥bs will be traversed by N packets in total.

Another interesting observation is: the packet routing in such permutation is not “load-balancing”.

View each bit being fixed as a packet traversing from one half-hypercube to another half-hypercube. By prior discussion, we noticed that the first phase bit fixing is “localized”, namely all N packets from ∗∥bs go to bs∥bs, and it takes no other packets. To be more generalized, all packets from ∗‖as,1‖⁢bs,0∥bs,1 go to bs,0⁢‖as,1‖⁢bs,0∥bs,1. The earlier the bit being fixed, the less packets traversing through half-hypercubes. With more bits fixed in the front (bs,0) and less bits flexible in the back (as,1), more packets aggregated from sub-hypercubes are forced to take 1 path to merge sub-hypercubes (Think of 8 packets over 3 bit hypercube, the 110−111 edge will take 4 packages). Therefore, right before nth bit being fixed, where n=|as|, there are N/2 packets aggregated for 1 bit fix to bs∥bs, that the edge will be used by N/2 packets, and thus the edge has an Ω⁢(N) delay.

We conclude that the deterministic bit-fixing algorithm takes Ω⁢(N) steps to route in this permutation. ∎

Exercise 1.4.13 (Exercise 4.23 [MU17]).

Consider the following modification to the bit-fixing routing algorithm for routing a permutation on the n-cube. Instead of fixing the bits in order from 1 to n, each packet chooses a random order (independent of other packet’s choices) and fixes the bits in that order. Show that there is a permutation for which this algorithm requires 2Ω⁢(n) steps with high probability.

Proof.

We use the previous permutation as∥bs↦bs∥as, and 2⁢N special cases, as∥0 and 0∥bs, are interesting. For these permutations, we would like to lower bound the number of packets that traverse 0∥0.

To reach 0∥0, the non-zero side should be fixed to zero first, before any bit on zero side being fliped to non-zero. WLOG we discuss the case that non-zero on the left side, the non-zero on right side follows from symmetry. We introduce 0-1 independent random variables {Xi,j} where i∈[1,n2] and j∈[1,(n/2i)], indicating if jth packet with i ones traverses 0∥0. The routing should fix i one bits first, thus Pr⁡[Xi,j=1]=(2⁢ii)−1.

Before moving to the lower bound the packet numbers, we need to derive the expectation of X=∑Xi,j,

𝔼[X]=∑i∈[1,n2]∑j∈[1,(n/2i)]𝔼[Xi,j]=∑i∈[1,n2](n/2i)(2⁢ii)≥∑i∈[1,n2]14i⋅(n/2i)=(54)n/2−1=μL,

the relaxation on (2⁢ii) follows

(2⁢ii)≤∑k∈[0,2⁢i](2⁢ik)=22⁢i=4i.

The previous lower tail bound inequality chain comes in handy, that

Pr⁡[X≤(1−δ)⋅μ]≤(e−δ(1−δ)1−δ)μ≤(e−δ(1−δ)1−δ)μL.

Since μL=2Ω⁢(n), we conclude that the algorithm on this permutation has runtime 2Ω⁢(n) time steps. ∎

Exercise 1.4.14 (Exercise 4.24 [MU17]).

Assume we use the randomized routing algorithm for n-cube network to route a total of up to p⁢2n packets, where each node is the source of no more than p packets, and each node is the destination of no more than p packets.

  • •

    Give a high probability bound on the runtime of the algorithm.

  • •

    Give a high probability bound on the maximum number of packets at any nodes at any step of the execution of the routing algorithm.

Proof.

The analysis follows from the runtime analysis for randomized bit-fixing routing [VB81], but the number of packets increase from 2n to p⋅2n. There are 2 phases, by first routing p⋅2n packets to random intermediate nodes, then route these nodes to their destinations. WLOG we analyze the first phase’s runtime, as they are symmetric.

Follow from the proof structure, we first bound the number of “active packets” over certain path, then upper bound the probability of the path with not many “active packets” yet runs slow, finally we derive a probability upper bound by union bounding all paths over the n-cube.

We recall the notion of “active packets”, that a packet is “active” at a node vi−1 on the path. If vi−1 and vi are adjacent on path, and diff by jth bit, in order for a packet to be “active”, its bits should be fixed before jth bit when it reaches vi−1. With that said, there are p⁢2j−1 packets sharing same suffix as vi−1 from jth bit, while the probability of sampling a random intermediate address with prefixed j−1 bits matching vi−1 is 2−(j−1). Thus, the expected number of “active packets” at a node on an edge is p.

Given a path of length m, the path is at most n as there are n bits to fix. Let X be the number of “active packets” on this path, then the expected number of “active packets” is upper bounded by 𝔼[X]=m⁢p≤n⁢p. By Chernoff’s bound, the probability of having too many “active packets” is upper bounded as follows

Pr⁡[X≥6⁢n⁢p≥6⁢m⁢p]≤2−6⁢n⁢p.

By conditional probability, we derive the following upper bound by sums of (conditional) probabilities

Pr⁡[A] =Pr⁡[A∣B]⋅Pr⁡[B]+Pr⁡[A∣¬B]⋅Pr⁡[¬B]
≤Pr⁡[B]+Pr⁡[A∣¬B].

We upper bound the probability of the runtime of the path being at least 30⁢n⁢p time steps by either “too many active packets” or “not many active packets but running slow” as follows

Pr⁡[T≥30⁢n⁢p] =Pr⁡[T≥30⁢n⁢p∣X≥6⁢n⁢p]⋅Pr⁡[X≥6⁢n⁢p]+Pr⁡[T≥30⁢n⁢p∣X<6⁢n⁢p]⋅Pr⁡[X<6⁢n⁢p]
≤Pr⁡[X≥6⁢n⁢p]+Pr⁡[T≥30⁢n⁢p∣X<6⁢n⁢p].

For “not many active packets but running slow” case, the runtime of the path is measuring how many packets stay on the path, turns into the time steps used to route all the packets. Only “active packets” can stay on the path, with probability 1/2 to branch into the next node on path. An “active packet”’s stay on the path can be modeled by the number of failures in a geometrically distributed random variable, and it leaves the path on a successful trial with probability 1/2. Upper bound on the sum of geometrically distributed random variables can be relaxed by upper bounding the sum of a serial of Bernoulli trials with parameter 1/2 here

Pr⁡[T≥30⁢n⁢p∣X<6⁢n⁢p]≤Pr⁡[∑i∈[1,36⁢n⁢p]Yi<6⁢n⁢p]≤exp⁡(−12⋅18⁢n⁢p⋅(23)2)=exp⁡(−4⁢n⁢p)≤2−3⁢n⁢p−1.

Therefore, the probability for the path’s runtime being at least 30⁢n⁢p is upper bounded by 2−3⁢n⁢p

Pr⁡[T≥30⁢n⁢p]≤2−6⁢n⁢p+2−3⁢n⁢p−1≤2−3⁢n⁢p.

Union bounding over 22⁢n paths, the probability of the first phase runtime exceeding 30⁢n⁢p is at most 22⁢n−3⁢n⁢p.

On the number of packets at any nodes at any time step, we can upper bound by the number of packets that will traverse the node. Let Xi be the number of packets arriving the node on ith bit, X=∑i∈[1,n]Xi be the number of packets using the node. Since 𝔼[Xi]=p by p⁢2i source packets and 2−i probability in random address prefix matching the node’s address’s prefix, by linearity of expectation, 𝔼[X]=n⁢p.

Once we have an expectation, by Chernoff’s bound we have Pr⁡[X≥6⁢n⁢p]≤2−6⁢n⁢p for this node at a certain step. By union bound over all nodes and time steps, the queue exceeding 6⁢n⁢p has probability at most 2−6⁢n⁢p⋅2n⋅O⁢(n⁢p). ∎

Exercise 1.4.15 (Exercise 4.26 [MU17]).

Given a network that is an undirected graph G, where nodes represent processors and the edges between the nodes represent wires. We are also given a set of N packets to route. For each packet we are given a source node, a destination node, and the exact route that the packet should take from source to destination. In each time step, at most one packet can traverse an edge. A packet can wait at any node during any time step, and we assume unbounded queue sizes at each node.

A schedule for a set of packets specifies the timing for the movement of packets along their respective routes. That is, it specifies which packet should move and which should wait at each time step. Our goal is to produce a schedule for the packets that tries to minimize the total time and the maximum queue size needed to route all the packets to their destination.

  • •

    The dilation d is the maximum distance traveled by any packet. The congestion c is the maximum number of packets that must traverses a single edge during the entire course of the routing. Argue that the time required for any schedule should be at least Ω⁢(c+d).

  • •

    Consider the following unconstrained schedule, where many packets may traverse an edge during a single time step. Assign each packet an integral delay x, chosen randomly, independently, and uniformly from the interval [1,⌈α⁢c/log⁡(N⁢d)⌉], where α is a constant. A packet waits in its source node for x time steps, then it moves on to its final destination through its specified route without ever stopping. Give an upper bound on the probability that more than O⁢(log⁡(N⁢d)) packets use a particular edge e at a particular time step t.

  • •

    Again using the unconstrained schedule, show that the probability that more than O⁢(log⁡(N⁢d)) packets pass through any edge at any time step is at most 1/(N⁢d) for a positive constant α.

  • •

    Use the unconstrained schedule to devise a simple randomized algorithm that, with high probability, produces a schedule of length O⁢(c+d⁢log⁡(N⁢d)) using queues of size O⁢(log⁡(N⁢d)) and following the constraint that at most one packet crosses an edge per time step.

Proof.

The length of the schedule is the runtime of the routing algorithm, and it is lower bounded by: the maximum distance a packet can traverse in the network, and the maximum congestion that delays the package traversal. Therefore, let T denotes the time steps of the routing algorithm, and T≥max⁡(c,d), and we conclude that T=Ω⁢(c+d).

Considering how many packets traverse edge e at the tth time step, we introduce {Xi}i∈[1,N] independent 0-1 random variables, where Xi=1 stands for ith packet traverses e at tth time step. Since there are at most c≤N packets traverse e, and if they traverse e at the tth time step, they had to be starting by one of the ⌈α⁢c/log⁡N⁢d⌉ delays, we here upper bound the expectation of X=∑i∈[1,N]Xi by

𝔼[X]≤c⋅log⁡(N⁢d)α⁢c=log⁡(N⁢d)α.

By 1.4.7, given μH≥μ,

Pr⁡[X≥(1+δ)⁢μH]≤(eδ(1+δ)1+δ)μH≤exp⁡(−μH⁢δ2/3),

we have X≥(1+δ)⁢log⁡(N⁢d)/α probability upper bounded by (N⁢d)−δ2/3⁢α.

Bounding the number of packets traverses any edge at any time step is equivalent to bounding the congestion of the schedule, which can be achieved by union bounding through all the time steps and all the edges. Each packet can go as far as d edges, and the packet arrives destination with at most d+⌈α⁢c/log⁡(N⁢d)⌉ time steps (by assumption that it does not stop once). If δ=1 and α<1/9, the upper bounded probability is

N⁢d⋅(d+⌈α⁢clog⁡N⁢d⌉)⋅(N⁢d)−δ23⁢α ≤N⁢d⋅N⁢d⋅(N⁢d)−δ23⁢α
≤(N⁢d)2⋅(N⁢d)−3=(N⁢d)−1.

If the tuned algorithm has schedule of length O⁢(d⁢log⁡(N⁢d)+c) with queue size O⁢(log⁡(N⁢d)), try scale the schedule by 2⁢log⁡(N⁢d)/α. By previous result, with the assumption that multiple packets crossing an edge at a time with no stop, the probability of more than 2⁢log⁡(N⁢d)/α packets passing through any edge at any time step is at most (N⁢d)−1. In the prior model, each time step the edge let packets crossing in a batch, and the batch is at most 2⁢log⁡(N⁢d)/α.

Now removing the assumption of multiple packets crossing an edge at a time, by scaling 2⁢log⁡(N⁢d)/α to the schedule and queue of size O⁢(log⁡(N⁢d)), given an edge allowing only 1 packet at a time, the batched moving can be simulated with the devised algorithm. ∎

Remark 1.4.16.

The intuition is: we first let everyone run non-stop with random starts, count how bad the pileups get, then spread those pileups thin by stretching time proportionally, and leading to an average case non stop routing. This is the Leighton-Maggs-Rao trick [LMR94].