What is the Probability of Two Sharing Birthday?


Assume a year has 365 days, what is the probability among 50 students, that at least two having the same birthday?

Let’s consider this: what is the probability that all 50 students are having different birthdays?

tex_3e9ee4865e46a28902c4218503e3ad85 What is the Probability of Two Sharing Birthday? algorithms c / c++ math puzzle .

P is the permutation function, so P(365, 50) is the total permutation of choosing 50 out of 365. We are choosing 50 days out of a year which is the students having different birthdays. The total number of possibilities is 36550.

So the answer will be 1 – 0.03 = 97%.

Let’s consider this: what is the probability that all only two (exactly two) share the birthday?

Let’s solve this step by step:

  1. Pick two out of 50 students, which is C(50, 2) i.e. C is the combination function.
  2. Pick one out of 365 days, which is used as the same birthday, that is 365 solutions.
  3. Among the 48 students, their birthdays should be among the rest 364 days, which is P(364, 48)

Therefore, the probability that all only two (exactly two) share the birthday is:

tex_0717200969b18fa12a25f88d85688e06 What is the Probability of Two Sharing Birthday? algorithms c / c++ math puzzle

C++ solution to compute the probability

Let’s create a simple console application in C/C++.

1
2
3
4
5
6
7
8
9
10
11
12
13
// birthday.c
// https://helloacm.com/what-is-the-probability-of-two-sharing-birthday/
#include <stdio.h>
 
int main() {
  double r = 1.0;
  for (int i = 0; i < 48; i ++) {
     r *= (364 - i) / 365.0;
  }
  r = r * (25.0 * 49) / 365.0;
  printf("%.5lf\n", r);
  return 0;
}
// birthday.c
// https://helloacm.com/what-is-the-probability-of-two-sharing-birthday/
#include <stdio.h>

int main() {
  double r = 1.0;
  for (int i = 0; i < 48; i ++) {
     r *= (364 - i) / 365.0;
  }
  r = r * (25.0 * 49) / 365.0;
  printf("%.5lf\n", r);
  return 0;
}

Compile above using gcc birthday.c -o birthday. Run ./birthday:

0.11485

That means the probability of exactly two out of 50 having the same birthday is 11.485%.

Useful Link

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
414 words
Last Post: How to Call COM Object from Visual Studio C++?
Next Post: How to Add Search Function to A Blog?

The Permanent URL is: What is the Probability of Two Sharing Birthday?

Leave a Reply