Suppose that we are given a fair coin and we toss the coin indefinitely. What is the average number of tosses so that two consecutive heads are obtained?
The solution is as follows:
Let $X$ be the random variable denoting the number of tosses required to obtain 2 consecutive heads.
Then we are asked to calculate $E(X) $.
Note that $$E(X)=P(T) (E(X) +1)+P(HT)(E(X)+2)+P(HH)(2).$$
Solving the equation leads to
$$E(X) =6.$$
My question is how to prove the equation above.
By the law of total expectation, the expected value for $X$, the count of tosses until we obtain two heads on consecutive rolls is.$$\mathsf E(X)=\mathsf P(\mathrm T)~\mathsf E(X\mid \mathrm T)+\mathsf P(\mathrm H\mathrm T)~\mathsf E(X\mid \mathrm H\mathrm T)+\mathsf P(\mathrm H\mathrm H)~\mathsf E(X\mid \mathrm H\mathrm H)$$
Where $\mathrm T$ is the event for obtaining a tail on the first roll, $\mathrm H\mathrm T$ is the event for obtaining head then tail on the first two rolls, and $\mathrm H\mathrm H$ is the even for obtaining head on both first two rolls. These are disjoint events that partition the sample space (ie: they are mutually exclusive and exhaustive events).
Now when we roll a tail on the first roll, we count that roll, then continue as though we have started the experiment over again. $$\mathsf E(X\mid\mathrm T)=1+\mathsf E(X)$$ Similarly, when we roll a head then a tail we count those rolls then continue as though we have started over.$$\mathsf E(X\mid\mathrm H\mathrm T)=2+\mathsf E(X)$$ However, when we roll two heads, then we are done.$$\mathsf E(X\mid\mathrm{HH})=2$$ Thus$$\mathsf E(X)=\mathsf P(\mathrm T)~(1+\mathsf E(X))+\mathsf P(\mathrm{HT})~(2+\mathsf E(X))+2~\mathsf P(\mathrm {HH})$$