MathematicsGrade 8–13

Simulating the birthday problem

How likely is it that two people in a class share a birthday? From just 23 people on, it is more likely than not.

Loading simulation …

What is it about?

What is the probability that in a class of nn people at least two share a birthday? Many people guess only a few percent for 2525 people – in fact it is almost 57 %57\,\%.

Model: Each of the 365365 days is equally likely (no leap days, no twins), and the birthdays are independent.

Calculation via the complement (view “Calculation”): Instead of “at least two equal” we compute “all different”. The people arrive one by one: the first may have any day, the second must hit one of the 364364 free days, the third one of the remaining 363363 … By the path rule we multiply:

P(all different)=365365⋅364365⋅363365⋅…⋅365−n+1365,P(at least two equal)=1−P(all different).P(\text{all different}) = \frac{365}{365} \cdot \frac{364}{365} \cdot \frac{363}{365} \cdot \ldots \cdot \frac{365 - n + 1}{365}, \qquad P(\text{at least two equal}) = 1 - P(\text{all different}).
nn 1010 2323 3030 5050
P(at least two equal)P(\text{at least two equal}) 11.7 %11.7\,\% 50.7 %50.7\,\% 70.6 %70.6\,\% 97.0 %97.0\,\%

Why so high? – Counting pairs (view “Pairs”): It is not about one particular day but about any pair. nn people form n⋅(n−1)2\frac{n \cdot (n-1)}{2} pairs, already 253253 for 2323 people. Each pair shares a birthday with probability 1365\frac{1}{365}. If we pretend the pairs are independent, we get the good approximation

P≈1−(364365)n(n−1)2,n=23:  1−(364365)253≈50.0 %.P \approx 1 - \left(\frac{364}{365}\right)^{\frac{n(n-1)}{2}}, \qquad n = 23: \; 1 - \left(\tfrac{364}{365}\right)^{253} \approx 50.0\,\%.

Compare: “on my birthday”. Here only the nn pairs “me – other person” count:

P(someone on my day)=1−(364365)n,n=25:≈6.6 %.P(\text{someone on my day}) = 1 - \left(\frac{364}{365}\right)^{n}, \qquad n = 25: \approx 6.6\,\%.

Only from 253253 other people on is this value above 50 %50\,\%.

Simulation (view “Many classes”): Each tile is a randomly drawn class: filled with, light with a border without a shared birthday. The relative frequency h=hitsclassesh = \frac{\text{hits}}{\text{classes}} varies a lot at first and then approaches the probability PP (empirical law of large numbers). The light funnel shows where hh lies after NN classes in about 95 %95\,\% of all cases: P±1.96⋅P(1−P)NP \pm 1.96 \cdot \sqrt{\frac{P(1-P)}{N}}.

Same month, same weekday: The same calculation works with 1212 months or 77 weekdays. With only 55 people, two share a birth month with probability 61.8 %61.8\,\%. From 1313 people on it is certain: there are only 1212 months, so two must share one (pigeonhole principle). The product then contains the factor 012\frac{0}{12}.

Try it

  1. Press New class several times. How often do you find a shared day? One class
  2. Tap your birthday in the calendar and compare the two questions. My birthday
  3. Start 1000 classes and watch the curve of the relative frequency settle into the funnel. Simulation
  4. Watch the free days shrink. From which person on is P(all different)P(\text{all different}) smaller than 0.50.5? Calculation
  5. Tap a person in the pairs view: how many pairs does it form? How many pairs are there in total? Pairs
  6. Switch the pairs view to “on my birthday”. Why are there suddenly far fewer lines? Only my pairs
  7. Choose “same month” and increase nn from 55 to 1313. What happens at 1313? Same month · 13 people

Tasks

Task 1: Three people

Find the probability that at least two of three people share a birthday. Load task

Show solution

P=1−365365⋅364365⋅363365≈1−0.9918=0.0082P = 1 - \frac{365}{365} \cdot \frac{364}{365} \cdot \frac{363}{365} \approx 1 - 0.9918 = 0.0082, so about 0.82 %0.82\,\%. Show in the simulation

Task 2: Your class

Find the probability for a class size of 2828. About how many of 10001000 classes of this size have a shared birthday? Check with the simulation. Load task

Show solution

For n=28n = 28, P≈65.4 %P \approx 65.4\,\%, so about 654654 of 10001000 classes. The simulation gives values around this; after 10001000 classes hh almost always lies between about 0.620.62 and 0.680.68. Show in the simulation

Task 3: Pairs and approximation

How many pairs do 3030 people form? Use this to compute the approximation and compare it with the exact value 70.6 %70.6\,\%. Load task

Show solution

30⋅292=435\frac{30 \cdot 29}{2} = 435 pairs. Approximation: 1−(364365)435≈69.7 %1 - \left(\frac{364}{365}\right)^{435} \approx 69.7\,\% – just below the exact value 70.6 %70.6\,\%. Show in the simulation

Task 4: My birthday

What is the probability that one of 2525 other people has a birthday on exactly your birthday? Why is this so much less than 56.9 %56.9\,\%? Load task

Show solution

1−(364365)25≈6.6 %1 - \left(\frac{364}{365}\right)^{25} \approx 6.6\,\%. Here someone has to hit one particular day, and there are only 2525 pairs “me – other”. In the birthday problem any of 300300 pairs is enough. Show in the simulation

Task 5: Same weekday

What is the probability that at least two of 44 people were born on the same weekday? From how many people on is it certain? Load task

Show solution

P=1−7⋅6⋅5⋅474=1−8402401≈65.0 %P = 1 - \frac{7 \cdot 6 \cdot 5 \cdot 4}{7^4} = 1 - \frac{840}{2401} \approx 65.0\,\%. From 88 people on it is certain (pigeonhole principle: only 77 weekdays). Show in the simulation

Task 6: Model check

In reality, birthdays are not spread quite evenly over the year. Does this make a shared birthday more or less likely?

Show solution

Rather more likely: if some days are more frequent, birthdays cluster there and matches become more likely. The even distribution is the “least favourable” case for shared birthdays.

Ideas for the classroom

  • Use: Lower secondary, multi-stage random experiments and stochastic simulations. Let the class estimate before calculating – and perhaps take a look at the birthdays in your own class.
  • Simulation and calculation: The view “Many classes” makes the surprising size plausible, the view “Calculation” explains it. The funnel shows how much relative frequencies still vary after 100100 classes.
  • Same month works well as a game in class: even in small groups a shared month almost always turns up.
  • Compare groups: Each device draws its own classes. Collect the numbers of hits after 100100 classes each on the board – the spread between the groups fits the funnel well.
  • Common stumbling blocks:
    • The birthday problem is confused with “someone shares my birthday”.
    • Computing n365\frac{n}{365} – which is even greater than 11 for large nn.
    • Adding the factors 364365,363365,…\frac{364}{365}, \frac{363}{365}, \ldots instead of multiplying them.