Monday, July 7, 2008

Birthday Problem

You have N people at a dinner party.  How likely is it that two guests have the same birthday?

The first insight is that the probability $A$ of having a birthday pair is one, less the probability $B$ of having $N$ totally unique birthdays. That is, $A=1-B$.  Let's work $B$, it makes for easy counting.

We're looking for a probability, which in this case is a ratio between two things.  The first thing we want to know is, how many ways are there for $N$ people to have birthdays (any birthdays at all)?  That's easy: $365^N$.  The other thing we want to know is, how many ways are there for N people to NOT share a birthday?  That is, how many ways can we have $N$ unique birthdays?  Well, for more than 365 people we must have at least one pair, but for less than this a little reflection reveals the answer to be $365 * 364 * 363 * 362 * ... * (365-N)$.  In other words, let one person have any birthday, the next can have almost any birthday, the next one less, etc... The ratio of these is the probability we're after.

$$ P(N) = \frac{365 * 364 * 363 * ... * (365-N)} {365^N} =  \frac{365!}{365^N (365-N)!} $$

Here's a plot of P(N) for up to 100 people.  You can see the probability of unique birthdays is very high for small numbers of people, but crosses the "even odds" plane at 23 people.