What is the expected number of flips of an unfair coin until you have 2 more heads than tails?

We only ever need to keep track of the difference between the number of heads, and the number of tails. Moreover, the time it takes to increase this difference by $2$ is twice the time it takes to increase this difference by $1$.

So let's call $x$ the time it takes to go from a difference of $k$ to a difference of $k+1$: for example, the time it takes from the start until you have flipped heads once more than tails.

After the very first coinflip, we're either done (with probability $p$), or we have made progress in the wrong direction and have a difference of $2$ to make up for (with probablity $1-p$). So we have $$x = 1 + (1-p) \cdot 2x$$ or $x = \frac1{2p-1}$.

The answer you want is $2x = \frac2{2p-1}$.


This corresponds to calculating the expectation of the first-passage time of an asymmetric one-dimensional random walk. I believe that even the asymmetric one-dimensional random walk satisfies the (strong) Markov property, so therefore we can assume that the random walk "starts over" at every step. (See p. 4)

I.e. if $T(1)$ is the random variable indicating the first time we have one more head than tail, then $T(2)$ is the sum of two independent copies of $T(1)$. So by linearity of expectation: $$\mathbb{E}[T(2)]=\mathbb{E}[T(1)]+\mathbb{E}[T(1)]=2\mathbb{E}[T(1)]. $$

Now, $\mathbb{E}[T(1)]$ is a lot easier to calculate. According to this document (p.3 & p.5), $$\mathbb{E}[T(1)] = \Phi'(1)\,, \quad \text{where} \quad \Phi(t) = \frac{1 - \sqrt{1-4p(1-p)t^2}}{2(1-p)t} $$ i.e. $$\mathbb{E}[T(1)] = \frac{1 }{2p-1} \quad (p > \frac{1}{2})\,.$$ (In the document, $N= T(1)$.)