1.2 Discrete Random Variable and Expectation

Exercise 1.2.1 (Exercise 2.2 [MU17]).

A monkey types on a 26-letter keyboard that has lowercase letters only. Each letter is chosen independently and uniformly at random from the alphabet. If the monkey types 1,000,000 letters, what is the expected number of times the sequence “proof” appears?

Proof.

This is exactly a brain teaser in linearity of expectation.

Say Xi are 0-1 random variables indicating if the sequence “proof” appears at ith alphabet. Then X=∑Xi is the random variable for the number of appearances of the sequence “proof”.

By linearity of expectation,

𝔼[X]=𝔼[∑i∈[1,999996]Xi]=∑i∈[1,999996]𝔼[Xi]=999996×(126)5.

∎

Exercise 1.2.2 (Exercise 2.12 [MU17]).

We draw cards uniformly at random with replacement from a deck of n cards. What is the expected number of cards we must draw until we have seen all n cards in the deck? If we draw 2⁢n cards, what is the expected number of cards in the deck that are not chosen at all? Chosen exactly once?

Proof.

The problem is a combination of “coupon collection” problem and “indicator” problem.

First one is the “coupon collection” problem, then let Xi be the number of draws to draw ith different card, which is a geometrically distributed random variable with parameter n−i+1n, and X=∑Xi be the total number of draws to draw all n different cards. 𝔼[X]=n⁢ln⁡n+Θ⁢(n).

Later, we introduce 0-1 random variables {Yi}i∈[1,n] indicating if the ith cards is not drawn once in the 2⁢n draws, then Pr⁡[Yi=1]=(n−1n)2⁢n. Let Y=∑Yi for the number of cards not drawn at all in 2⁢n draws, then

𝔼[Y]=𝔼[∑i∈[1,n]Yi]=∑i∈[1,n]𝔼[Yi]=n⋅(n−1n)2⁢n.

We also introduce 0-1 random variables {Zi}i∈[1,n] indicating if the ith card is drawn only once in the 2⁢n draws, then Pr⁡[Zi=1]=2⁢n⋅1n⋅(n−1n)2⁢n−1. Let Z=∑Zi for the number of cards drawn only once in 2⁢n draws, then

𝔼[Z]=𝔼[∑i∈[1,n]Zi]=∑i∈[1,n]𝔼[Zi]=2⁢n⋅(n−1n)2⁢n−1.

∎

Exercise 1.2.3 (Exercise 2.16 [MU17]).

Suppose we flip a coin n times to obtain a sequence of flips {Xi}i∈[1,n]. A streak of flips is a consecutive subsequence of flips that are all the same.

  • •

    Let n be a power of 2. Show that the expected number of streaks of length log2⁡n+1 is 1−o⁢(1).

  • •

    Show that, for sufficiently large n, the probability that there is no streak of length at least ⌊log2⁡n−2⁢log2⁡log2⁡n⌋ is less than 1/n.

Proof.

We first consider the expected number of streaks of length at least log2⁡n+1. This is solved by the linearity of expectation, by introducing {Xi}i∈[1,k] 0-1 random variables, where k=n−log2⁡n, indicating the ith flip starts a streak of length at least log2⁡n+1. The probability for Xi=1 can be upper bounded as follows

Pr⁡[Xi=1]=2⋅12log2⁡n+1=1n,

as streak on either face works. Therefore, number of streaks is X=∑i∈[1,k]Xi, and the expectation is

𝔼[X] =𝔼[∑i∈[1,k]Xi]=∑i∈[1,k]𝔼[Xi]
=(n−log2⁡n)⁢𝔼[Xi]
=n−log2⁡nn=1−o⁢(1).

We now show that the probability of no streaks of length at least ℓ=⌊log2⁡n−2⁢log2⁡log2⁡n⌋ is less than 1/n. We consider n/ℓ segments of ℓ length flips, and thus introduce n/ℓ independent 0-1 random variables indicating if the ith segment starts a streak of length at least ℓ. Therefore Pr⁡[Yi=1]=2/2ℓ.

Though n/ℓ segments is less than the total number of potential segments among n flips, it suffices for giving a sufficiently low probability. We now bound the probability of all n/ℓ segments has no streaks of length ℓ by

Pr⁡[⋂i∈[1,n/ℓ]Yi=0]=(1−22ℓ)n/ℓ=(1−12ℓ−1)2ℓ−1⋅n/(ℓ⋅2ℓ−1)≤(1e)n/(ℓ⋅2ℓ−1).

Let η=n/(ℓ⋅2ℓ−1). By ⌊x⌋≤x for any x, we lower bound η by

η =nℓ⋅2ℓ−1=2⁢n⌊log2⁡n−2⁢log2⁡log2⁡n⌋⋅12⌊log2⁡n−2⁢log2⁡log2⁡n⌋
≥2⁢nlog2⁡n−2⁢log2⁡log2⁡n⋅log22⁡nn=2⁢log22⁡nlog2⁡n−2⁢log2⁡log2⁡n
≥2⁢log2⁡n.

Therefore, exp⁡(−η) is at most 1/n, and thus completes the proof. ∎

Exercise 1.2.4 (Exercise 2.20 [MU17]).

A permutation on the numbers [1,n] can be represented as a function π:[1,n]↦[1,n]. A fixed point of a permutation π is a value for which π⁢(x)=x. Find the expected number of fixed points for a permutation chosen uniformly at random for all permutations.

Proof.

This is another indicator counting problem.

We introduce n 0-1 random variables {Xi}i∈[1,n] indicating if ith value is a fixed point for the permutation. Then Pr⁡[Xi=1]=1/n, and thus the expectation of X=∑Xi, which is the number of fixed points in π, is

𝔼[X]=𝔼[∑i∈[1,n]Xi]=∑i∈[1,n]𝔼[Xi]=1.

∎

Theorem 1.2.5 (Jensen’s Inequality).

If f is a convex function, then

𝔼[f⁢(X)]≥f⁢(𝔼[X]).

If f is concave, then

𝔼[f⁢(X)]≤f⁢(𝔼[X]).
Definition 1.2.6.

The expression 𝔼[Y∣X] is a random variable f⁢(X) that takes on value 𝔼[Y∣X=x] when X=x.

Lemma 1.2.7.
𝔼[Y]=𝔼[𝔼[Y∣X]].