Two players A and B play a game in which they alternately flips a coin. Player A starts the game. If a player gets T and another player got H before, he/she is the winner. What is the expected no. of flips for A to win ?
Ex:-
Game-1: HT --> B wins
Game-2: HHT --> A wins
We expect four coin flips. That's because we first expect two flips to get the first heads, and then we expect two flips to get the first tails.
More detailed: as a player is about to throw, the game is in one of two states: either there hasn't been any heads yet, or there has been at least one head (and since the game isn't over, the last throw must've been a head). Let's call the expected number of throws left until the game is over if we're in the first state $E_1$, and the expected number of throws left if we're in the second state $E_2$.
First we calculate $E_2$. If a player is about to throw, and the last throw was a heads, then there's a probability of $0.5$ of the game ending in one more throw, and a probability of $0.5$ of the game continuing to the next player still in the same state, which means that after that we expect another $E_2$ throws. This implies $$ E_2=0.5\cdot1+0.5(1+E_2)\\ E_2=2 $$ Now we get to $E_1$. If a player is about to throw, and there hasn't been any heads yet, then there is a probability of $0.5$ that the player throws heads, and the game continues in state two, which means that we expect another $E_2=2$ throws, and there is a probability of $0.5$ of the player throwing tails, which means that the game continues in the first state, and we expect another $E_1$ throws. This gives $$ E_1=0.5(1+E_2)+0.5(1+E_1)\\ E_1=4 $$ which is our answer.