What is a Factorial?
The factorial of a non-negative integer n, written as n!, is the product of all positive integers from 1 to n. Factorials are widely used in permutations, combinations, and probability.
5! = 5 × 4 × 3 × 2 × 1 = 120
Factorial Table
Complete Factorial Table (0! to 20!)
| n | n! (Factorial) | n | n! (Factorial) |
|---|---|---|---|
| 0! | 1 | 11! | 39,916,800 |
| 1! | 1 | 12! | 479,001,600 |
| 2! | 2 | 13! | 6,227,020,800 |
| 3! | 6 | 14! | 87,178,291,200 |
| 4! | 24 | 15! | 1,307,674,368,000 |
| 5! | 120 | 16! | 20,922,789,888,000 |
| 6! | 720 | 17! | 355,687,428,096,000 |
| 7! | 5,040 | 18! | 6,402,373,705,728,000 |
| 8! | 40,320 | 19! | 121,645,100,408,832,000 |
| 9! | 362,880 | 20! | 2,432,902,008,176,640,000 |
| 10! | 3,628,800 | — | — |
Factorial in Permutations and Combinations
Factorials are the building block of combinatorics — the mathematics of counting arrangements and selections.
Combinations C(n,r) = n! / [r! × (n−r)!]
Arrangements of n distinct objects = n!
Example: 5 books on a shelf = 5! = 120 arrangements
Stirling's Approximation for Large Factorials
For very large n, Stirling's approximation provides a fast estimate:
100! ≈ 9.332 × 10¹⁵⁷ (a 158-digit number!)
Real-World Applications
- Card games: A deck of 52 cards can be arranged in 52! ≈ 8×10⁶⁷ ways — more than the number of atoms in the observable universe
- Password security: An 8-character password from 26 letters = 26⁸ ≈ 200 billion combinations
- Genetics: Counting possible DNA sequences and gene arrangements
- Probability: Calculating odds in games of chance, lottery combinations
- Computer science: Algorithm complexity analysis — O(n!) algorithms are extremely slow
Factorial Growth — How Fast Numbers Explode
Factorials grow incredibly fast — faster than exponential functions. This is called super-exponential growth:
| n | 2ⁿ (exponential) | n! (factorial) | Ratio n!/2ⁿ |
|---|---|---|---|
| 5 | 32 | 120 | 3.75× |
| 10 | 1,024 | 3,628,800 | 3,543× |
| 15 | 32,768 | 1.307×10¹² | 39,900,000× |
| 20 | 1,048,576 | 2.432×10¹⁸ | 2.3 trillion× |
Why n! Matters in Computer Science
An algorithm with O(n!) time complexity is one of the slowest possible. For n=20, it requires over 2 quadrillion operations. The famous Travelling Salesman Problem (finding the shortest route visiting n cities) has n! possible routes — making brute force solutions impossible for large n.