Massachusetts Institute of Technology Lecture 21 6.042J/18.062J: Mathematics for Computer Science April 20, 2000 Professors Nancy Lynch and Srinivas Devadas

Independence

1 Set Theory and Probability

1.1 Basic Facts

Here are some handy facts about the probability of various combinations of sets:

Theorem 1.1 Suppose A and B are events in the same probability space.

1. If A ⊆ B then Pr(A) ≤ Pr(B).

2. Pr(Ā) = 1 − Pr(A).

3. Pr(A ∪ B) = Pr(A) + Pr(B) − Pr(A ∩ B).

4. Pr(A ∪ B) ≤ Pr(A) + Pr(B).

5. Pr(A ∩ B) = Pr(A) − Pr(A − B).

6. Pr(A ∩ B) ≤ Pr(A).

These can be proved from the basic definition of probability of a set as the sum of the probabilities of all the individual elements of the set, plus facts from basic set theory. For instance, to show the first part, we assume that A ⊆ B and note that Pr(A) = Σ_{s∈A} Pr(s) ≤ Σ_{s∈B} Pr(s) = Pr(B).

1.2 Example: Circuit Failure

Suppose you are wiring up a circuit containing a total of n connections. From past experience we assume that any particular connection is made incorrectly with probability p, for some 0 ≤ p ≤ 1. That is, for 1 ≤ i ≤ n,

Pr(i^{th} connection is wrong) = p.

What can we say about the probability that the circuit is wired correctly, i.e., that it contains no incorrect connections?

Let A_{i} denote the event that connection i is made correctly. Then Ā_{i} is the event that connection i is made incorrectly, so Pr(Ā_{i}) = p. Now Pr(all connections are OK) = Pr(∩_{i=1}^{n}A_{i}).

Without any additional assumptions (we will reconsider this problem after we introduce independence, below), we can’t get an exact answer. However, we can give reasonable upper and lower bounds.

For an upper bound, we can see that Pr(∩_{i=1}^{n}A_{i}) ≤ Pr(A_{1}) = 1 − p. This follows because of the first fact, about subset.

For a lower bound, we can see that Pr(∩_{i=1}^{n}A_{i}) = 1 − Pr(∪_{i=1}^{n}Ā_{i}) using the second fact, which is ≥ 1 − ∑_{i=1}^{n} Pr(Ā_{i}) by the fourth fact (actually, by the natural generalization of the fourth fact to n sets instead of 2), which is equal to 1 − np. That is, Pr(∩_{i=1}^{n}A_{i}) ≥ 1 − np.

So for example, if n = 10 and p = 0.01, we get the following bounds:

0.9 = 1 − 10 · 0.01 ≤ Pr(all connections are OK) =≤ 1 − 0.01 = 0.99.

So we have concluded that the chance that all connections are okay is somewhere between 90% and 99%. Although we don’t have enough information to calculate the probability of individual sample points, we can conclude something useful by using simple facts from set theory.

Could it actually be as high as 99% ? Yes, if the errors occur in such a way that whenever you make one connection wrong, all the connections are wrong.

Could it be 90% ? Yes, suppose the errors are such that we never make two wrong connections. So the events \overline{A_{i}} are all disjoint and the probability of getting it right is

Pr(∩A_{i}) = 1 − Pr(∪\overline{A_{i}}) = 1 − ∑_{i=1}^{10} Pr(\overline{A_{i}}) = 1 − 10 · 0.01 = 0.9.

1.3 Extension to Conditional Probability

All of the basic facts extend to conditional probability:

Theorem 1.2 Suppose A, B, and C are events in the same probability space, and Pr(C) ≠ 0.

1. If A ⊆ B then Pr(A | C) ≤ Pr(B | C).

2. Pr(Ā | C) = 1 − Pr(A | C).

3. Pr(A ∪ B | C) = Pr(A | C) + Pr(B | C) − Pr(A ∩ B | C).

4. Pr(A ∪ B | C) ≤ Pr(A | C) + Pr(B | C).

5. Pr(A ∩ B | C) = Pr(A | C) − Pr(A − B | C).

6. Pr(A ∩ B | C) ≤ Pr(A | C).

These facts follow from the definition of conditional probability and the previous set of facts. For instance, to show the first part:

Prove: If A ⊆ B then Pr(A | C) ≤ Pr(B | C).

1. Assume A ⊆ B.

2. A ∩ C ⊆ B ∩ C. Set theory.

3. Pr(A ∩ C) ≤ Pr(B ∩ C). By the previous theorem.

4. Pr(A | C) = \frac{Pr(A∩C)}{Pr(C)}, Pr(B | C) = \frac{Pr(B∩C)}{Pr(C)}.

Definition.

5. Pr(A | C) ≤ Pr(B | C). Algebra.

6. QED Implication

2 Uniform Probability Spaces

This material is here for review and reference—we use it later in the lecture.

Definition A probability space S is uniform or equiprobable if Pr(s) is the same for all s ∈ S.

This definition has the following consequence. Since the sum of the probabilities over all outcomes is 1, we must have Pr(s) = \frac{1}{|S|} for all outcomes s in a uniform probability space S.

The probability of an event in a uniform probability space is very easy to compute. We only need to count the number of outcomes in the event. This amounts to counting the number of items in a set— we know all about that!

Theorem 2.1 If A is an event in a uniform probability space, then

Pr(A) = \frac{|A|}{|S|}

Proof.

Pr(A) = ∑_{s∈A} Pr(s)

= ∑^{s∈A} \frac{1}{|S|}
= \frac{|A|}{|S|}

The first equation follows because the probability of an event is defined to be the sum of the probabilities of the outcomes it contains. The second equation comes from the observation above that every outcome in a uniform sample space has probability \frac{1}{|S|}. The final equation holds because the sum has |A| terms.

3 Independence

The main topic of today’s lecture is independence.

3.1 Definition

Definition Suppose A and B are events in the same probability space. Then A is independent of B if:

Pr(A | B) = Pr(A)

Figure 1: In this diagram, event A is independent of event B.

In other words, that fact that event B occurs does not affect the probability that event A occurs.

Figure 1 shows an arrangement of events such that A is independent of B. Assume that the probability of an event is proportional to its area in the diagram. In this example, event A occupies the same fraction of event B as of event S, namely \frac{1}{2}. Therefore, the probability of event A is \frac{1}{2} and the probability of event A, given event B, is also \frac{1}{2}. This implies that A is independent of B.

It turns out that independence is a symmetric relation:

Theorem 3.1 Suppose A and B are events in the same probability space, with nonzero probabilities. If event A is independent of B, then B is independent of A.

For this reason, we do not have to say, “A is independent of B” or vice versa; we can just say “A and B are independent”.

Proof.

Assume: Pr(A | B) = Pr(A). Prove: Pr(B | A) = Pr(B).

1. Pr(A | B) = \frac{Pr(A∩B)}{Pr(B)} Definition of |

2. Pr(B | A) = \frac{Pr(A∩B)}{Pr(A)} Definition of |

3. Pr(A | B) · Pr(B) = Pr(B | A) · Pr(A) Algebra, from 1. and 2.

4. Pr(B | A) = Pr(B). Algebra, from 3. and the assumption.

For example, in Figure 1, B occupies the same fraction of event A as of event S (about \frac{1}{4}).

3.2 Coin Examples

Suppose we flip two fair coins. Let A be the event that the first coin is heads, and let B be the event that the second coin is heads. Since the coins are fair, we have Pr(A) = Pr(B) = \frac{1}{2}. In fact, the probability that the first coin is heads is still \frac{1}{2}, even if we are given that the second coin is heads; the outcome of one toss does not affect the outcome of the other. In symbols, Pr(A | B) = \frac{1}{2}. Since Pr(A | B) = Pr(A), events A and B are independent.

Now suppose that we glue the coins together, heads to heads. Now each coin still has probability \frac{1}{2} of coming up heads; that is, Pr(A) = Pr(B) = \frac{1}{2}. But if the second coin comes up heads, then the first coin must be tails! That is, Pr(A | B) = 0. Now, since Pr(A | B) ≠ Pr(A), the events A and B are not independent.

3.3 Disjoint Events vs. Independent Events

Suppose that events A and B are disjoint, as shown in Figure 2; that is, no outcome is in both events. In the diagram, we see that Pr(A) is non-zero. On the other hand:

Figure 2: This diagram shows two disjoint events, A and B. Disjoint events are not independent!

Pr(A | B) = \frac{Pr(A ∩ B)}{Pr(B)}
= 0

Therefore, Pr(A | B) ≠ Pr(A), and so event A is not independent of event B. In general, disjoint events are not independent.

3.4 Product Rule for Independent Events

The Product Rule says:

Pr(A ∩ B) = Pr(A | B) · Pr(B)

If A and B are independent events, then Pr(A | B) = Pr(A). In this case, the Product Rule simplifies to:

Pr(A ∩ B) = Pr(A) · Pr(B)

This rule is very useful and worth remembering. But also remember that it only holds if A and B are independent events!

Many textbooks define two events to be independent if Pr(A∩B) = Pr(A)·Pr(B). This is equivalent to our definition, though we will not prove that here.

4 More Examples

These two examples show that it is not always obvious whether two events are independent or not.

4.1 An Experiment with Two Coins

Suppose that we flip two independent, fair coins. Let A be the event that the coins match; that is, both are head or both are tails. Let B the event that the first coin is heads. Are these independent events?

At first, the answer may appear to be “no”. After all, whether or not the coins match depends on how the first coin comes up; if we toss HH, then they match, but if we toss T H, then they do not.

The preceding observation is true, but irrelevant. The two events are independent if Pr(A | B) = Pr(A), and we can prove this by the usual procedure.

Claim 4.1 Events A and B are independent.

Proof. We must show that Pr(A | B) = Pr(A).

Step 1: Find the Sample Space. The tree diagram in Figure 3 shows that there are four outcomes in this experiment, HH, T H, HT, and T T.

Figure 3: This is a tree diagram for the two coins experiment.

Step 2: Define Events of Interest. As previously defined, A is the event that the coins match, and B is the event that the first coin is heads. Outcomes in each event are marked in the tree diagram.

Step 3: Compute Outcome Probabilities. Since the coins are independent and fair, all edge probabilities are \frac{1}{2}. We find outcome probabilities by multiplying edge probabilities on each rootto-leaf path. All outcomes have probability \frac{1}{4}.

Step 4: Compute Event Probabilities.

Pr(A | B) = \frac{Pr(A ∩ B)}{Pr(B)}
= \frac{Pr(HH)}{Pr(HH) + Pr(HT)}
= \frac{\frac{1}{4}}{\frac{1}{4} + \frac{1}{4}}
= \frac{1}{2}
Pr(A) = Pr(HH) + Pr(T T)
= \frac{1}{4} + \frac{1}{4}
= \frac{1}{2}

Therefore, Pr(A | B) = Pr(A), and so A and B are independent events as claimed.

4.2 A Variation of the Two-Coin Experiment

Now suppose that we alter the preceding experiment so that the coins are independent, but not fair. That is each coin is heads with probability p and tails with probability 1 − p. Again, let A be the event that the coins match, and let B the event that the first coin is heads. Are events A and B independent for all values of p?

The problem is worked out with a tree diagram in Figure 4. The sample space and events are the same as before, so we will not repeat steps 1 and 2 of the probability calculation.

Figure 4: This is a tree diagram for a variant of the two coins experiment. The coins are still independent, but no longer necessarily fair.

Step 3: Compute Outcome Probabilities. Since the coins are independent, all edge probabilities are p or 1−p. Outcomes probabilities are products of edge probabilities on root-to-leaf paths, as shown in the figure.

Step 4: Compute Event Probabilities.

We want to determine whether Pr(A | B) = Pr(A).

Pr(A | B) = \frac{Pr(A ∩ B)}{Pr(B)}
= \frac{Pr(HH)}{Pr(HH) + Pr(HT)}
= \frac{p^{2}}{p^{2} + p(1 − p)}
= p
Pr(A) = Pr(HH) + Pr(T T)
= p^{2} + (1 − p)^{2}
= 1 − 2p + 2p^{2}

Events A and B are independent only if these two probabilities are equal:

Pr(A | B) = Pr(A)
⇔  p = 1 − 2p + 2p^{2}
⇔  0 = 1 − 3p + 2p^{2}
⇔  0 = (1 − 2p)(1 − p)
⇔  p = \frac{1}{2}, 1

The two events are independent only if the coins are fair or if both always come up heads. Evidently, there was some dependence lurking in the previous problem, but it was cleverly hidden by the unbiased coins!

4.3 Dice

Suppose we throw two fair dice. Is the event that the sum is equal to a particular value independent of the event that the first throw yields another particular value?

To be specific, let A be the event that the the first die turns up 3 and B the event that the sum is 6. Are the two events independent?

No, because Pr(B | A) = \frac{Pr(B∩A)}{Pr(A)} = \frac{\frac{1}{36}}{\frac{1}{6}} = \frac{1}{6}, whereas Pr(B) = \frac{5}{36}.

On the other hand, let A be the event that the first die turns up 3 and B the event that the sum is 7. Then Pr(B | A) = \frac{Pr(B∩A)}{Pr(A)} = \frac{\frac{1}{36}}{\frac{1}{6}} = \frac{1}{6}, whereas Pr(B) = \frac{6}{36}. So in this case, the two events are independent.

Can you explain the difference between these two results?

5 Mutual Independence

We have defined what it means for two events to be independent. But how can we talk about independence when there are more than two events?

5.1 Example: Blood Evidence

During the O. J. Simpson trial a few years ago, a probability problem involving independence arose. A prosecution witness claimed that only one in 200 Americans has the blood type found at the crime scene. The witness then presented facts something like the following:

• \frac{1}{10} of people have type O blood.

• \frac{1}{5} of people have a positive Rh factor.

• \frac{1}{4} of people have another special marker.

The one in 200 figure came from multiplying these three fractions. Was the witness reasoning correctly?

The answer depends on whether or not the three blood characteristics are independent. This might not be true; maybe most people with O^{+} blood have the special marker. When the math-competent defense lawyer asked the witness whether these characteristics were independent, he could not say. He could not justify his claim.

5.2 Definition

What sort of independence is needed to justify multiplying probabilities of more than two events? The notion we need is called mutual independence.

Definition Events A_{1}, A_{2}, …, A_{n} are mutually independent if for all i such that 1 ≤ i ≤ n and for all J ⊆ [1, n] − {i}, we have:

Pr(A_{i} | ⋂_{j∈J} A_{j}) = Pr(A_{i})

In other words, a collection of events is mutually independent if each event is independent of the intersection of every subset of the others. The following definition is equivalent, though we will not prove this.

Definition Events A_{1}, A_{2}, …, A_{n} are mutually independent if for all J ⊆ [1, n], we have:

Pr(⋂_{j∈J} A_{j}) = ∏_{j∈J} Pr(A_{j})

Like the general form of the Inclusion-Exclusion principle, these general definitions of mutual independence are a bit tricky. The following special case of the second definition may be easier to understand.

Definition Three events A_{1}, A_{2}, A_{3} are mutually independent if all of the following hold:

Pr(A_{1} ∩ A_{2}) = Pr(A_{1}) · Pr(A_{2})
Pr(A_{1} ∩ A_{3}) = Pr(A_{1}) · Pr(A_{3})
Pr(A_{2} ∩ A_{3}) = Pr(A_{2}) · Pr(A_{3})
Pr(A_{1} ∩ A_{2} ∩ A_{3}) = Pr(A_{1}) · Pr(A_{2}) · Pr(A_{3})

Important: To prove a set of three or more events mutually independent, it is not sufficient to prove every pair of events independent! In particular, for three events we must also prove that the fourth equality listed above holds.

In the blood example, if the three blood characteristics were mutually independent, then the witness was justified in multiplying probabilities by the fourth equality above.

5.3 Flipping a Set of Coins

Suppose we flip n fair coins. Let A_{i} be the event that the i-th coin is heads. The outcome of one coin in unaffected by the outcomes of the others. Therefore, for all i, we have:

Pr(A_{i} | any set of other events) = \frac{1}{2} = Pr(A_{i})

This implies that the events are mutually independent. The probability of flipping all heads can be found by using the second definition of mutual independence:

Pr(⋂_{i=1}^{n} A_{i}) = (\frac{1}{2})^{n}

5.4 A Red Sox Streak

The Boston Red Sox baseball team has lost 14 consecutive playoff games. What are the odds of such a miserable streak?

Suppose that we assume that the Sox have a \frac{1}{2} chance of winning each game and that the game results are mutually independent. Then we can compute the probability of losing 14 straight games as follows. Let L_{i} be the event that the Sox lose the i-th game. This gives:

Pr(L_{1} ∩ L_{2} ∩ … ∩ L_{14}) = Pr(L_{1}) Pr(L_{2}) · . . . Pr(L_{14})
= (\frac{1}{2})^{14}
= \frac{1}{16, 384}

The first equation follows from the second definition of mutual independence. The remaining steps use only substitution and simplification.

These are pretty long odds; of course, the probability that the Red Sox lose a playoff game may be greater than \frac{1}{2}. Maybe they’re cursed.

5.5 An Experiment with Three Coins

This is a tricky problem that always confuses people! Suppose that we flip three fair coins and that the results are mutually independent. Define the following events:

• A_{1} is the event that coin 1 matches coin 2

• A_{2} is the event that coin 2 matches coin 3

• A_{3} is the event that coin 3 matches coin 1

Are these three events mutually independent?

For once, we will dispense with the tree diagram. The sample space is easy enough to find anyway; there are eight outcomes, corresponding to every possible sequence of three flips: HHH, HHT, HT H, . . .. We are interested in events A_{1}, A_{2}, and A_{3}, defined as above. Each outcome has probability \frac{1}{8}.

To prove that the three events are mutually independent, we must prove a sequence of equalities. It will be helpful first to compute the probability of each event A_{i}:

Pr(A_{1}) = Pr(HHH) + Pr(HHT) + Pr(T T T) + Pr(T T H)
= \frac{1}{8} + \frac{1}{8} + \frac{1}{8} + \frac{1}{8}
= \frac{1}{2}

By symmetry, Pr(A_{2}) = Pr(A_{3}) = \frac{1}{2}. Now we can begin checking all the equalities required for mutual independence.

Pr(A_{1} ∩ A_{2}) = Pr(HHH) + Pr(T T T)
= \frac{1}{8} + \frac{1}{8}
= \frac{1}{4}
= \frac{1}{2} · \frac{1}{2}
= Pr(A_{1}) Pr(A_{2})

By symmetry, Pr(A_{1} ∩ A_{3}) = Pr(A_{1}) Pr(A_{3}) and Pr(A_{2} ∩ A_{3}) = Pr(A_{2}) Pr(A_{3}) must hold as well. We have now proven that every pair of events is independent. But this is not enough to prove that A_{1}, A_{2}, and A_{3} are mutually independent! We must check the fourth condition:

Pr(A_{1} ∩ A_{2} ∩ A_{3}) = Pr(HHH) + Pr(T T T)
= \frac{1}{8} + \frac{1}{8}
= \frac{1}{4}
≠ Pr(A_{1}) Pr(A_{2}) Pr(A_{3})  (which is \frac{1}{8})

The three events A_{1}, A_{2}, and A_{3} are not mutually independent, even though all pairs of events are independent! When proving a set of events independent, remember to check all pairs of events, and all sets of three events, four events, etc.

5.6 Pairwise Independence

Suppose we have a set of events. We know that all pairs of events are independent, but we know nothing about the independence of subsets of three or more events. This situation arises often enough that a special term has been defined for it:

Definition Events A_{1}, A_{2}, … A_{n} are pairwise independent if A_{i} and A_{j} are independent events for all i ≠ j.

Note that mutual independence is stronger than pairwise independence. That is, if a set of events is mutually independent, then it must be pairwise independent, but the reverse is not true. For example, the events in the three coin experiment of the preceding subsection were pairwise independent, but not mutually independent.

In the blood example, suppose initially that we know nothing about independence. Then we can only say that the probability that a person has all three blood factors is no greater than the probability that a person has blood type O, which is \frac{1}{10}.

If we know that the three blood factors in the O. J. case appear pairwise independently, then we can conclude:

Pr(person has all 3 factors) ≤ Pr(person is type O and Rh positive)
= Pr(person is type O) Pr(person is Rh positive)
= \frac{1}{10} · \frac{1}{5}
= \frac{1}{50}

Knowing that a set of events is pairwise independent is useful!

However, if all three factors are mutually independent, then the witness is right; the probability a person has all three factors is \frac{1}{200}.

The point is that we get progressively tighter upper bounds as we strengthen our assumption about independence.

5.7 Example: Circuit Failure

Let’s reconsider the circuit problem mentioned earlier in these notes, involving wiring up a circuit containing n connections, where the probability that each particular connection is made incorrectly, Pr(¯(A_{i})), is p. Again, we want to know the probability that the entire circuit is wired correctly. This time, assume that all the events A_{i} are mutually independent.

Now we can calculate the exact probability that the circuit is correct: (1 − p)^{n}. For n, p as above, this comes out to around 90.4 % Very close to the lower bound. That’s because the chance of more than one error is relatively small (less than 1 %).

6 The Birthday Problem

Most people expect that, if the same experiment is repeated over and over again, independently, the results are likely to be very varied. However, some patterns are actually pretty likely.

6.1 The Problem

There are 365 possible birthdays, ignoring leap-days, and there are 120 students in the lecture hall. What is the probability that two students have the same birthday? 50%? 90%? 99%? In fact, the probability is greater than 99.99999997%! There is less than one chance in four billion that everyone has a different birthday!

There are two big assumptions underlying this assertion. First, we assume that all birthdates are equally likely. Second, we assume that birthdays are mutually independent. Neither assumption is really true. Birthdays follow seasonal patterns and are often related to major events. For example, nine months after a blackout in the 70’s there was a sudden increase in the number of births in New England. (Try counting back nine months from your birthday!) Nevertheless, we’ll stick with these assumptions!

Suppose we perform the following experiment. We ask one student at a time for his or her birthday. How many students must we ask before we find two with the same birthday? Surprisingly, the answer is usually in the mid-twenties. This seems odd! There are 12 months in the year. At a point when we’ve only collected about two birthdays per month, we have usually already found two students with exactly the same birthday!

Here is the intuition. The probability that a pair of students have the same birthday is only \frac{1}{365}. This is very small. But by the time we have a couple dozen birthdays, we have lots of pairs of students! Therefore, the probability that some pair have the same birthday is really pretty good.

In general, suppose there are m students and N days in the year. We want to determine the probability that at least two students have the same birthday. There are at least two good ways to solve this problem. We will show only one here.

6.2 Solution

Step 1. Find the Sample Space

Finding the sample space with a tree diagram is difficult. Each internal node will have N children, and the tree will have depth m. For the values of N and m of interest, this tree will be huge!

We have to find the sample space a different way. There are N possible birthdays for the first student, N birthdays for the second student, and so on for all m students. In fact, we can regard an outcome as a vector of m birthdays. The sample space is the set of all such vectors:

S = {< b_{1}, b_{2}, …, b_{m} >| b_{i} ∈ [1, N] for all i}

By the Product Rule for the cardinality of a product of sets, the size of the sample space is N^{m}.

Step 2: Define Events of Interest

Let A be the event that two or more students have the same birthday. That is, event A is the following set of outcomes:

{< b_{1}, b_{2}, …, b_{m} >| b_{i} = b_{j} for some distinct i and j}

Step 3: Compute Outcome Probabilities

The probability of outcome < b_{1}, b_{2}, …, b_{m} > is the probability that the first student has birthday b_{1} and the second student has birthday b_{2} and the third student has birthday b_{3}, etc. The i-th person has birthday b_{i} with probability \frac{1}{N}. Since birthdates are independent, we can multiply probabilities to get the probability of a particular outcome:

Pr(< b_{1}, b_{2}, …, b_{m} >) = \frac{1}{N^{m}}

Notice that we have a uniform probability space—the probabilities of all the outcomes are the same.

In principle, we could obtain the same result from a tree diagram. Since each students is equally likely to have any one of N birthdays, independent of all other students, we would label every edge in the tree with probability \frac{1}{N}. Then we would compute the probability of an outcome by multiplying probabilities on the corresponding root-to-leaf path. Since the tree has depth m, we would find that every outcome has probability \frac{1}{N^{m}}, exactly as above.

Step 4: Compute Event Probabilities

The remaining task in the birthday problem is to compute the probability of A, the event that two or more students have the same birthday. Since the sample space is uniform, we need only count the number of outcomes in the event. This can be done with inclusion-exclusion, but the calculation is involved.

A simpler method is to use the trick of “counting the complement”. Let Ā be the complementary event; that is, let Ā = S − A. Then, since Pr(A) = 1 − Pr(Ā), we are done if we can determine the probability of event Ā.

In the event Ā, all students have different birthdays. The event consists of the following outcomes:

{< b_{1}, b_{2}, …, b_{m} >| b_{i} ≠ b_{j} for all distinct i and j}

The notation above is a little confusing, but we have seen sets like this before. The set Ā consists of all m-permutations of the set of N possible birthdays! We can now compute the probability of event Ā:

Pr(Ā) = \frac{|Ā|}{|S|}
= \frac{|Ā|}{N^{m}}
= \frac{P (N, m)}{N^{m}}
= \frac{N!}{(N − m)! N^{m}}

The first equation uses Theorem 2.1 to reduce the probability problem to a counting problem. In the second step, we substitute in the size of the sample space S. In the third step, we use the observation that Ā is the set of all m-permutations of an N-element set. In the last step, we substitute the value of P (N, m) that we worked out a few weeks ago.

We now know Pr(A):

Pr(A) = 1 − \frac{N!}{(N − m)! N^{m}}

This is the probability that at least two students in a room of m have the same birthday in a year with N days.

Using this formula, if we have m = 22 students and a year with N = 365 days, then at least two students have the same birthday with probability P (A) ≈ 0.476. If we have m = 23 students, then the probability rises to P (A) ≈ 0.507. Therefore, in a room with 23 students, the odds are better than even that at least two have the same birthday!

7 Approximating the Answer to the Birthday Problem

We now know that Pr(A) = 1 − \frac{N!}{(N−m)! N^{m}}. This formula is hard to work with because it is not a closed form. Evaluating the expression for, say, N = 365 and m = 120 is a lot of work!

There is another reason to want a closed form. We might want to know how many students are needed so that at least two have the same birthday with probability \frac{1}{2}. We computed this for a year with N = 365 days, but what is the answer as a function of N?

7.1 Approximating Pr(Ā)

Unfortunately, there is no closed form for Pr(A). There is a nice approximation for Pr(Ā) using Stirling’s formula, but some ugly math is required to find it! Hold on tight!

\frac{N!}{(N − m)! N^{m}} = \frac{\sqrt{2πN} (\frac{N}{e} )^{N} e^{a_{N}}}{\sqrt{2π(N − m)} (\frac{N−m}{e})^{N−m} e^{a_{N−m}}N^{m}}

= \sqrt{\frac{N}{N − m}} \frac{N^{N}e^{N−m}e^{a_{N} −a_{N−m}}}{(N − m)^{N−m}e^{N}N^{m}}
= \sqrt{\frac{N}{N − m}} \frac{e^{a_{N} −a_{N−m}}}{e^{m} (1 − \frac{m}{N})^{N−m}}

In the expressions above, the symbol a_{i} denotes some value between \frac{1}{12i+1} and \frac{1}{12i}. In effect, a_{i} captures the error in Stirling’s approximation.

The last expression is useful for approximating Pr(Ā). For example, substituting N = 365 and m = 23 gives approximately:

Pr(Ā) = 1.033 \frac{0.99998}{2.097}
= 0.492 …

Substituting N = 365 and m = 120 gives:

Pr(Ā) = 1.221 \frac{0.99999}{5.00 · 10^{9}}
= 2.442 · 10^{−10}

The main difference between these two cases is the denominator of the fraction. For m = 23, the denominator is about 2. For m = 120, it is about 5 billion!

Since the denominator is the main term, let’s try to simplify it some more. The first step looks arbitrary; we apply the identity x = e^{ln x}, seemingly at random:

e^{m} (1 − \frac{m}{N})^{N−m} = e^{m} (e^{ln(1− \frac{m}{N})})^{N−m}

The motivation for the preceding step is that there is a nice Taylor series expansion for ln(1 − x):

ln(1 − x) = −x − \frac{x^{2}}{2} − \frac{x^{3}}{3} − …

We can now continue by replacing ln(1 − \frac{m}{N}) with the Taylor series:

e^{m} (e^{ln(1− \frac{m}{N})})^{N−m} = e^{m}e^{(− \frac{m}{N} − \frac{m^{2}}{2N^{2}} − \frac{m^{3}}{3N^{3}} −...)(N−m)}
= e^{m}e^{(−m− \frac{m^{2}}{2N} − \frac{m^{3}}{3N^{2}} −...)+( \frac{m^{2}}{N} + \frac{m^{3}}{2N^{2}} + \frac{m^{4}}{3N^{3}} +...)}
= e^{\frac{m^{2}}{2N} + \frac{m^{3}}{6N^{2}} + \frac{m^{4}}{12N^{3}} +...}
≥ e^{\frac{m^{2}}{2N}}

Now we have simplified the denominator in our expression for Pr(Ā). Substituting the simplified denominator back into this expression gives:

Pr(Ā) ≤ \sqrt{\frac{N}{N − m}} e^{− \frac{m^{2}}{2N}}

This is the pretty approximation we were aiming for!

7.2 Nice Features of the Formula for Pr(Ā)

The formula derived above for Pr(Ā) has several nice features. First, it shows why the probability that all students have distinct birthdays drops off so incredibly fast as the number of students grows. The reason is that the number of students, m, is squared and then exponentiated! Therefore m has a huge effect on the probability.

Second, this formula actually has some intuitive justification! The number of ways to pair m students is \binom{m}{2} ≈ \frac{m^{2}}{2} . The event that a pair of students has the same birthday has probability \frac{1}{N}. If these events were independent, then the probability that no pair of students had the same birthday would be:

Pr(no pair have same birthday) ≈ (1 − \frac{1}{N} )^{\frac{m^{2}}{2}}
≈ e^{− \frac{1}{N} · \frac{m^{2}}{2}}
= e^{− \frac{m^{2}}{2N}}

(We use the approximation 1 − x ≈ e^{−x}.)

This is almost the same answer that we derived above! Of course, this calculation is for intuition’s sake only; it is blatantly not correct, since we assumed that events were independent when they are not!

7.3 Making the Probability of a Match \frac{1}{2}

A final nice feature of our approximation for Pr(Ā) is that we can determine the number of students for which the probability that two have the same birthday is (approximately) \frac{1}{2}.

First, notice that if m = o(N^{\frac{2}{3}} ), then our approximation is really very good. The reason is that the major source of error was truncating the Taylor series for a logarithm. The terms we threw out were:

\frac{m^{3}}{6N^{2}} + \frac{m^{4}}{12N^{3}} + …

Under the assumption that m = o(N^{\frac{2}{3}} ), these terms all go to zero as N becomes large. Furthermore, under this same assumption the term \sqrt{\frac{N}{N−m}} in our formula tends to 1 as N grows large. Therefore, with this assumption we can conclude:

Pr(Ā) ∼ e^{− \frac{m^{2}}{2N}}

All that remains is to set the probability that all birthdays are distinct to \frac{1}{2} and solve for the number of students.

e^{− \frac{m^{2}}{2N}} ∼ \frac{1}{2}
e^{\frac{m^{2}}{2N}} ∼ 2
\frac{m^{2}}{2N} ∼ ln 2
m ∼ \sqrt{2N ln 2}
≈ 1.177\sqrt{N}
= Θ(\sqrt{N})

We are interested in values of m that are Θ(\sqrt{N}) = o(N^{\frac{2}{3}} ); therefore, our earlier assumption is justified and we can expect our approximation to be good!

For example, if N = 365, then 1.177\sqrt{N} = 22.49. This is consistent with out earlier calculation; we found that the probability that at least two students have the same birthday is \frac{1}{2} in a room with around 22 or 23 students!

Of course, one has to be careful with the ∼ notation; we may end up with an approximation that is only good for very large values. In this case, though, our approximation works well for reasonable values!

7.4 The Birthday Principle

The preceding result is called the Birthday Principle. It can be interpreted this way: if you throw about \sqrt{N} balls into N boxes, then there is about a 50% chance that some box gets two balls.

For example, in 27 years there are about 10,000 days. If we put about 1.177\sqrt{10, 000} ≈ 118 people under the age of 28 in a room, then there is a 50% chance that at least two were born on exactly the same day of the same year!

As another example, suppose we have a roomful of people. Each person writes a random number between 1 and a million on a piece of paper. Even if there are only about 1.177\sqrt{1, 000, 000} = 1177 people in the room, then there is a 50% chance that two wrote exactly the same number!

8 Derangements

A derangement is a permutation of 1, 2, …, n where i is not in the i^{th} position. E.g. the number of ways of addressing n envelopes to n people so that all the envelopes are mailed to wrong addresses. Let us represent the number of derangements on n elements as !n.

The question we would like to answer is: Given that all permutations are equally likely, i.e., we have a uniform sample space, what is the probability that two randomly shuffled decks of cards are such that the permutation of cards in one deck is a derangement of the other?

To do this, we will compute the number of derangements using Inclusion-Exclusion and use Theorem 2.1.

Theorem 8.1

!n = n! ∑_{k=0}^{n} \frac{(−1)^{k}}{k!}

Proof. Let A_{1} be the set of permutations where the element 1 is mapped to position 1. Similarly let A_{i} for i = 1, …, n be the set of permutations of 1, …, n where i is mapped to the i^{th} position. Then the set of permutations that are not derangements is

A_{1} ∪ … ∪ A_{n}

and the number of such permutations is

|A_{1} ∪ … ∪ A_{n}| = ∑_{k=1}^{n}(−1)^{k+1} ( ∑_{S⊆{1,... ,n},|S|=k} | ⋂_{i∈S} A_{i}|)

In order to evaluate the Inclusion-Exclusion formula, we note that for any set S ⊂ {1, …, n} such that |S| = k we have

| ⋂_{i∈S} A_{i}| = (n − k)!

since a permutation in ⋂_{i∈S} A_{i} is a permutation that fixes the elements of S and permutes in an arbitrary way the other n − k elements. There are (n − k)! ways to choose such a permutation. Considering that for any k there are \binom{n}{k} sets S of size k, the sum evaluates to

∑_{k=1}^{n}(−1)^{k+1}\binom{n}{k}(n − k)! = ∑_{k=1}^{n}(−1)^{k+1} \frac{n!}{(n − k)!k!}(n − k)!

= ∑_{k=1}^{n}(−1)^{k+1} \frac{n!}{k!}

Since this gives us the number of permutations that are not derangements, by subtracting this value from n! we find the number of derangements:

!n = n! − ∑_{k=1}^{n}(−1)^{k+1} \frac{n!}{k!}

= n! (1 + ∑_{k=1}^{n}(−1)^{k} \frac{1}{k!})

= n! ∑_{k=0}^{n}(−1)^{k} \frac{1}{k!}

The Taylor expansion of e^{x} is

e^{x} = 1 + x + \frac{x^{2}}{2!} + \frac{x^{3}}{3!} + …

That is,

e^{x} = ∑_{k=0}^{∞} \frac{x^{k}}{k!}

For x = −1, we have

e^{−1} = 1/e = ∑_{k=0}^{∞} \frac{(−1)^{k}}{k!}

This looks very close to our formula for derangements which is n! times the first n + 1 terms in this expansion. In fact, we can observe that the number of derangements is the nearest integer to n!/e. To see this, consider the difference n!/e−!n.

n!/e−!n = n! ( ∑_{k=n+1}^{∞} \frac{(−1)^{k}}{k!} )

= (−1)^{n+1} (\frac{1}{n + 1} − \frac{1}{(n + 1)(n + 2)} + … + \frac{(−1)^{k+1}}{(n + 1)(n + 2) … (n + k)} + …)

So for n ≥ 1,

|n!/e−!n| = \frac{1}{n + 1} − \frac{1}{(n + 1)(n + 2)} + … + \frac{(−1)^{k+1}}{(n + 1)(n + 2) … (n + k)} + …

≤ \frac{1}{2} − \frac{1}{2.3} + … + \frac{(−1)^{k+1}}{(k + 1)!} = 1/e

The last inequality can be observed by grouping the terms of the summation into pairs (the first two, next two and so on) and then comparing. The difference between n!/e and !n is at most 1/e < 1/2, so the number of derangements must be the integer closest to n!/e.

Therefore, we have the probability of one deck’s order being a derangement of the other to be 1/e.