Probability density function of flipping until heads and tails

344 Views Asked by At

Let's say that we are going to flip a coin, and want to flip until we have flipped both heads and tails. Let X = the total number of flips. How would we go about finding the probability density function of X?

My attempt to solve the problem is this: For one flip, we cannot have both heads and tails, only one or the other. Then, in order to keep flipping, we would need to continuously flip the same as our first flip. For 2 flips, we can either have HH or TT, and for 3 flips HHH or TTT.

So we know that:

$$P(X=1) = 0$$

$$P(X=2) = 0.5$$

To find $P(X=3)$ we can take the probability that we don't flip HHH or TTT, and subtract the chance that we flipped heads and tails in 2 flips, or $P(X=2)$.

Therefore, $$P(X=3) = (1 - 2*(0.5)^3) - 0.5 = 0.75 - 0.5 = 0.25 = (0.5)^2$$

To generalize, it looks as if $$P(X=n) = (0.5)^{n-1}$$

Is this line of thinking correct? It seems a little complex to me, so I think there must be a way to come to this answer with less steps, but I can't see it.

4

There are 4 best solutions below

0
On

This is correct and I don't really see a less complicated way of thinking about it. Maybe a slightly quicker way of putting it (though it is pretty much the exact same idea) is that once we flip one coin, we are trying to flip the other side, so $T-1$ is geometrically distributed with $p=1/2.$

0
On

You need to count the last flip as well. As you say, we have to have at least two flips so P= 0. To get X=2 we must have either "TH" or "HT". The probability of each is 1/4. P(2)= 1/4+ 1/4= 1/2. To get X= 3 we must have either "TTH" or "HHT". The probability of either is 1/8 so P(3)= 1/4. You can probably guess P(X) for higher values of X.

1
On

Clearly, $X \ge 2$ and is an integer. We will solve the general case where the coin has probability of heads $p$ for any single trial, and trials are independent. Then for a fair coin, $p = 1/2$.

Consider $\Pr[X > x]$ for $x = 1, 2, \ldots$; that is to say, we want to compute the probability of needing more than $x$ trials to get both heads and tails. Since this can only happen if all of the $x$ trials are heads, or all are tails, and these outcomes are mutually exclusive, $$\Pr[X > x] = p^x + (1-p)^x.$$ Consequently, $$\begin{align*} \Pr[X = x] &= \Pr[X > x-1] - \Pr[X > x] \\ &= p^{x-1} - p^x + (1-p)^{x-1} - (1-p)^x \\ &= p^{x-1}(1-p) + (1-p)^{x-1}(1 - (1-p)) \\ &= p^{x-1}(1-p) + (1-p)^{x-1}p \\ &= p(1-p)\left(p^{x-2} + (1-p)^{x-2}\right). \end{align*}$$ When $p = 1/2$, this reduces to $$\Pr[X = x] = \frac{1}{2^{x-1}}.$$

0
On

Is this line of thinking correct? It seems a little complex to me, so I think there must be a way to come to this answer with less steps, but I can't see it.

Yes, indeed -- that is well reasoned; you just need to generalise a bit earlier.

  • Now, $\{X=n\}$ is the event of obtaining any result, then $n-2$ consecutive results identical to that, followed by the first different result on the $n$eth toss.   So immediately we see that $\mathsf P(X=n)=(1/2)^{n-1}$ for an unbiased coin.