



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
An analysis of the average number of coin flips required to obtain a specified number of consecutive heads using a Markov chain model. The document derives equations for the average number of flips to get one head, two heads in a row, and generally n heads in a row, assuming a fair coin with a probability of 0.5 for heads.
What you will learn
Typology: Lecture notes
1 / 6
This page cannot be seen from the preview
Don't miss anything!
How many coin flips on average does it take to get n consecutive heads?
The process of flipping n consecutive heads can be described by a Markov chain in which the states correspond to the number of consecutive heads in a row, as depicted below. In this language, the question becomes how many steps does it take on average to get from the state 0H to the state nH?
Assume the coin has probability p of coming up heads. Begin with the case depicted in fig. (a), and let A 1 be the average number of flips on average before getting the first head. If the first flip is heads (probability p), then the answer is 1; if, on the other hand, the first flip is tails (probability 1 − p), then one flip is wasted and there remain A 1 to go. These two observations give an equation for A 1 :
A 1 = (1 − p)(1 + A 1 ) + p · 1 , (a1)
with solution
A 1 =^1 p. (a2)
(This result should be familiar, since if the probability to remain in a state is 1 − p, then the average number of steps to leave the state is∗^ ∑∞ k=1 k(1 − p)k−^1 p = (1/p^2 )p = 1/p.) For p = 1/2, we find A 1 = 2, so on average two flips are required to get the first head if the coin is fair. Now consider A 2 , the average number of flips to get two heads in a row (fig. (b)). Again, if the first flip is “wasted” on a tails, there’s a term (1 − p)(1 + A 2 ) on the right side. But now if the first flip is heads, there are two possibilities for what happens next. If the next flip is tails, the first two flips are “wasted” and we’re back where we started.
∗ (^) See footnote 2 below.
But if the next flip is a head, then the goal is accomplished in two flips. This gives the equation A 2 = (1 − p)(1 + A 2 ) + p(1 − p)(2 + A 2 ) + p^2 · 2 , (b1)
with solution A 2 = 1 +^ p p^2
. (b2)
For p = 1/2, we find A 2 = 6, so on average six flips are required to get 2 heads in a row if the coin is fair. Similar reasoning for A 3 , the average number of flips to get three heads in a row (fig. (c)) gives
A 3 = (1 − p)(1 + A 3 ) + p(1 − p)(2 + A 3 ) + p^2 (1 − p)(3 + A 3 ) + p^3 · 3 , (c1)
with solution
A 3 = 1 +^ p^ +^ p
2 p^3.^ (c2)
For p = 1/2, we find A 3 = 14, so on average fourteen flips are required to get 3 heads in a row if the coin is fair. In general, the average number of flips to get n heads in a row (fig. (d)), An, satisfies
An = (1−p)(1+An)+p(1−p)(2+An)+p^2 (1−p)(3+An)+.. .+pn−^1 (1−p)(n+An)+pn^ ·n. (d1) Regrouping terms on the right hand side and using^1 1 + p + p^2 +... + pn−^1 = 1 −p
n 1 −p gives
An = An(1 − p)(1 + p + p^2 +... + pn−^1 ) + (1 − p)(1 + 2p + 3p^2 +... + npn−^1 ) + npn = An(1 − pn) + (1 − p + 2p − 2 p^2 + 3p^2 − 3 p^3 +... + npn−^1 − npn) + npn = An − pnAn + (1 + p + p^2 +... + pn−^1 ).
This results in
An = 1 +^ p^ +^ p
(^2) +... + pn− 1 pn^
= 1 −^ p
n pn(1 − p)
= p
−n (^) − 1 1 − p
. (d2)
For p = 1/2, we find An = 2n+1^ − 2 flips required to get n heads in a row if the coin is fair, and the number grows exponentially in n.
(^1) To prove this, let Sn = ∑n k=0−^1 pk (^) and note that 1 + pSn = Sn + pn.
Summing over k gives An =
k=0(An−^1 + 1)(k^ + 1)(1^ −^ pn)kpn. Using^2 1 + 2(1^ −^ p) + 3(1 − p)^2 +... = (^) p^12 , it follows that
An = (An− 1 + 1)pn
k=
(k + 1)(1 − pn)k^ = (An− 1 + 1)pn p^12 n
= (An− 1 + 1) p^1 n
reproducing the generating equation (f 2). (The 1/pn is now recognized as the same familiar 1 /p mentioned after eq. (a2).)
As usual, there’s more structure in these probability distributions than just the average number of steps. Let pn(M ) denote the probability of reaching n consecutive heads only after exactly M flips of a single coin, each flip with probability p of heads. Then the average satisfies An =
M=0 M pn(M^ ). For n = 1, the probability to reach the first head in M flips is the probability of M − 1 tails and one head, hence ∑ p 1 (M ) = pM^. The average number of flips until the first head is ∞ k=0(k^ + 1)(1^ −^ p)kp^ = 1/p. The probability distribution^ p^1 (M^ ) is shown for a fair coin (p = 1/2) in the first figure on the next page. Additional figures show the probability distributions for n = 2, 3 , 4 , 5 , 10. In general, the probability vanishes, pn(M ) = 0, for M < n since it’s impossible to have n consecutive heads with fewer than n total flips. The first non-zero probability is pn(M = n) = pn, corresponding to all heads for the first n flips. For the next n values of M , from M = n + 1 through M = 2n flips, the probability is constant, pn(M ) = pn+1, since it is fully characterized by just the last n + 1 flips (i.e., a tail followed by n heads, and anything can happen in the first M − (n + 1) flips). For larger values of M , pn(M ) becomes the probability of not having more than n − 1 consecutive heads in the first M − (n + 1) flips, then followed by a final tail and n heads in the last n+1 flips. For example, for M = 2n+ flips, that probability is just all the ways not to have n consecutive flips in the first n flips, then the tail and n heads, so pn(M = 2n + 1) = (1 − pn)pn+1.
The probabilities pn(M ) are thus related to the probability of having no more than n consecutive heads in M − (n + 1) flips, in turn equal to 1 minus the probability of having at least n consecutive heads in M − (n + 1) flips. In general, the probability of having at least n consecutive heads in N flips of a fair coin (or equivalently the probability of at least n consecutive successes in N Bernoulli trials) is difficult to write down in closed form. To provide some intution for how those numbers behave, consider the example of N = 100.
(^2) To prove this, let S = ∑∞ k=0 qk (^) = (^1) − (^1) q , and note that ∑∞ k=0 kqk− (^1) = (^) ∂q∂ S = (^) (1− (^1) q) 2.
0
1 2 3 4 5 6 7 8 9 10 11 12
n=
0
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
n=
0
5 10 15 20 25 30 35 40 45 50 55 60 65 70
n=
0
5 10 15 20 25 30 35 40 45 50 60 70 80 90 100 110 120 130 140 150
n=
0
10 20 30 40 50 60 70 80 90100 120 140 160 180 200 220 240 260 280
n=
0
0 1000 2000 3000 4000 5000 6000 7000 8000 9000 10000 11000
n=
Figures: The probabilities pn(M ) of first flipping n consecutive heads after exactly M flips of a fair (p = 1/2) coin, for n = 1, 2 , 3 , 4 , 5 , 10. M is plotted along the horizontal axis. The red line shows the value of the average number of rolls required, eq. (d2): An = 2n+1^ − 2 (resp., 2,6,14,30,2046). The regions indicated in black represent the first 50% of the probability for each of the graphs.