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.
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.$