Deranged Mathematics

Reading Time: 6 minutes

I had a strange mathematical experience during my first year of teaching high school math. I gave my students a typical matching exercise to complete, like the one you see below.

ItemTermDefinition
AVariableA relationship with a constant rate of change, forming a straight line graph.
BCoefficientA mathematical statement showing that two expressions are equal.
CLinear RelationshipThe amount of space inside a 2D shape, measured in square units.
DConstantA symbol (usually a letter) used to represent an unknown number or value.
EEquationThe point where a line crosses the y-axis (when x = 0).
FSlopeThe average of a set of numbers, found by dividing the sum by how many there are.
GY-interceptA number from 0 to 1 that shows how likely an event is to happen.
HAreaA number multiplied by a variable in an algebraic expression (e.g., 3 in 3x).
IMeanThe steepness of a line, calculated as rise over run (change in y over x).
JProbabilityA value that does not change in an expression or equation.

It surprised me how much my students struggled on questions like these. A few students even managed to get zero correct matches! I was baffled. I thought that even a student who completely guesses at random is unlikely get zero right answers. Since I hold a statistics degree and teach statistics at my school, I set out to answer the following question.

What is the probability of getting zero right answers on a matching question with n items?

Drawing It Out

Let’s consider a question with three items only.

ItemTermDefinition
AVariableA relationship with a constant rate of change, forming a straight line graph.
BCoefficientA symbol (usually a letter) used to represent an unknown number or value.
CLinear RelationshipA number multiplied by a variable in an algebraic expression (e.g., 3 in 3x).

There are six possible ways of matching the terms and definitions above. There are three options for the first term, two options for the second and one for the last term. Drawing the possibility tree is the best way to visualize all the arrangements.

    \[3\times 2 \times 1 = 6\]

We can see that, in general, if we had n items, we’d have n \cdot (n-1) \cdot (n-2) \cdot ... \cdot 2 \cdot 1 arrangements. Mathematicians came up with the factorial notation n! to represent this concept.

The six arrangements are ABC, ACB, BAC, BCA, CAB, and CBA. The right answers are plotted in green, and the number of correct answers for each arrangement is indicated below each branch. We see that there’s only one way to get all the right answers. Additionally, it’s impossible to get n-1 correct answers because the last option will be good if all the others were correct.

# of Correct Answers# of ArrangementsProbability
0233%
1350%
200%
3117%
TOTAL6100%

What is the probability of getting zero right answers on a matching question with 3 items?

Sometimes the best way to answer a difficult question is to start by answering similar, but simpler one. We see that, when guessing at random, the probability of getting zero right answers on a matching question with 3 items is \frac{2}{6} = \frac{1}{3} \approx 33%.

Let’s repeat this process for four items to build our intuition.

There are now 4! = 4 \times 3 \times 2 \times 1 = 24 possible ways of arranging four items.

# of Correct Answers# of ArrangementsProbability
0938%
1833%
2625%
300%
414%
TOTAL24100%

We see that there is still only one way to get all the correct answers. The probability of getting zero right answers moved from 33% to 38%.

The factorial function grows fast. Ten factorial is over three million.

nn!
11
22
36
424
5120
6720
75,040
840,320
9365,880
103,628,800

For this reason, we’ll only plot the tree with five items. We’ll use computer programming to determine the probability for larger values of n.

# of Correct Answers# of ArrangementsProbability
04437%
14538%
22017%
3108%
400%
511%
TOTAL120100%

Surprisingly, the probability of getting zero right answers barely moved. It appears to approach a certain value as n increases. This is the result for larger numbers of items.

n# of Arrangementsn!Probability
21250%
32633.3%
492437.5%
54412036.7%
626572036.8%
718545,04036.8%
81483340,32036.8%
9133496365,88036.8%
1013349613,628,80036.8%

The probability seems to stabilize around 0.368. I find it easier to see what is going on by plotting the numbers in the table.

Something special happens when things converge to a specific number in mathematics. The first special number I could think of was \pi \approx 3.14. Unfortunately, this is nowhere near our value of 0.368. So I had the idea of dividing one by Pi, which gave me 0.318. So close but not close enough.

Another famous constant in mathematics is Euler’s number e \approx 2.718. Again, dividing one by e gives us… drum roll… 0.368!!!!!!!!!!!!!!!

Note: The exclamation marks above are not factorials. 😋

This was one of the most awe-inspiring moments of my mathematical career. I set out to calculate a probability about my students, and then e shows up seemingly out of nowhere. I felt like how the ancient mathematicians must have felt when they discovered that the ratio of a circle’s circumference to its diameter is the same number for all circles.

Mathematical Proof

It’s cool that we were able to use computers and intuition to show that the probability of getting no correct answers approaches \frac{1}{e} as the number of questions increases. However, ideally, we’d show mathematically that

    \[\lim_{n \to \infty} \frac{D_n}{n!} = \frac{1}{e}\]

where D_n is the number of ways to get zero right answers and n is the number of items. To do so, we need to determine the mathematical function D_n that relates the number of items n and the number of ways it’s possible to get zero correct answers.

n# of Arrangements (D_n)
21
32
49
544
6265
71854
814833
9133496
101334961

The function is

    \[D_n = n! \sum_{k=0}^n \frac{(-1)^k}{k!}\]

It turns out this formula has a name. D_n represents the number of derangements and is sometimes denoted as !n.

A derangement is a permutation of the elements of a set in which no element appears in its original position.

Wikipedia

Let’s try a few values of n.

    \[D_2 = 2! \sum_{k=0}^2 \frac{(-1)^k}{k!} = (2 \times 1) \times \left[\frac{(-1)^0}{0!} + \frac{(-1)^1}{1!} + \frac{(-1)^2}{2!} \right] = 2 \times \left[1 + -1 + \frac{1}{2} \right]\]

    \[D_3 = 3! \sum_{k=0}^3 \frac{(-1)^k}{k!} = (3 \times 2 \times 1) \times \left[\frac{(-1)^0}{0!} + \frac{(-1)^1}{1!} + \frac{(-1)^2}{2!} + \frac{(-1)^3}{3!} \right] = 6 \times \left[1 + -1 + \frac{1}{2} + \frac{-1}{6} \right] = 6 \times \left[ \frac{3}{6} - \frac{1}{6} \right] = 2\]

    \[D_5 = 5! \sum_{k=0}^5 \frac{(-1)^k}{k!} = 120 \times \left[\frac{1}{3} + \frac{(-1)^4}{4!} + \frac{(-1)^5}{5!} \right] = 120 \times \left[\frac{1}{3} + \frac{1}{24} + \frac{-1}{120} \right] = 120 \times \left[\frac{44}{120} \right] = 44\]

Nice! We’ve shown that D_n = n! \sum_{k=0}^n \frac{(-1)^k}{k!} (at least for three examples).

Let’s substitute this function into our initial equation.

    \[\lim_{n \to \infty} \frac{D_n}{n!} = \lim_{n \to \infty} \frac{n! \sum_{k=0}^n \frac{(-1)^k}{k!}}{n!}\]

Cancelling out the n! on the top and bottom gives us:

    \[\lim_{n \to \infty} \frac{D_n}{n!} = \lim_{n \to \infty} \sum_{k=0}^n \frac{(-1)^k}{k!}\]

Thus, we need to show that \lim_{n \to \infty} \sum_{k=0}^n \frac{(-1)^k}{k!} = \frac{1}{e}.

Let’s start by showing something simpler first. Consider the following table where the last column is the cumulative sum of \frac{1}{n!}.

nn!1 / n!Cumulative Sum
0111
1112
220.52.5
360.1672.667
4240.0422.708
51200.0082.717
67200.0012.718
75,0400.0002.718
840,3200.0002.718
9365,8800.0002.718
103,628,8000.0002.718

We see that the values in the last column approach Euler’s number e \approx 2.718. We can express this fact mathematically as :

    \[e = \sum_{k=0}^{\infty} \frac{1}{k!} \approx 2.718\]

This is a special case of the Taylor series for e^x where

    \[e^x = \sum_{k=0}^{\infty} \frac{x^k}{k!}\]

Substituting x = 1 gives us the result above that e = \sum_{k=0}^{\infty} \frac{1}{k!} \approx 2.718. However, substituting x = -1 gives us

    \[e^{-1} = \frac{1}{e} = \sum_{k=0}^{\infty} \frac{(-1)^k}{k!}\]

Thus, we have shown that \lim_{n \to \infty} \sum_{k=0}^n \frac{(-1)^k}{k!} = \frac{1}{e}.


The theory of derangements can be applied to the gift exchange custom of Secret Santa. The probability that no one picks their own name approaches \frac{1}{e} as the number of people increases. As we’ve seen, it only takes about five people for the probability to be very close to the magic number of 0.368.

Read This Next

Recent Articles