Factorial and Permutations

The factorial n! is the product 1 · 2 · 3 ⋯ n, and it counts the permutations of n distinct objects, that is, the number of ways to arrange them in a row. In brief: 5! = 120, so 5 books can be arranged on a shelf in 120 ways. With repeated objects, the count is smaller: the letters of MISSISSIPPI can be arranged in 11!/(4! 4! 2!) = 34,650 ways. By convention 0! = 1.

A permutation is an ordered arrangement. Factorials grow extremely fast: 10! is already 3,628,800, and 20! is about 2.4 × 1018. This guide defines the factorial, derives the permutation count, handles repeated objects, circular arrangements and arrangements with conditions, introduces derangements and gives a table of factorials from 0! to 12!.

What is a factorial?

For a positive integer n, n! = n(n − 1)(n − 2)⋯2 · 1. It satisfies the recursion n! = n · (n − 1)!, so 6! = 6 · 120 = 720. Defining 0! = 1 keeps the recursion working (1! = 1 · 0!) and makes the formulas for combinations correct. Useful simplification: 8!/6! = 8 · 7 = 56, because the common factors cancel.

The factorial also extends to non-integers by the gamma function, with Γ(n + 1) = n!, for example (1/2)! = √π/2 ≈ 0.886, but this belongs to advanced mathematics.

How many permutations of n objects are there?

There are n choices for the first position, n − 1 for the second, and so on down to 1 for the last. By the multiplication principle, the number of arrangements is n · (n − 1) ⋯ 1 = n!.

Example 1

The letters of the word MATH can be arranged in 4! = 24 ways. Seven runners can finish a race (no ties) in 7! = 5,040 different orders. A deck of 52 cards can be shuffled in 52! ≈ 8.07 × 1067 ways, more than the number of atoms on Earth, so a well-shuffled deck is almost certainly in an order never seen before.

Example 2: simplifying

(n + 2)!/n! = (n + 2)(n + 1). For n = 5: 7!/5! = 42. And 10!/(7! · 3!) = (10 · 9 · 8)/6 = 120.

Example 3: solving an equation

Solve (n + 1)!/(n − 1)! = 30. The left side is (n + 1)n, so n2 + n − 30 = 0, and (n + 6)(n − 5) = 0. Since n is positive, n = 5. Check: 6!/4! = 30 ✓.

What if some objects are identical?

If among n objects there are n1 of one kind, n2 of another, …, nk of the last kind, the number of distinguishable arrangements is n!/(n1! n2! ⋯ nk!). Swapping identical objects does not give a new arrangement, so the n! count is divided by the numbers of swaps within each group.

Example 4: MISSISSIPPI

The word has 11 letters: M once, I four times, S four times, P twice. The number of arrangements is 11!/(1! 4! 4! 2!) = 39,916,800/(24 · 24 · 2) = 39,916,800/1,152 = 34,650.

Example 5: ALABAMA

7 letters with A four times, L, B and M once each: 7!/4! = 5,040/24 = 210.

Example 6: paths on a grid

The number of shortest paths from the lower-left to the upper-right corner of a 3 by 2 grid (3 steps right and 2 steps up) is the number of arrangements of RRRUU: 5!/(3! 2!) = 10.

5!/(3!·2!)=10

How do you count circular arrangements?

For n distinct people around a round table, rotations of the same seating are the same arrangement. Fix one person’s position; the other n − 1 people can be arranged in (n − 1)! ways. For 6 people at a round table: 5! = 120 seatings. If the table can also be flipped (like beads on a bracelet), the count for n ≥ 3 is halved: (n − 1)!/2, so a bracelet of 6 different beads has 60 distinct designs.

How do you count arrangements with conditions?

Example 7: two people together

Five friends sit in a row, with A and B next to each other. Treat AB as a single block: 4 objects can be arranged in 4! = 24 ways, and the block can be AB or BA, so 2 · 24 = 48 arrangements. Without the condition: 120. So the two are next to each other in 48/120 = 40% of the arrangements.

Example 8: two people apart

By complementary counting, the number of arrangements with A and B not adjacent is 120 − 48 = 72.

Example 9: vowels together

How many arrangements of the letters of PARTIAL have the vowels together? The vowels are A, I, A (3 letters, with A repeated): arranged in 3!/2! = 3 ways. The consonants P, R, T, L (4 distinct) plus the block of vowels make 5 objects: 5! = 120. The total is 120 · 3 = 360.

Example 10: derangements

A derangement is a permutation with no object in its original position. The number Dn of derangements: D2 = 1, D3 = 2, D4 = 9, D5 = 44, D6 = 265. The formula is Dn = n! (1 − 1/1! + 1/2! − … + (−1)n/n!), approximately n!/e. If 5 people hand their coats back at random, the probability that nobody gets their own coat is 44/120 ≈ 36.7%.

Table of factorials

Factorials n! for n from 0 to 12
n n! n n!
0175,040
11840,320
229362,880
36103,628,800
4241139,916,800
512012479,001,600
6720––

Where does the factorial come from?

The counting of permutations is old: Indian texts such as the Jain Bhagavati Sutra and the work of Bhaskara II discuss the number of arrangements, and Hebrew and Arabic scholars counted the permutations of letters in connection with the study of the names of God and with cryptography. The notation n! was introduced by Christian Kramp in 1808, and the exclamation mark was chosen for typographical convenience.

Where is it used today?

Factorials appear in probability (the number of orderings), in the Taylor series of ex (terms xn/n!), in the analysis of algorithms (the brute-force solution of the travelling salesman problem tries (n − 1)!/2 routes: for 15 cities more than 43 billion) and in statistical mechanics. The growth of n! is why exhaustive search is impractical for even moderately large problems.

Which mistakes are common?

Thinking 0! = 0

0! = 1. There is exactly one way to arrange nothing.

Cancelling factorials incorrectly

(n + 2)!/n! is (n + 2)(n + 1), not n + 2. And (2n)! is not 2 · n!.

Forgetting to divide for identical objects

MISSISSIPPI does not have 11! arrangements. Divide by the factorials of the counts of each repeated letter.

Using n! for a circular arrangement

Rotations are equivalent, so use (n − 1)!.