Jump to content

Birthday problem

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by 65.196.158.240 (talk) at 17:31, 11 October 2005 (→‎Calculating the probability: table changed to use prettytable, since header p(n;365) was centering over 99.99...98% and therefore looked to be out to the side.). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

The birthday paradox states that if there are 23 people in a room then there is a chance of more than 50% that at least two of them will have the same birthday. This means that in a typically-sized school class, where the 'paradox' is often cited, an even higher probability often applies. For 60 or more people, the probability is already greater than 99%. This is not a paradox in the sense of leading to a logical contradiction; it is a paradox in the sense that it is a mathematical truth that contradicts common intuition. Most people estimate that the chance is much lower than 50:50. Calculating this probability (and related ones) is the birthday problem. The mathematics behind it has been used to devise a well-known cryptographic attack named the birthday attack.

Understanding the paradox

The key to understanding the birthday paradox is to realize that there are many possible pairs of people whose birthdays could match. Specifically, among 23 people, there are C(23,2) = 23 × 22/2 = 253 pairs, each of which being a potential candidate for a match. Looked at in this way, it doesn't seem that unlikely that one of these 253 pairs yields a match.

To emphasize the point, consider a different scenario: if you enter a room with 22 other people, the chance that somebody there has the same birthday as you is not 50:50, but much lower. This is because now there are only 22 possible pairs that could yield a match. The actual birthday problem is asking if any of the 23 people have a matching birthday with any of the others.

Calculating the probability

To compute the approximate probability that in a room of n people, at least two have the same birthday, we disregard distribution variations, such as leap years, twins, seasonal or weekday variations, and assume that d = 365 possible birthdays are equally likely. Real-life birthday distributions are not uniform since not all dates are equally likely.

Note that keeping d generic allows us to find the (approximate) solution to a more general problem: given n random integers drawn from a discrete uniform distribution with range [1,d], what is the probability that at least two numbers are the same?

The trick is to first calculate the probability p(n;d) that all n birthdays are different. If n > d, by the pigeonhole principle this probability is 0%. On the other hand, if nd, it is given by

A graph showing the probability of at least two people sharing a birthday amongst a certain number of people.

because the second person cannot have the same birthday as the first (364/365), the third cannot have the same birthday as the first two (363/365), etc.

Using the Taylor series expansion (some may say the definition) of the exponential function

the above expression can be approximated as

The event of at least two of the n persons having the same birthday is complementary to all n birthdays being different. Therefore, its probability p(n;d) is

Substituting n = 23 and d = 365 gives a probability of about 50.7%. The following table shows other probabilities, numerically computed using the formula above, for d = 365:

n p(n;365)
10 12%
20 41%
30 70%
50 97%
100 99.99996%
200 99.9999999999999999999999999998%
300 1 − (7 × 10−73)
350 1 − (3 × 10−131)
≥366 100%

Accuracy of the approximation

A graph showing the accuracy of the approximation used in the above.

An even coarser approximation to the answer is given by

which, as the graph illustrates, is still fairly accurate for d = 365.

Same birthday as you

Comparing p(n;365) = probability of a birthday match with q(n;365) = probability of matching your birthday

Note that in the birthday problem, neither of the two people is chosen in advance. By way of contrast, the probability q(n;d) that someone in a room of n other people has the same birthday as a particular person (for example, you), or more generally has picked the same number between 1 and d as you, is given by

Substituting n = 22 and d = 365 gives about 5.9%, which is only slightly better than 1 chance in 17. For a greater than 50:50 chance that one person in a roomful of n people has the same birthday as you, n would need to be at least 253. Note that this number is significantly higher than 365/2 = 182.5: the reason is that there are likely some birthday matches among the people in the room.

Reverse problem

An alternate question may be:

For a fixed probability p and number of days in a year d...
... find the greatest n(p;d) for which the probability p(n;d) is smaller than the given p, or
... find the smallest n(p;d) for which the probability p(n;d) is greater than the given p.

An approximation for this is given by:

Example

approximationcomputation for d := 365
pn generalizedn for d := 365 np(n↓)np(n↑)
0.01
0.14178 √d
2.70864
20.002743
0.00820
0.050.32029 √d 6.1191660.0404670.05624
0.1
0.45904 √d
8.77002
80.074349
0.09462
0.2
0.66805 √d
12.76302
120.1670213
0.19441
0.30.84460 √d16.13607160.28360170.31501
0.51.17741 √d22.49439220.47570230.50730
0.71.55176 √d29.64625290.68097300.70632
0.81.79412 √d34.27666340.79532350.81438
0.92.14597 √d40.99862400.89123410.90315
0.952.44775 √d46.76414460.94825470.95477
0.99
3.03485 √d
57.98081
57
0.99012
580.99166

Note: some values are coloured showing that the approximation is not always exact.

Implications of inequalities

For variations of the birthday scenario in broader contexts, a different flavor of argument is essential. The argument below, exploiting important inequalities, is adapted from an argument of Paul Halmos(refactored from Halmos).

The probability of coincident birthdays, p(n), is one minus the probability that no two birthdays coincide, 1 − p(n). The usual argument given above says that p(n) is the product

We are interested in the smallest n such that p(n) > 1/2; or equivalently, the smallest n such that p(n), shown here, is less than 1/2. The general idea is to repeatedly replace the complicated product by simpler expressions, each of which is no smaller in value. If our final simple expression is less than 1/2, then the true value must be also. Results obtained this way may be overly conservative, in the sense that a smaller value of n might suffice; but they are always safe.

Because of the inequality of arithmetic and geometric means, we have

Here the left side is the geometric mean (root of a product) and the right side is the arithmetic mean (division of a sum). Neither side is greater than one, so raising both sides to the power n−1 does not change the inequality. Thus our first replacement is

That is, we substitute the sum raised to n−1 for the product. The sum splits into (∑ 1) − (∑k)/365; and since the first is a constant (summing to n−1) and the second an arithmetic progression (summing to n(n − 1)/2), we can replace the sum by an exact expression:

Our next substitution uses the inequality 1 − x < ex. Thus we have

By the usual laws of exponents, (ea)b = eab; so we can simplify again:

Noting that ex = 1/ex, we see that ex < 1/2 is the same as ex > 2 (reciprocating reverses the inequality). We can take logarithms of both sides without changing the ordering; thus our original inequality demand, that the probability product be less than 1/2, finally simplifies to the much more manageable

(Here "log" refers to the natural logarithm.) Now 730 log 2 is approximately 505.997, which is barely below 506, the value of n2 − n attained when n = 23. Therefore, 23 people suffice.

Note that Halmos' derivation only shows that at most 23 people are needed to ensure a birthday match with even chance; since we haven't studied how sharp the given inequalities are, the argument leaves open the possibility that, say, n = 22 could also work.

Empirical test

days := 365
numPeople := 1
prob := 0.0
while prob < 0.5 {
    numPeople := numPeople + 1
    prob := 1 - ((1-prob) * (days-(numPeople-1)) / days)
    print "Number of people: " + numPeople
    print "Prob. of same birthday: " + prob
}

Applications

The birthday paradox in its more generic sense applies to hash functions: the number of N-bit hashes that can be generated before probably getting a collision is not 2N (this is the probability that a specific hash gets repeated), but rather only 2N/2 (this is the probability that any 2 generated hash values are the same). This is exploited by birthday attacks on cryptographic hash functions.

The theory behind the birthday problem was used in [Schnabel 1938] under the name of capture-recapture statistics to estimate the size of fish population in lakes.

Unequal probabilities

As mentioned above, real-world birthday data are not equally distributed. The birthday problem for such non-constant birthday probabilities was tackled in [Klamkin 1967].

Near matches

Another generalization is to ask how many people are needed in order to have a better than 50% chance that two people have a birthday within one day of each other, or within two, three, etc., days of each other. This is a more difficult problem and requires use of the inclusion-exclusion principle. The results (assuming an equal distribution for birthdays) are just as surprising as in the standard birthday problem:

within k days    #people required
0   23
1   14
2   11
3    9
4    8
5    7
7    6

Thus in a family with six members, it is more likely than not that two members will have a birthday within a week of each other.

References

  • Zoe Emily Schnabel: "The estimation of the total fish population of a lake", American Mathematical Monthly 45 (1938), pages 348-352
  • M. Klamkin and D. Newman: "Extensions of the birthday surprise", Journal of Combinatorial Theory 3 (1967), pages 279-282.

Note

Template:Ent In his autobiography, Halmos deplored the fact that the birthday paradox is often presented in terms of numerical computation rather than more abstract concepts. He wrote: The reasoning is based on important tools that all students of mathematics should have ready access to. The birthday problem used to be a splendid illustration of the advantages of pure thought over mechanical manipulation; the inequalities can be obtained in a minute or two, whereas the multiplications would take much longer, and be much more subject to error, whether the instrument is a pencil or an old-fashioned desk computer. What calculators do not yield is understanding, or mathematical facility, or a solid basis for more advanced, generalized theories.