Encoding two equal outcomes as 1 and two different outcomes as 0, this is the time until 11111 appears in a random equidistributed 0-1 sequence. Can you solve this version of your problem?
–
DidDec 31 '11 at 12:42

Yes, now I can solve the problem. Thank you for pointing out the connection.
–
user12290Jan 2 '12 at 7:24

2 Answers
2

As Didier points out in his comment, the problem is equivalent to the problem of finding the expected number of flips, $X$, of a fair coin that are made until 5 heads appear in a row.

We condition on whether or not a tail appears in the first five flips.

For $1\le i\le5$,
let $T_i$ be the event that the first tail occurs on flip $i$ and let $T_6$ be the event that the first five flips are all heads.

We have $$\Bbb E(X\mid T_i)=i+\Bbb E(X),\quad 1\le i\le 5$$ (if the first tail occurs on flip 3, for example, then it's as if we are "restarting": the expected number of flips to obtain 5 heads in a row would be 3 plus the original expected number of flips).

Inspired by Mike Spivey's excellent answer, I'll add that the above can be generalized to the case where $X$ is the number of flips to be made until $n$ heads in a row are obtained, where the probability that the coin lands heads on one flip is $p$.

Here, for $1\le i\le n$, let $T_i$ be the event that the first tail occurs on flip $i$ and let $T_{n+1}$ be the event that the first $n$ flips are all heads.

Thank you very much for such detail answer. Just for information, one can use the idea of of Li (Page 428, Grinstead and Snell's Introduction to Probability) to solve these kind of problem.
–
user12290Jan 2 '12 at 7:20

Here's a different approach that simultaneously generalizes the solution.

As Didier and David have pointed out, the problem is equivalent to finding the expected number of flips required for a fair coin to achieve five consecutive heads for the first time. Let $X_n$ denote the toss on which a fair coin achieves $n$ consecutive heads for the first time. The analysis is just as easy if the coin isn't fair, though, so let's suppose that the coin has probability $p$ of being heads.

Suppose the coin has just achieved $n-1$ consecutive heads for the first time. Then, with probability $p$, the coin achieves $n$ consecutive heads for the first time on the next flip, and with probability $1-p$, the process restarts after the next flip. Mathematically, this is saying that $$\begin{align}E[X_n|X_{n-1}] &= p (X_{n-1}+1) + (1-p)(X_{n-1} + 1+ E[X_n])\\ &= X_{n-1} +1+ (1-p)E[X_n].\end{align}$$
Applying the law of total expectation, we have $$\begin{align} E[X_n] &= E[X_{n-1}] +1 + (1-p)E[X_n] \\ \Rightarrow E[X_n] &= \frac{E[X_{n-1}] +1}{p}.\end{align}$$
Now we have a nice recurrence for $E[X_n]$. Since $E[X_0] = 0$, unrolling this recurrence shows that
$$\begin{align}E[X_1] &= \frac{1}{p}, \\ E[X_2] &= \frac{1 + p}{p^2}, \\ E[X_3] &= \frac{1 + p+p^2}{p^3},\end{align}$$ and in general
$$E[X_n] = \frac{1+p+p^2+\cdots + p^{n-1}}{p^n}.$$
Using the formula for the partial sum of a geometric series, this expression simplifies to
$$\begin{align}E[X_n] &= \frac{1-p^n}{(1-p)p^n} \\ &= \frac{p^{-n}-1}{1-p}.\end{align}$$
In the case of a fair coin we have $p = 1/2$, and so $$E[X_n] = 2^{n+1}-2.$$
Thus the answer to the OP's question is $E[X_5] = 2^6-2 = 62,$ as David Mitra has already shown.

This approach also handles the generalization of the OP's question in which the two coins being tossed do not necessarily have the same probability of being heads. Suppose one has probability $p_1$ of being heads, the other has probability $p_2$ of being heads, and we toss them until the last $n$ flips are the same. For a single flip, they are the same if they both come up heads, with probability $p_1 p_2$, or both tails, with probability $(1-p_1)(1-p_2)$. Thus the probability that they are the same on a single flip is $1 - p_1 - p_2 + 2p_1p_2$. Tossing these two coins until the last $n$ flips are the same is the same problem as tossing a single coin with heads probability $1 - p_1 - p_2 + 2p_1p_2$ until we see $n$ consecutive heads, and so the formula above for $E[X_n]$ tells us that the expected number of tosses of the two coins until the last $n$ flips are the same is $$E[X_n] = \frac{(1-p_1 - p_2+ 2p_1p_2)^{-n}-1}{p_1 + p_2 - 2p_1p_2}.$$