### $n=3$

For the first appearance of three of heads in $n$ tosses,

• the last one needs to be a heads,
• the total number of heads needs to be $3$ (in the limit the rare event of no heads will play no role),
• the first two heads could be in any of the first $n-1$ tosses.

Thus we get the expectation of the first occurrence of three heads:

$\displaystyle E_3(p)=\sum_{n=3}^{\infty}n\frac{(n-1)(n-2)}{2!}(1-p)^{n-3}p^3=\frac{3}{p}.$

To see that, introduce $\displaystyle f(x)=\sum_{n=3}^{\infty}n\frac{(n-1)(n-2)}{2!}x^{n-3}.$ Integrate three times from $0$ to $x$ to get $\displaystyle \sum_{n=3}x^n=\frac{x^3}{1-x}.$ Differentiate three times to find $\displaystyle f(x)=\frac{3}{(1-x)^4}.$ Then substitute $x=1-p$ and multiply by $\displaystyle \frac{p^3}{2!}$

### $n=4$

For the first appearance of four of heads in $n$ tosses,

• the last one needs to be a heads,
• the total number of heads needs to be $4$ (in the limit the rare event of no heads will play no role),
• the first three heads could be in any of the first $n-1$ tosses.

Thus we get the expectation of the first occurrence of four heads:

$\displaystyle E_4(p)=\sum_{n=4}^{\infty}n\frac{(n-1)(n-2)(n-3)}{3!}(1-p)^{n-4}p^4=\frac{4}{p}.$

Follow the steps described above but with four integrations followed by four differentiations.

### Markov Chain

It seems reasonable to conjecture that on average one will need to wait $\displaystyle \frac{N}{p}$ flips before getting $N$ heads the first time. I'll describe a process of obtaining this result for $N=5$ that will make the assertion obvious. The process is based on constructing the Markov chain that describe flipping a coin and counting the number of heads.

There are six nodes, corresponding to the number of heads from $0$ to $5.$ The one at the bottom corresponds to a zero count of heads. This is, say, state $1.$ We move from one state to the next with the probability of $p$ and stay in the same state with the probability of $1-p.$