The symbol for Aries is the Ram, representing its headstrong nature and determination to charge forward, breaking through any barrier.
In mythology, A
# 1.6: An Example - The Birthday Problem
## The Birthday Problem
This is a well-known problem in probability theory.
We have $n$ people in a room. We assume that their birthdays are independent and uniformly distributed among the 365 days of the year. We ignore the complication of leap-years. We want to compute the probability that at least two people have the same birthday.
Let us label the people , 2, \dots, n$. The sample space $\Omega$ consists of all $n$-tuples of integers between 1 and 365. There are 5^n$ such $n$-tuples.
We assume that each such $n$-tuple is equally likely. So, $\mathbb{P}(E) = \frac{|E|}{365^n}$ for any event $E$.
Let $A$ be the event that at least two people have the same birthday. It is easier to compute $\mathbb{P}(A^c)$, the probability that no two people have the same birthday.
$A^c$ occurs if and only if all birthdays are distinct. How many $n$-tuples with distinct birthdays are there? The first person can have any of 365 birthdays, the second person can have any of the remaining 364 birthdays, the third person can have any of the remaining 363 birthdays, etc. So, the number of $n$-tuples with distinct birthdays is
$5 \times 364 \times 363 \times \dots \times (365 - n + 1)$$
Thus,
$$\mathbb{P}(A^c) = \frac{365 \times 364 \times \dots \times (365 - n + 1)}{365^n}$$
and
$$\mathbb{P}(A) = 1 - \frac{365 \times 364 \times \dots \times (365 - n + 1)}{365^n}$$
For $n = 23$, we can compute $\mathbb{P}(A) \approx 0.507$. So, with just 23 people in the room, there is a better than 50% chance that at least two people share a birthday. For $n = 50$, $\mathbb{P}(A) \approx 0.970$. So, with 50 people, it is almost certain that at least two people share a birthday.
This is counterintuitive to many people. The reason is that we are not looking for a specific pair of people to share a birthday, but rather any pair. The number of pairs grows quadratically with $n$, so the probability grows quickly.
## Simulation
We can simulate the birthday problem using Python. The following code simulates the birthday problem for $n$ people and returns the probability that at least two people share a birthday.
import random
def birthday_simulation(n, trials=10000):
count = 0
for _ in range(trials):
birthdays = [random.randint(1, 365) for _ in range(n)]
if len(birthdays) != len(set(birthdays)):
count += 1
return count / trials
for n in [10, 20, 23, 30, 40, 50]:
print(f"n = {n}: {birthday_simulation(n)}")
This will output something like:
n = 10: 0.1169
n = 20: 0.4112
n = 23: 0.5073
n = 30: 0.7065
n = 40: 0.8912
n = 50: 0.9704
The simulation results are close to the theoretical values.
## Generalization
We can generalize the birthday problem. Suppose we have $n$ people and each person's birthday is uniformly distributed among $d$ days. What is the probability that at least two people share a birthday?
The same reasoning gives
$$\mathbb{P}(A) = 1 - \frac{d \times (d-1) \times \dots \times (d-n+1)}{d^n}$$
For $d = 365$, we get the original birthday problem.
We can also ask: how many people are needed so that the probability of a shared birthday is at least $p$? We can solve for $n$ in the equation
$ - \frac{d \times (d-1) \times \dots \times (d-n+1)}{d^n} \ge p$$
For $p = 0.5$ and $d = 365$, we get $n \approx 23$.
## Applications
The birthday problem has applications in cryptography, hashing, and other areas. For example, in cryptography, the birthday attack is a type of cryptographic attack that exploits the mathematics behind the birthday problem in probability theory. The attack depends on the higher likelihood of collisions found between random attack attempts and a fixed degree of permutations (pigeonholes).
## Conclusion
The birthday problem is a classic example in probability theory. It shows how counterintuitive probabilities can be. It also demonstrates the power of combinatorial reasoning in computing probabilities.
In the next section, we will discuss conditional probability and independence.