Advanced level

Combinatorics

The art of counting without listing. The rule of product, factorials, permutations, arrangements and combinations all answer one question — in how many ways can this be done — and the whole difficulty comes down to two decisions: does order matter, and may items repeat.

Before you start

This topic builds on earlier ideas. Before you start, it's worth working through the lessons below — they'll make everything click:

Where this is used

Real situations where you count exactly the way this lesson teaches:

  • How strong a password is
    A four-digit PIN is 10⁴ = 10,000 possibilities — a phone locks after three attempts, but a stolen database of such codes falls in a fraction of a second. Eight lower-case letters give 26⁸ ≈ 209 billion combinations, and eight characters drawn from 62 (lower case, upper case, digits) give 62⁸ ≈ 218 trillion, over a thousand times as many. Every character you add multiplies that count by the size of the alphabet rather than adding to it.
  • Planning a delivery round
    Eight addresses can be visited in 8! = 40,320 different orders; add two more and there are 10! = 3,628,800, ninety times as many. That is why routing software hunts for a good round rather than the best one — the factorial itself says at which point going through the options one by one stops being feasible.
  • Drawing up a season
    In a sixteen-team league everyone plays everyone once per round: C(16, 2) = 120 fixtures, or 240 across two rounds. Eight matches to a matchday makes 30 matchdays, so before a single fixture is drawn you know how many weekends the season has to fill and how many refereeing teams have to be rostered.
  • Putting a project team together
    Three people out of ten can be picked in C(10, 3) = 120 ways. Once the roles differ — lead, analyst, tester — order counts and there are 10 · 9 · 8 = 720 options, six times as many, because every trio can be assigned in 3! = 6 ways. The same distinction settles whether a recruiter is discussing who is on the team or who does what on it.
  • Where compound interest comes from
    Ten years at 5% a year multiply the capital by (1 + 0.05)¹⁰ ≈ 1.6289. The binomial theorem splits that number into parts: the 1 is the capital, 10 · 0.05 = 0.5 is simple interest on its own, and C(10, 2) · 0.05² = 0.1125 is interest on interest — the first term a simple-interest calculation cannot see at all. The remaining terms (0.015 and 0.0013) add the rest. That is why at low rates the gap between simple and compound interest is small, and at high rates it grows quadratically.

All formulas

  • Rule of product

    N=k1k2kmN = k_1 \cdot k_2 \cdot \ldots \cdot k_m

    a choice made in several independent steps — multiply the counts

  • Factorial

    n!=123n,0!=1n! = 1 \cdot 2 \cdot 3 \cdot \ldots \cdot n, \qquad 0! = 1

    the product of the first n naturals; 0! equals 1 by definition

  • Permutations

    Pn=n!P_n = n!

    the number of orderings of all n items

  • Arrangements without repetition

    n!(nk)!=n(n1)(nk+1)\frac{n!}{(n-k)!} = n(n-1)\ldots(n-k+1)

    choose k out of n, order matters, nothing repeats

  • Arrangements with repetition

    nkn^k

    k times over, we choose from the same n options

  • Combinations

    (nk)=n!k!(nk)!\binom{n}{k} = \frac{n!}{k! \, (n-k)!}

    choose k out of n, order does NOT matter

  • Symmetry of combinations

    (nk)=(nnk)\binom{n}{k} = \binom{n}{n-k}

    choosing k items is the same as discarding the other n − k

  • Pascal's rule

    (nk)=(n1k1)+(n1k)\binom{n}{k} = \binom{n-1}{k-1} + \binom{n-1}{k}

    every entry of the triangle is the sum of the two above it

  • The binomial theorem

    (a+b)n=k=0n(nk)ankbk(a+b)^n = \sum_{k=0}^{n} \binom{n}{k} a^{n-k} b^k

    the coefficients of the expansion are row n of Pascal's triangle

Combinatorics answers the question "in how many ways?" before anyone can start listing cases. It is also a prerequisite for classical probability: to divide the number of favourable outcomes by the number of all of them, you first have to be able to count both.

The rule of product

All of combinatorics grows out of a single observation. If a choice is made in several independent steps offering k1,k2,,kmk_1, k_2, \ldots, k_m options, then the number of outcomes is:

N=k1k2kmN = k_1 \cdot k_2 \cdot \ldots \cdot k_m

The counts are multiplied, not added — because every decision in the first step can be paired with every decision in the second.

A restaurant offers 4 soups, 6 mains and 3 desserts. How many different three-course meals are there?

Factorials

The product of the first few naturals turns up so often in counting that it has its own symbol:

n!=123nn! = 1 \cdot 2 \cdot 3 \cdot \ldots \cdot n

It is read "n factorial". The first few values are worth knowing by heart:

nn01234567
n!n!1126241207205040

Mind the first column: 0!=10! = 1, by definition. An empty sequence can be arranged in exactly one way — by doing nothing — and besides, without that convention the combination formula would divide by zero.

012345670200400600800nn!12624120720n!
The first three bars are almost invisible at this scale. A factorial grows faster than any power — 10! is already over three and a half million.

That growth is a practical hint: if ten people can be ordered in 3,628,8003{,}628{,}800 ways, solving a problem by listing cases is out of the question.

Permutations

A permutation is an ordering of all nn items. The first position can be filled in nn ways, the second in n1n-1 (one item is already used), and so on:

Pn=n(n1)21=n!P_n = n \cdot (n-1) \cdot \ldots \cdot 2 \cdot 1 = n!
In how many ways can five people form a queue?

Arrangements without repetition

When only kk of the nn items are chosen but order matters, we are counting arrangements without repetition:

n!(nk)!=n(n1)(nk+1)\frac{n!}{(n-k)!} = n(n-1)\ldots(n-k+1)

The second form is the handier one to compute: it is simply kk decreasing factors starting at nn.

A club has 8 members. In how many ways can a chair, a secretary and a treasurer be chosen?

Arrangements with repetition

If items may repeat, each of the kk steps has the full nn options, so the rule of product gives directly:

nkn^k
How many four-digit PINs are there?

Combinations

When kk items are chosen out of nn and order does not matter, we have combinations:

(nk)=n!k!(nk)!\binom{n}{k} = \frac{n!}{k! \, (n-k)!}

Where does the k!k! in the denominator come from? From the fact that the arrangements counted every kk-element set k!k! times over — once for each ordering of the same items. So we divide by the number of those orderings:

(nk)=n!/(nk)!k!\binom{n}{k} = \frac{n!/(n-k)!}{k!}
In how many ways can a delegation of three be chosen out of 8 people?

Symmetry

Combinations have a property that saves a great deal of arithmetic:

(nk)=(nnk)\binom{n}{k} = \binom{n}{n-k}

Choosing kk items is, after all, the same as naming the nkn-k items left behind. So (2018)\binom{20}{18} is computed like (202)=190\binom{20}{2} = 190, rather than by writing out eighteen factors.

−10123456704812162024kC(6, k)1615201561C(6, k)
The counts of choices from a six-element set line up symmetrically: the outer bars are choosing nothing and choosing everything, and the tallest one stands exactly in the middle.

The bars add up to 64=2664 = 2^6 — the number of subsets of a six-element set, because every item is decided independently: take it or leave it.

Pascal's triangle

The symbols (nk)\binom{n}{k} for successive nn line up into a triangle in which not one factorial has to be computed. The rows are numbered from zero:

111121133114641151010511615201561\begin{array}{ccccccccccccc} & & & & & & 1 \\ & & & & & 1 & & 1 \\ & & & & 1 & & 2 & & 1 \\ & & & 1 & & 3 & & 3 & & 1 \\ & & 1 & & 4 & & 6 & & 4 & & 1 \\ & 1 & & 5 & & 10 & & 10 & & 5 & & 1 \\ 1 & & 6 & & 15 & & 20 & & 15 & & 6 & & 1 \end{array}

There is a single rule of construction: every row starts and ends with a 1, and every entry in between is the sum of the two above it. Written in symbols, that is the identity:

(nk)=(n1k1)+(n1k)\binom{n}{k} = \binom{n-1}{k-1} + \binom{n-1}{k}

Why does it hold? Single out one fixed item of the set — say the first. Every choice of kk items either takes it (leaving k1k-1 places to fill from the other n1n-1 items) or skips it (all kk places have to be filled from those n1n-1). The two cases do not overlap and cover everything, so the counts add up.

The triangle also displays two properties we already have, only this time as a picture. The symmetry (nk)=(nnk)\binom{n}{k} = \binom{n}{n-k} is the mirror image of a row about its middle. And the entries of row nn add up to 2n2^n — row six is exactly the 1,6,15,20,15,6,11, 6, 15, 20, 15, 6, 1 of the chart above, summing to 6464.

Write down the eighth row of Pascal's triangle (that is, row number 7).

The binomial theorem

The triangle is not a curiosity — it is the table of coefficients of a power of a sum. The binomial theorem states:

(a+b)n=k=0n(nk)ankbk(a+b)^n = \sum_{k=0}^{n} \binom{n}{k} a^{n-k} b^k

The justification is again a counting argument rather than an algebraic one. The power (a+b)n(a+b)^n is a product of nn identical brackets; multiplying them out, each bracket contributes either aa or bb. A term with bkb^k arises exactly when bb was taken from kk of the nn brackets — and there are (nk)\binom{n}{k} such choices. Hence the coefficient.

In practice nobody sums this symbolically; you read off row nn of the triangle. For n=4n = 4 that row is 1,4,6,4,11, 4, 6, 4, 1:

(a+b)4=a4+4a3b+6a2b2+4ab3+b4(a+b)^4 = a^4 + 4a^3b + 6a^2b^2 + 4ab^3 + b^4

Note the two independent rhythms: the exponent of aa falls from nn to zero, the exponent of bb rises from zero to nn, and in every term the two add up to nn. That is the fastest check on an expansion. The special products for (a+b)2(a+b)^2 and (a+b)3(a+b)^3 are simply rows two and three of this same triangle.

Expand (x + 2)⁵ and give the coefficient of x³.

Which formula to use

The whole difficulty comes down to two questions about the problem:

does order matter?may items repeat?formula
yes, all items are usedn!n!
yes, kk out of nnnon!(nk)!\dfrac{n!}{(n-k)!}
yes, kk out of nnyesnkn^k
no, kk out of nnno(nk)\dbinom{n}{k}

A practical test for the first question: swap two of the chosen items. If that gives a different situation, order matters.

Exercises

The five kinds of question match the five formulas in the table above — Pascal's triangle and the binomial theorem are practised on the worked examples of those sections, because the generator here asks for a number of ways, not for a row or a coefficient. A prompt with an exclamation mark asks straight for a factorial — mind 0!=10! = 1. Permutations for a given nn is also n!n!, only phrased in words. Arrangements without repetition and arrangements with repetition both come with nn and kk; they differ only in whether items may be taken more than once. Combinations ask for a choice of kk out of nn with order ignored — and here the symmetry is worth remembering. Every answer is a whole number.

Practice

Work through a set of exercises — they get harder as you go. At the end you'll see your score and the mistakes worth reviewing.

Exercise 1 of 8Score: 0
3! =

Common mistakes

  • Adding instead of multiplying — successive steps of a choice multiply the counts.
  • Confusing arrangements with combinations — if order does not matter, the result still has to be divided by k!k!.
  • Forgetting 0!=10! = 1 — especially in the edge cases of the combination formula.
  • Cancelling factorials by eye8!5!\tfrac{8!}{5!} is 8768 \cdot 7 \cdot 6, not 85\tfrac{8}{5} and not 3!3!.
  • Assuming repetition — whether items may repeat is decided by the problem, not by which formula is more convenient.
  • Listing the cases — beyond n=5n = 5 there are usually far too many to get through without a slip.
  • Counting a row from one — row nn has n+1n+1 entries and they are numbered from zero, so (52)\binom{5}{2} is the third entry of row five, not the second.
  • The bare coefficient instead of the whole term — in the expansion of (x+2)5(x+2)^5 the coefficient of x3x^3 is (52)22=40\binom{5}{2} \cdot 2^2 = 40, not (52)=10\binom{5}{2} = 10: it is the whole 2 that is raised to a power, not just the xx.

Formula card

Topic: Combinatorics

  • Rule of product

    N=k1k2kmN = k_1 \cdot k_2 \cdot \ldots \cdot k_m

    a choice made in several independent steps — multiply the counts

  • Factorial

    n!=123n,0!=1n! = 1 \cdot 2 \cdot 3 \cdot \ldots \cdot n, \qquad 0! = 1

    the product of the first n naturals; 0! equals 1 by definition

  • Permutations

    Pn=n!P_n = n!

    the number of orderings of all n items

  • Arrangements without repetition

    n!(nk)!=n(n1)(nk+1)\frac{n!}{(n-k)!} = n(n-1)\ldots(n-k+1)

    choose k out of n, order matters, nothing repeats

  • Arrangements with repetition

    nkn^k

    k times over, we choose from the same n options

  • Combinations

    (nk)=n!k!(nk)!\binom{n}{k} = \frac{n!}{k! \, (n-k)!}

    choose k out of n, order does NOT matter

  • Symmetry of combinations

    (nk)=(nnk)\binom{n}{k} = \binom{n}{n-k}

    choosing k items is the same as discarding the other n − k

  • Pascal's rule

    (nk)=(n1k1)+(n1k)\binom{n}{k} = \binom{n-1}{k-1} + \binom{n-1}{k}

    every entry of the triangle is the sum of the two above it

  • The binomial theorem

    (a+b)n=k=0n(nk)ankbk(a+b)^n = \sum_{k=0}^{n} \binom{n}{k} a^{n-k} b^k

    the coefficients of the expansion are row n of Pascal's triangle

012345670200400600800nn!12624120720n!
Factorials for n from 1 to 6. At this scale the first three bars are practically invisible — 6! is already a hundred and twenty times 3!. This is what combinatorial growth looks like.
−10123456704812162024kC(6, k)1615201561C(6, k)
The number of ways of choosing k items out of six. The picture is symmetric, because choosing k items is the same as discarding the other 6 − k; picking half the set gives the most options.

Frequently asked questions

Related articles