返回题库

连续 N 次正面

Consecutive Heads

专题
Probability / 概率
难度
L4

题目详情

抛一枚公平硬币,问得到连续 NN 次正面(HH...H,共 NN 个 H)所需抛掷次数的期望是多少?记为 ENE_N

提示:尝试建立递推关系。

What is the expected number of coin tosses required to get NN consecutive heads?

Denote the term by ENE_N

Hint

Try to find a recurrence relation between ENE_{N} and EN1E_{N-1}.

解析

递推可得

EN=2EN1+2,E1=2.E_N = 2E_{N-1}+2,\quad E_1=2.

解得

EN=2N+12.E_N = 2^{N+1}-2.

Original Explanation

Recurrence form: EN=2EN1+2E_N = 2E_{N-1} + 2; Closed form: EN=2N+12E_N = 2^{N+1}-2

Solution

Method 1

We can simply reuse the method from problem "Innocent Monkey" (the law of total probability)

Define let XNX_N = number of tosses to get NN consecutive heads

ENE_N = expected number of coin tosses we require from now on, to get NN consecutive heads.

Note that if we already have N1N-1 Heads, then with probability (1/2), we can get NN consecutive heads, and with probability (1/2), we get a tail, and the state is reset.

EN=12(E(N1)+1)+12(EN1+1+EN)E_N = \frac{1}{2}( E_{(N-1)} + 1) + \frac{1}{2}(E_{N-1} + 1 + E_N)

the extra 1 is because we just used a toss

EN=2EN1+2E_N = 2E_{N-1} + 2

This is a recurrence relation and a good enough solution. But we can solve this into its closed form too.

The right way to solve this is by using generating functions or characteristic equations. But we will use a more intuitive approach.

We can tell it is an exponential function, involving powers of 22 because the NNth term is about 2 times N1N-1th term. Suppose EN=C12N+C2E_N = C_1 \cdot 2^{N} + C_2

Assume that E0=0E_0 = 0 (no tosses needed)     0=C1+C2\implies 0 = C_1 + C_2

And E1=2E_1 = 2 (refer to method 2, step 1)     2=C12+C2\implies 2 = C_1\cdot 2 + C_2

Simplify to get C1=2,C2=2C_1 =2, C_2 = -2

This simplifies to EN=2(N+1)2E_N = 2^{(N+1)}-2


Method 2

This approach is more rigorous and algebraic.

Let us solve a simpler question first.

Step 1: What's the expected number of coin tosses to get N=1N=1 heads?

There are two possibilities:

  1. We get a head in the first toss itself. This happens with probability 1/21/2.
  2. We get a tail in the first toss, and then we start a new game, where number of chance is 1 more than the expected value.

E1=121+12(1+E1)E_1 = \dfrac{1}{2} \cdot 1 + \dfrac{1}{2} \cdot (1 + E_1)

Simplify to get E1=2E_1 = 2

Step 2: What's the expected number of coin tosses to get N=2N=2 consecutive heads?

There are three possibilities:

  1. We can get two heads in the first two tosses itself. This happens with probability 1/41/4, and takes 2 tosses.
  2. We can get a tail in the first toss, and then we start a new game, where number of attempts is 1 more than the expected value.
  3. We can get a heads in the first toss, and then tails in the second. Then we start a new game, where number of attempts is 2 more than the expected value.

E2=142+12(1+E2)+14(2+E2)E_2 = \dfrac{1}{4} \cdot 2 + \dfrac{1}{2} \cdot (1 + E_2) + \dfrac{1}{4} \cdot (2 + E_2)

Simplify to get E2=6E_2 = 6

Step 3: What's the expected number of coin tosses to get NN consecutive heads?

There are N+1N+1 possibilities.

  1. We can get NN heads in the first NN tosses itself. This happens with probability 1/2N1/2^N, and takes NN tosses.
  2. We can get a tail in the first toss, and then we start a new game, where number of attempts is 1 more than the expected value.
  3. We can get a heads in the first toss, and then tails in second. Then we start a new game, where number of attempts is 2 more than the expected value.
  4. \vdots
  5. We can get N1N-1 heads in the first N1N-1 tosses, and then a tail in the NthN^{th} toss. Then we start a new game, where number of attempts is NN more than the expected value.

EN=12NN+12(1+EN)+122(2+EN)++12N(N+EN)E_N = \dfrac{1}{2^N} \cdot N + \dfrac{1}{2} \cdot (1 + E_N) + \dfrac{1}{2^2} \cdot (2 + E_N) + \ldots + \dfrac{1}{2^{N}} \cdot (N + E_N)

This looks quite complex, but be assured that this can be simplified. I did not spend time on solving this.

Simplify to get EN=2N+12E_N = 2^{N+1}-2


Method 3 (for N=1N=1 only)

We can use linearity of expectation for N=1N=1

Let XX be the number of tosses required to get 1 head.

Define indicator variable, Xi=1X_i = 1 if no Heads appeared before the iith step and 00 otherwise. Once we get a "heads", we stop tossing, so all the later Xi=0X_i=0.

Note that X=i=1XiX = \sum_{i=1}^{\infty} X_i

E[X]=E[i=1Xi]=i=1E[Xi]E[X] = E[\sum_{i=1}^{\infty} X_i] = \sum_{i=1}^{\infty} E[X_i] (using linearity of expectation)

E[X1]=112+112=1E[X_1] = 1 \cdot \dfrac{1}{2} + 1 \cdot \dfrac{1}{2} = 1 (if heads, then also count 1, if tails, then also count 1)

E[X2]=P(First toss was Tails)1E[X_2] = P(\text{First toss was Tails}) \cdot 1

E[X3]=P(First two toss were Tails)1=14E[X_3] = P(\text{First two toss were Tails}) \cdot 1 = \dfrac{1}{4}

\vdots

E[X]=i=1E[Xi]=1+12+14+=2E[X] = \sum_{i=1}^{\infty} E[X_i] = 1 + \dfrac{1}{2} + \dfrac{1}{4} + \ldots = 2

Okay, same answer as before.

Unfortunately, I'm unable to extend this solution to N=2N=2 and further because of the presence of the state.


Method 4 (for N=1N=1 only)

This method uses the basic definition of expected value.

E[X]=P(X=1)1+P(X=2)2+E[X] = P(X=1) \cdot 1 + P(X=2) \cdot 2 + \ldots

P(X=1)=1/2P(X=1) = 1/2 (because we can get a head in the first toss itself)

P(X=2)=1/4P(X=2) = 1/4 (first tails, and second hands)

\vdots

E[X]=121+1222+1233E[X] = \dfrac{1}{2} \cdot 1 + \dfrac{1}{2^2} \cdot 2 + \dfrac{1}{2^3} \cdot{3}

This is an Arithmetic Geometric Progression of type a,(a+d)r,(a+2d)r2,,[a+(n1)d]rn1a, (a+d)r, (a+2d)r^2, \ldots, [a + (n-1)d] r^{n-1} with a=0,d=1,r=1/2a=0, d=1, r=1/2

The sum of infinite such terms is S=a1r+dr(1r)2=1/21/4=2S = \dfrac{a}{1-r} + \dfrac{dr}{(1-r)^2} = \dfrac{1/2}{1/4} = 2