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.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Count of total Heads and Tails after N flips in a coin
- Expected Number of Trials to get N Consecutive Heads
- Probability of getting two consecutive heads after choosing a random coin among two different types of coins
- Probability of not getting two consecutive heads together in N tosses of coin
- Probability of getting K heads in N coin tosses
- Make a fair coin from a biased coin
- Puzzle | Can 2 persons be with same number of hairs on their heads?
- Expected Number of Trials until Success
- Expected number of moves to reach the end of a board | Dynamic programming
- Expected number of moves to reach the end of a board | Matrix Exponentiation
- Probability of getting at least K heads in N tosses of Coins
- Puzzle | Heads or Tails
- Probability of getting more heads than tails when N biased coins are tossed
- Minimum number of flips with rotation to make binary string alternating
- Coin Change | DP-7
- Frobenius coin problem
- Coin Change | BFS Approach
- Find the player who will win the Coin game
- Minimum moves taken to move coin of each cell to any one cell of Matrix
- Philaland Coin | TCS Mockvita 2020
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.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.