Search

Search papers and lessons

Counting Principles

Level 1 · 9 min read

Counting principles turn a question about how many outcomes exist into arithmetic: multiply the choices at each stage, and divide out the orderings you do not care about.

On this page

TL;DR

Counting principles are the rules for answering "how many ways can this happen?" without listing every way. If a task has several stages and each stage has a fixed number of choices, multiply those numbers. If the order of choices does not matter, divide by the number of ways to reorder them. Almost every counting problem is one of these two moves, applied with care.

Where you'll see it: in computing the chance of a poker hand, in estimating how many passwords an attacker must try, in the coefficients of a polynomial expansion, and in the probability formulas used throughout Probability.

Intuition

A menu with two courses

Suppose a cafe offers 3 soups and 4 sandwiches, and you order one soup and one sandwich. How many meals are possible? Pick a soup (3 ways). For each soup, pick a sandwich (4 ways). Each of the 3 soups pairs with each of the 4 sandwiches, so there are 3×4=123 \times 4 = 12 meals. You never wrote the 12 pairs out. You only needed to know how many choices each stage had.

That is the whole idea of counting. We cannot always list the outcomes, because there may be billions of them. But if the structure is clear, we can count them by thinking about the stages.

Why order sometimes matters and sometimes does not

Now suppose three friends want to share a pizza, and you must choose two of them to wash the dishes. Choosing Ana then Ben is the same job as choosing Ben then Ana. Here order does not change the outcome. A different situation is a podium: gold, silver and bronze go to different people, so Ana-Ben-Cy is a different result from Cy-Ben-Ana. The first kind of selection is a combination, the second is a permutation. Most mistakes in counting come from using the wrong one.

flowchart TD
  A[Selecting k items from n] --> B{Does order matter?}
  B -->|Yes| C{Can an item repeat?}
  B -->|No| D{Can an item repeat?}
  C -->|No| E[Permutations: n times n-1 and so on]
  C -->|Yes| F[n to the power k]
  D -->|No| G[Combinations: n choose k]
  D -->|Yes| H[Multisets: a different formula]

The math

The multiplication principle

If a procedure has kk stages, and stage ii can be done in nin_i ways regardless of what happened earlier, then the whole procedure can be done in

n1×n2×⋯×nkn_1 \times n_2 \times \cdots \times n_k

ways. The phrase "regardless of what happened earlier" matters. If the choices at a later stage depend on earlier ones, you must count each branch separately.

The addition principle

If a choice is one of two or more disjoint options, add the counts. Choosing a starter from 4 soups or a dessert from 3 cakes gives 4+3=74 + 3 = 7 options for a single course. "Disjoint" means no option is also counted in another. When options overlap, you must subtract the overlap, which leads to set union and the inclusion-exclusion formula.

Factorials

The number of ways to arrange nn distinct objects in a line is

n!=n×(n−1)×⋯×2×1,n! = n \times (n-1) \times \cdots \times 2 \times 1,

read "nn factorial". By convention 0!=10! = 1. The reason is the multiplication principle: the first position has nn choices, the second has n−1n-1 remaining, and so on until one object is left for the last spot.

Permutations

An ordered selection of kk objects from nn distinct objects, with no repeats, is a permutation. The count is

P(n,k)=n!(n−k)!=n×(n−1)×⋯×(n−k+1).P(n, k) = \frac{n!}{(n-k)!} = n \times (n-1) \times \cdots \times (n-k+1).

The first form says: take all n!n! orderings, then discard the orderings of the n−kn-k objects you did not pick. The second form is the one you compute by hand, with exactly kk factors.

Combinations

An unordered selection of kk objects from nn is a combination. Each combination of kk items can be arranged in k!k! ways, and each of those arrangements is a permutation. So the number of combinations is the number of permutations divided by k!k!:

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

This is read "nn choose kk", and it is called the binomial coefficient. It counts subsets: the number of ways to choose a kk-element subset of an nn-element set. A useful fact is the symmetry (nk)=(nn−k)\binom{n}{k} = \binom{n}{n-k}, because choosing who goes in a committee is the same as choosing who stays out.

Pascal's rule

The binomial coefficients satisfy

(nk)=(n−1k−1)+(n−1k).\binom{n}{k} = \binom{n-1}{k-1} + \binom{n-1}{k}.

To see why, fix one particular object. Either it is in the chosen subset, leaving k−1k-1 spots for the other n−1n-1 objects, or it is not, leaving kk spots. Arranging these values in rows gives Pascal's triangle, where each entry is the sum of the two above it.

Worked examples

Example
Passwords and repeats

A four-digit PIN uses the digits 0 through 9.

  1. Repeats allowed: each of the 4 positions has 10 choices, so 10×10×10×10=10,00010 \times 10 \times 10 \times 10 = 10{,}000 PINs.
  2. No repeats: the first digit has 10 choices, the second 9, the third 8, the fourth 7. So 10×9×8×7=5,04010 \times 9 \times 8 \times 7 = 5{,}040.
  3. The restriction removes half of the PINs (5,0405{,}040 of 10,00010{,}000), so a rule forbidding repeats actually makes guessing easier for an attacker, not harder: there are only half as many codes to try.
Example
A podium and a committee

Eight runners finish a race. Two different questions use the same eight people.

Question 1: how many ways can gold, silver and bronze be awarded?

  1. Order matters, and no one can win two medals. This is P(8,3)P(8, 3).
  2. P(8,3)=8!5!=8×7×6=336P(8,3) = \dfrac{8!}{5!} = 8 \times 7 \times 6 = 336.

Question 2: how many ways can three people be chosen for a relay team, with no roles?

  1. Order does not matter. This is (83)\binom{8}{3}.
  2. (83)=8×7×63!=3366=56\binom{8}{3} = \dfrac{8 \times 7 \times 6}{3!} = \dfrac{336}{6} = 56.
  3. Each team of 3 appears 3!=63! = 6 times in the 336 podiums, which is exactly the factor that divides out.
Example
A poker hand as a probability

A standard deck has 52 cards, 4 of them aces. A five-card hand is dealt at random. What is the chance it contains exactly two aces?

  1. Total hands: (525)=52×51×50×49×485!=2,598,960\binom{52}{5} = \dfrac{52 \times 51 \times 50 \times 49 \times 48}{5!} = 2{,}598{,}960.
  2. Choose which 2 aces: (42)=6\binom{4}{2} = 6.
  3. Choose the other 3 cards from the 48 non-aces: (483)=48×47×463!=17,296\binom{48}{3} = \dfrac{48 \times 47 \times 46}{3!} = 17{,}296.
  4. Favourable hands: 6×17,296=103,7766 \times 17{,}296 = 103{,}776.
  5. Probability: 103,776/2,598,960≈0.040103{,}776 / 2{,}598{,}960 \approx 0.040, about 4%.

The hand is counted without order, so the combinations formula is the right tool. Using permutations here would overcount each hand by 5!5!.

Tradeoffs and failure modes

Counting is simple to state and easy to get wrong. The errors are almost always about structure, not arithmetic.

SituationCommon mistakeBetter approach
Order does not matter, but you use permutationsEach set is counted k!k! timesDivide by k!k!, or use combinations
Choices at a later stage depend on earlier onesMultiplying fixed countsCount each branch, or condition on the first choice
Options overlapAdding counts and double-counting the overlapSubtract the overlap, or use inclusion-exclusion
Items may repeatUsing P(n,k)P(n,k)Use nkn^k for ordered repeats, or the multiset formula for unordered ones
Very large nnComputing n!n! fully before dividingCancel common factors first, as in (525)\binom{52}{5}

A few practical habits help. First, restate the problem as a sequence of stages and ask whether the count at each stage is fixed. Second, sanity-check with a tiny case: for 3 objects, list all the outcomes and confirm your formula gives that number. Third, when a count seems too large, check whether you counted the same outcome more than once.

Counting also has limits. Exact counts become impossible to compute for huge nn in practice, and that is one reason probabilistic methods such as Monte Carlo sampling exist. For estimating a rare event, sampling may be cheaper than exact counting.

History

Counting problems are very old. Pingala, an Indian scholar who probably wrote around the third or second century BCE, studied the number of possible syllable patterns in Sanskrit verse, a combinatorial question about sequences. Later Indian mathematicians worked out the binomial coefficients in connection with counting meters. Persian and Chinese mathematicians also described the triangular arrangement of these numbers centuries before it became known in Europe.

In Europe, the systematic study of combinations grew from gambling. In 1654, Blaise Pascal and Pierre de Fermat corresponded about how to divide the stakes of an unfinished game of chance, a problem that required counting outcomes. Pascal wrote a treatise on the arithmetical triangle that organised these coefficients and used them in probability. Jakob Bernoulli's later work on probability, published after his death in 1713, made counting a standard tool.

The modern field, called enumerative combinatorics, grew through the twentieth century as mathematicians studied counting problems for their own sake. The basic principles in this lesson, however, have been stable for centuries.

Check yourself

QuestionState the multiplication principle in your own words. Why is it not enough when later choices depend on earlier ones?Show answer

If a procedure has stages, and each stage has a fixed number of choices regardless of earlier choices, the total number of outcomes is the product of the counts. When later choices depend on earlier ones, the count at the later stage is not fixed. You then have to split the count into branches, each with its own number of choices, and add the branch totals.

QuestionHow many three-letter codes can be made from the 26 letters A to Z if no letter may repeat? Show the product.Show answer

The first letter has 26 choices, the second 25, the third 24. The total is 26×25×24=15,60026 \times 25 \times 24 = 15{,}600.

QuestionWhy does the formula for combinations divide by k!k! and not by (n−k)!(n-k)!?Show answer

A combination of kk chosen items can be arranged in k!k! orders, and each of those orders is counted once in the permutation formula. Dividing by k!k! removes this overcount, leaving one count per set. The (n−k)!(n-k)! term is already in the permutation formula, to discard the unchosen items, and it appears in the combinations formula as well, but it does not explain the division.

QuestionA team of 5 must be chosen from 12 people, with one captain and one deputy chosen from the team. How many ways are there? Explain which principle you used.Show answer

First choose the captain and deputy, in order, from the 12 people: 12×11=13212 \times 11 = 132 ways. Then choose the other 3 team members from the remaining 10 people, without order: (103)=120\binom{10}{3} = 120. Multiply the stages: 132×120=15,840132 \times 120 = 15{,}840. The multiplication principle links the stages, and the combinations formula handles the unordered part.

Sources