Coin Toss Sequence: HHH
How many times do you expect to toss a coin to get a sequence Heads Heads Heads (HHH)?
Answer
This is a markov chain problem. You solve it by recognising when you're in states you'd visited before, and solving a system of equations. Easiest way to solve it is to draw a tree diagram with possible outcomes. You can stop branching the three when you encounter a state you've visited before.
Looking at the image below, we start off with state $S_0$ - before tossing any coins, we have 0 of the required 3-letter sequence. If you toss T, you still don't have the first of the HHH sequence (since we need H to start), so we are back to $S_0$ and we don't branch the tree further in this direction. If you get H, you are in $S_1$ - you've obtained the first of the HHH sequence. If after that you get another H, you are at $S_2$ with first two of the target sequence HHH. If second flip was a T, you end up back at $S_0$ as we must restart the sequence after a T. We continue branching from $S_2$, as we haven't encountered this state before. If the next flip is H, we win; and otherwise we are back at the start (as after HHT we must restart the sequence). Now since this is a fair coin, each branch occurs with probability $\frac{1}{2}$.
Lastly, we set up the equations. Denote $E_i$ the expected number of flips needed to get HHH starting from state $S_i$. Then: $$E_0=1 + \frac{1}{2}\cdot E_0 + \frac{1}{2} \cdot E_1$$
, $$E_1 = 1 + \frac{1}{2}\cdot E_0 + \frac{1}{2}\cdot E_2$$ and $$E_2 = 1 + \frac{1}{2}\cdot 0 + \frac{1}{2}\cdot E_0$$.
Solving the system of three equations for $E_0$, we get $E_0=14$.