medium puzzles
medium | probability |
What is the expected number of coin tosses required to get consecutive heads?
Denote the term by
Try to find a recurrence relation between and .
Recurrence form: ; Closed form:
Method 1
We can simply reuse the method from problem "Innocent Monkey" (the law of total probability)
Define let = number of tosses to get consecutive heads
= expected number of coin tosses we require from now on, to get consecutive heads.
Note that if we already have Heads, then with probability (1/2), we can get consecutive heads, and with probability (1/2), we get a tail, and the state is reset.
the extra 1 is because we just used a toss
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 because the th term is about 2 times th term. Suppose
Assume that (no tosses needed)
And (refer to method 2, step 1)
Simplify to get
This simplifies to
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 heads?
There are two possibilities:
- We get a head in the first toss itself. This happens with probability .
- 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.
Simplify to get
Step 2: What's the expected number of coin tosses to get consecutive heads?
There are three possibilities:
- We can get two heads in the first two tosses itself. This happens with probability , and takes 2 tosses.
- 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.
- 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.
Simplify to get
Step 3: What's the expected number of coin tosses to get consecutive heads?
There are possibilities.
- We can get heads in the first tosses itself. This happens with probability , and takes tosses.
- 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.
- 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.
- We can get heads in the first tosses, and then a tail in the toss. Then we start a new game, where number of attempts is more than the expected value.
This looks quite complex, but be assured that this can be simplified. I did not spend time on solving this.
Simplify to get
Method 3 (for only)
We can use linearity of expectation for
Let be the number of tosses required to get 1 head.
Define indicator variable, if no Heads appeared before the th step and otherwise. Once we get a "heads", we stop tossing, so all the later .
Note that
(using linearity of expectation)
(if heads, then also count 1, if tails, then also count 1)
Okay, same answer as before.
Unfortunately, I'm unable to extend this solution to and further because of the presence of the state.
Method 4 (for only)
This method uses the basic definition of expected value.
(because we can get a head in the first toss itself)
(first tails, and second hands)
This is an Arithmetic Geometric Progression of type with
The sum of infinite such terms is