# Expected number of coin flips to get two heads in a row?

**Problem** : Find the expected number of times a coin must be flipped to get two heads consecutively?

**Solution** : The key is to observe that if we see a tail on the first flip, it basically ruins any streak and so we have to start over again. In other words, the first tails makes all the previous tosses “wasted” and that increases the conditional expected time by that many tosses.

Let the expected number of coin flips be . Now, there are three possible cases as listed below:

**If a tail appears on the first flip of coin**. If in the first flip, a tail occurs then it means that we have wasted one flip and we will have to do more flips to reach our goal. The probability of this event is 1/2 and the total number of flips now required will be**x+1**.**If a heads appears on the first flip of coin and a tails appears on the second flip**. In this case it means that we have wasted two flips and we will have to do more flips to reach our goal. Therefore the total number of flips now required will be**x+2**and the probability of this event is 1/4.- The last case is,
**if we get two consecutive heads on two consecutive flips of the coin**respectively. The probability of this event is 1/4 and the total number of flips required will be 2.

Framing the above three cases in the form of equations and adding we will get:

x = (1/2)(x+1) + (1/4)(x+2) + (1/4)2

x = 1/2 [ (1+x) + 1/2(2+x) + 1 ]

x = 1/2 [ 1 + x + 1 + x/2 + 1 ]

x / 4 = 3/2

x = 6

Therefore,** x = 6**.

Thus, the expected number of coin flips for getting two consecutive heads is 6.

## Recommended Posts:

- Probability of getting two consecutive heads after choosing a random coin among two different types of coins
- Puzzle | Can 2 persons be with same number of hairs on their heads?
- Expected Number of Trials until Success
- Make a fair coin from a biased coin
- Puzzle | Heads or Tails
- Probability of getting at least K heads in N tosses of Coins
- Coin Change | DP-7
- Frobenius coin problem
- Count number of trailing zeros in Binary representation of a number using Bitset
- Puzzle | Number of Sheets to be turned so that Prime Number has a Vowel on the other side
- Count number of triplets with product equal to given number with duplicates allowed
- Find minimum number to be divided to make a number a perfect square
- Number of times the largest perfect square number can be subtracted from N
- Given number of matches played, find number of teams in tournament
- Check if the binary representation of a number has equal number of 0s and 1s in blocks

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.