5

A coin is tossed continuously. Let $T$ be the minimum time to observe the $\text{HTH}$ block the third time. For example if the first tosses produce $$\text{H, H, T, H, H, T, T, H, T, H, T, H, H, T,}\dots$$ then the first $\text{HTH}$ block is obtained at time $4$, the second at time $10$ and the third at time $12$. Note that there was an overlap at $T=10$. Find $\mathbb E [T]$.

The expectation is given by $$\sum_{k=7}^\infty \mathbb P(T=k)\cdot k$$ since $T$ has to be atleast $7$.

Now, $\mathbb P(T=7)=\frac 1{2^7}$, but calculating $\mathbb P(T=k)$ for $k\ge 8$ seems to be very difficult since there are a lot of cases to take into consideration. Is there any easy way out?


The analogous problem of finding expected time for first $\text{HTH}$ can be solved using the neat trick shown in this answer. But even this trick fails to the number of combinations in the present case.

Sayan Dutta
  • 10,345

2 Answers2

6

Let $T_i$ denote the wait time for the $i^\text{th}$ occurrence of $\mathrm{H\,T\,H}$. We want to find $E[T_3]$. Write this as $$ E[T_3]=E[T_1]+E[T_2-T_1]+E[T_3-T_2], $$ and observe that $T_2-T_1$ and $T_3-T_2$ are identically distributed to each other; they are both the average time between occurrences of $\newcommand{\H}{\mathrm H\,}\newcommand{\T}{\mathrm T\,}\H \T \H$. Since the probability that any particular triple of coins is $\H\T\H$ is $1/8$, the average wait time between instances of $\H\T\H$ must be $1/(1/8)=8$. We now know that $E[T_2-T_1]=E[T_3-T_2]=8$, but how to reason about $E[T_1]$? For this, we calculate the expected return time in a different way.

Suppose we are in a state where the last three coin tosses are $\H\T\H$. Let $X$ denote the number of tosses it takes to see $\H\T\H$ again from this state. Three things can happen.

  • If the first toss is $\H$, then we are effectively in the same situation as the start, as the only potentially useful part of previous $\H\T\H$ is the final $\H$. Therefore, the wait time here is distributed like $X+1$.

  • If the first two tosses are $\T \T$, then we are a situation where the past tosses are no longer helpful. This means the remaining time is distributed like $E[T_1]+2$.

  • If the first two tosses are $\T\H$, then we re-use the previous $\H$, the wait time is just $2$.

Putting this altogether implies $$ E[X]=\frac12\cdot (E[X]+1)+\frac14\cdot(E[T_1]+2)+\frac14\cdot 2, $$ Combined with $E[X]=8$, the above implies $E[T_1]=10$, and we conclude $E[T_3]=10+8+8=26$.

More generally, $E[T_k]=10+8(k-1)=8k+2$.

I learned this trick for computing $E[T_1]$ from Peter Winkler, in his solution to the average wait time for HHHHH.

Mike Earnest
  • 84,902
  • This is such a nice answer (+1)! – Sayan Dutta May 14 '25 at 05:23
  • 4
    There's something that makes me a little uncomfortable though - you claim that since the probability that any particular triple of coins is $\H\T\H$ is $1/8$, the average wait time between instances of $\H\T\H$ must be $1/(1/8)=8$. But isn't this only true when you do not have the overlap issue? – Sayan Dutta May 14 '25 at 05:34
  • 1
    @SayanDutta The expected wait time of $8$ is the expected wait time to see $HTH$ given that you've just seen an $H$-- so it takes the overlap into account. When you are starting off (or when you've just seen a $T$), the expected wait time to see $HTH$ is $10$ (since you need on average $2$ flips before you see your first head), which is where the $+2$ comes from in the final formula. – Julius May 14 '25 at 10:57
  • +1 So the expected time to see HHH (or TTT) for the $k$th time is $8k+3$, for HTH (or THT) is $8k+2$, and for HTT (or HHT or TTH or THH) is $8k$. – Henry May 14 '25 at 12:44
  • Thanks, got it! For what its worth, the code Module[{simulateOnce, trials = 10000, totalTime},\n simulateOnce[] := Module[{seq = {}, count = 0, t = 0},\n While[count < 3,\n AppendTo[seq, RandomChoice[{\"H\", \"T\"}]];\n t++;\n If[t >= 3 && seq[[-3 ;;]] == {\"H\", \"T\", \"H\"}, count++];\n ];\n t\n ];\n \n totalTime = Total[Table[simulateOnce[], {trials}]];\n N[totalTime / trials]\n] did spit out $25.96$! – Sayan Dutta May 14 '25 at 15:42
  • @Henry so expected time to see $\text{HHH}$ is $8+3=11$, but doesn't that contradict this answer? – Sayan Dutta May 14 '25 at 19:22
  • 1
    @SayanDutta My mistake: HHH (or TTT) should be $8n+6$ – Henry May 14 '25 at 19:59
1

Edit: Rewriting the post to give a more concrete explanation.

There is an idea in martingale theory to find the expectation of a stopping time by using a betting martingale with mean $0$ difference. Suppose we have a series of people coming in, each right before a coin flip, who bet $1$ dollar on the outcome of the flip. If they win, they end up with $1$ dollar, if they lose, they end up with $-1$ and stay that way forever. Next, if they win again, they double the bet, and continue until they have completely won (our condition has been met). To formalize this, let $Z_{k,n}$ be the winnings of better $k$ at time $n$. Note that $Z_{k,k} = 2-1$ if we get heads on flip $k$, and $Z_{k,k} = -1$ if we get tails on flip $k$. Then, for $i > j > k$, if $Z_{k,j} = -1$, $Z_{k,i} = -1$ as well, i.e. they stay broke and cant bet anymore. Also, if they win three times in a row (HTH) then they stop betting completely. Define $S_n = \sum_{k=1}^n Z_{k,n}$. Note that $\mathbb E[Z_{k,j + 1} \mid Z_{k,j}] = Z_{k,j}$, so $S_n$ is a martingale. Now let $T$ be the first time at which we have finished seeing $3$ HTH sequences. It is not hard to check that $T$ is a stopping time, which means by the optional stopping theorem $$0 =\mathbb E[S_0] = \mathbb E[S_T] = \mathbb E[8 + 8 + 8 + 2 - T] \iff \mathbb E[T] = 26$$ Note that we get $8 + 8 + 8 + 2$ since three betters will have made $8$, and the last flip will have made an extra $2$. And the $-T$ is by design since every $Z_{k,n}$ has a $-1$ attached to it (the first win is $2-1$, then $4-1$, then $8-1$), hence $S_T$ has a $-T$ as well as $8,8,8,2$ in winnings.

The benefit of this method is that it is very versatile. You can use this to easily find any other string of sequences, or the expected amount of time before an infinite number of monkeys type a word (You should replace the bet of $2$ with the bet of $26$), or any expected time really. Take, for instance, HHHHH like another commenter pointed out. We don’t need to do any more complicated math since $$\mathbb E[ 2^5 + 2^4 + 2^3 + 2^2 + 2 - T] = 0$$ using the same design as before.

Robertmg
  • 2,155