# What is the probability of exactly two out of n persons sharing a birthday?

The classical Birthday problem asks for the probability of at least two out of $n$ people sharing the same birthday or sometimes for the least amount $n$ of people required such that with a probability of 50% at least two of them share their birthday. But what about the question how probable it is that also no more than two people share their birthday?

• @AndréNicolas : I think you missed a factor : P("n-1 don't share a birthday") = Nb of cases where n-1 don't share a birthday / $365^{(n-1)}$. P = Nb of cases where n-1 don't share a birthday * ${n \choose 2} / 365^{n}$ = P("n-1 don't share a birthday") * ${n \choose 2}$ / 365 Am I right? – gvo Oct 11 '13 at 16:24
• Got something from an answer below? – Did Oct 14 '13 at 17:08
• @Did I somehow missed the answer notifications, thanks for the ping - I'll try and vote/accept them by tomorrow – Tobias Kienzler Oct 14 '13 at 18:30

$\mathbb{P}$(no more than two people share their birthday) = $\mathbb{P}$(noone shares their birthday with anyone else) + $\mathbb{P}$(noone shares their birthday with anyone else except one pair)

Now,

1. $\mathbb{P}$(noone shares their birthday with anyone else) = $\frac{365!}{(365 -n)!}*\frac{1}{365^n}$
2. $\mathbb{P}$(noone shares their birthday with anyone else except one pair) = $\frac{364!}{(364 - \overline{n-2})!}*\left({n \choose 2} 365\right)*\frac{1}{365^n}$.

I think the answer of André Nicolas given in the comment is better, however, here is what I did : Let's denote $Q(n)$ the probability that n people don't share a common birthday, and $P(n)$ that exactly two people share a common birthday. $Q(n)$ is known for every $n$, cf. the Wikipedia link you gave. $P(1)$ also known.

We have the following relationship :

$P(n+1) = P(n)*\frac{n}{365} + Q(n)*\frac{365-(n-1)}{365}$

$P(n+1) = P(n)*\frac{n}{365} + Q(n)*\frac{366-n}{365}$

You can then compute all the probability up to 366, after, $P(n) = 0$

We interpret the question as asking for the probability that precisely two people share a birthday.

Imagine lining up our $n\ge 3$ people, and writing down their birthdays. Under the usual not quite accurate assumptions, there are $365^n$ equally likely strings.

We now count the number of "favourables."

The two people who share a birthday can be chosen in $\binom{n}{2}$ ways. For each such choice, the common birthday can be chosen in $365$ ways. For each such choice, the remaining $n-2$ slots can be filled in $(364)(363)\cdots (364-(n-3))$ ways, for a total of $\binom{n}{2}(365)(364)(363)\cdots(364-(n-3))$.

You need ${{n}\choose{2}}$ ways of choosing 2 people times probability the number of ways only those two share birthday [$365!/(366-n)!$ if $n\le366$ and $0$ otherwise] divided by the total possible ways $365^n$. Sorry, I am ignoring February 29 to keep things simple.

Draw at random $n$ birth dates from a set of $N=365$ different dates, independently and uniformly. The event that exactly $2$ birth dates coincide happens when, for some $1\leqslant k\leqslant n-1$, $k$ different dates are chosen, then a date already drawn is drawn again, then $n-k-1$ new different dates are drawn. For each such $k$, the probability that this happpens is $$p_k=\frac{N-1}N\cdot\frac{N-2}N\cdot\cdots\frac{N-k+1}N\cdot\frac{k}N\cdot\frac{N-k}N\cdot\frac{N-k-1}N\cdots\frac{N-n+2}N.$$ The probability of the event that exactly $2$ birth dates coincide is $$\sum_{k=1}^{n-1}p_k=\frac{(N-1)!}{(N-n+1)!N^{n-1}}\cdot\sum_{k=1}^{n-1}k=\frac{n(n-1)}2\cdot\frac1{N^n}\cdot\frac{N!}{(N-n+1)!}$$