A basic probability problem on conditional expectation A coin having probability $p$ of coming up heads is successively flipped until two of the most recent flips are heads. Let $N$ denote the number of flips. How to find $E[N]$. 
 A: Assume that $p\ne 0$. At any time during the tossing, we are in state $A$ if we have not just tossed a head. We are in state $B$ if we have just tossed a head, and we have not yet reached our goal. 
Let $a$ be the required expectation. Note that $a$ is also the expected number of additional tosses given that we are in state $A$. Let $b$ be the expected number of additional tosses given that we are in state $B$. We assume that $a$ and $b$ are finite. This is not difficult to prove, but we leave the sketch of a proof to a remark at the end.
If we are in state $A$, then with probability $p$ we enter state $B$, at the cost of $1$ toss, and with probability $1-p$ we stay in state $A$, again at the cost of $1$ toss. Thus
$$a=p(b+1) +(1-p)(a+1)=1+pb+(1-p)a.$$
A similar argument shows that 
$$b=p(1)+(1-p)(a+1)=1+(1-p)a.$$
Solve the above system of linear equations. We get $a=\frac{1+p}{p^2}$. 
Remark: To show that $a$ is finite, note that the probability of head at tosses $2k-1$ and $2k$ is $p^2$. So the probability that the number of tosses used is $2n$ is $\le (1-p^2)^n$. It follows that $a\le \sum_{1}^\infty 2n(1-p^2)^n$. By the Ratio Test, since $1-p^2\lt 1$, the series converges, so $a$ is finite.
One could calculate $a$ by summing appropriate series. However, the conditional expectation argument of the answer is simpler. 
