First time you toss the coin it'll be either a head or a tail. Let's go with an assumption it's a head, $ H $.
Now, let's denote $x$ as the number of tosses, which we need to find. Currently $x$ is already 1 as we have tossed already. The next toss will either get you a tail, $T$ or a head $H$. The probability is $\frac{1}{2}$.
Let me put this iterating $x$, after getting one head.
Outcomes |
$x$, the number of tosses |
$p(x)$ the probability |
T |
1 |
$\frac{1}{2}$ |
H, T |
2 |
$\frac{1}{4}$ |
H, H, T |
3 |
$\frac{1}{8}$ |
H, H, ...., T |
x |
$\frac{1}{2^x}$ |
We find that from this, $x$ is behaving as a geometric random variable. If you don't know what this is, read here.
So, $$E(x) = \sum_{x=1}^{\inf} x \cdot p(x)$$
$$\sum_{x=1}^{\inf} x \cdot p(x) = 1 \cdot \frac{1}{2} + 2 \cdot \frac{1}{4} + 3 \cdot \frac{1}{8} + \ldots $$
Dividing by $2$ and subtracting from the original we get,
$$\frac{1}{2} E(x) = \frac{1}{2} + \cdot \frac{1}{4} + \cdot \frac{1}{8} + \ldots $$
Infinite series summation is straightforward, when $r < 1$
$$ \frac{a}{1-r}$$
So we get, $$ 1 \cdot \frac{1}{2} + 2 \cdot \frac{1}{4} + 3 \cdot \frac{1}{8} + \ldots $$
$$= \frac{\frac{1}{2}}{1-\frac{1}{2}} $$
$$= 1$$
So, $E(x) = 2$
Finally adding the first toss which got us a Head we get, $3$, which is the average tosses needed for getting at least one head and one tail by tossing a fair coin, infinite times.
Pro-tip: It's a standard result, so remember it.