Factorial, combination and permutation
These three operations form the basis of combinatorics. The factorial (n!) is the product of all positive integers up to n. The combination C(n,r) counts how many different groups of r elements can be formed from n, regardless of order. The permutation P(n,r) counts the same, but taking order into account.
Formulas
| Operation | Formula |
|---|---|
| Factorial | n! = n × (n−1) × ... × 1 |
| Combination | C(n,r) = n! / (r! × (n−r)!) |
| Permutation | P(n,r) = n! / (n−r)! |
Examples
5! = 120. C(5,2) = 5!/(2!×3!) = 10 (choose 2 of 5, order does not matter). P(5,2) = 5!/3! = 20 (choose and order 2 of 5).
When to use each
Use combination when order does not matter (e.g. choosing 3 people for a committee). Use permutation when order matters (e.g. deciding the podium of a race — 1st, 2nd and 3rd place).
Reading the numbers
P(10,3) = 10 × 9 × 8 = 720 ways to award gold, silver and bronze among ten runners, while C(10,3) = 120 ways to simply pick three of them, since each trio can be ordered 3! = 6 ways. Symmetry helps: C(10,8) equals C(10,2) = 45. Browsers use double-precision numbers, so only the first 15 or 16 digits of a huge result are reliable.
Edge cases are easy to remember: C(n,0) = 1 because there is exactly one way to pick nothing, and C(n,n) = 1 because there is one way to pick everything.
Frequently asked questions
What's the difference between combination and permutation?
In a combination the order of chosen elements does not matter; in a permutation it does — so P(n,r) is always greater than or equal to C(n,r).
Why is n capped at 170?
Above that, the factorial exceeds the largest number a browser can represent (171! would already be infinity).
What is 0!?
By mathematical definition, 0! = 1.
Can r be greater than n?
No — you cannot choose more elements than exist in the original set.