Skip to content
VibeFormer
Beginner24 min

Counting, Permutations and Combinations

Product and sum rules, permutations with and without repetition, combinations, and multinomial coefficients.

Counting, Permutations and Combinations

Intuition first

When every outcome is equally likely, a probability is just a fraction: favourable outcomes divided by total outcomes. So computing the probability is counting, and every mistake in this lesson becomes a mistake in every probability that follows.

Two questions settle almost every counting problem:

  1. Does order matter? "ABC" and "CBA" — the same selection or different ones?
  2. Can things repeat? Once used, is an item gone?

Answer those two and the formula follows mechanically. Almost all errors come from answering them wrongly, not from arithmetic.

The two fundamental rules

Multiplication rule. If a task splits into kk independent stages with n1,n2,,nkn_1, n_2, \dots, n_k choices, the total number of outcomes is

n1×n2××nkn_1 \times n_2 \times \dots \times n_k

Addition rule. If a task can be done in one of kk mutually exclusive ways, with nin_i options in case ii, the total is

n1+n2++nkn_1 + n_2 + \dots + n_k
Notation used in this lesson
SymbolMeaning
n!n factorial — the product 1 × 2 × … × n, with 0! = 1
P(n, r)Permutations: ordered selections of r from n
C(n, r)Combinations: unordered selections of r from n
nCr or (n r)Alternative notation for combinations

The four cases

Order mattersOrder does not matter
No repetitionP(n,r)=n!(nr)!P(n,r) = \dfrac{n!}{(n-r)!}C(n,r)=n!r!(nr)!C(n,r) = \dfrac{n!}{r!\,(n-r)!}
Repetition allowednrn^r(n+r1r)\dbinom{n + r - 1}{r}

Permutations

Arranging rr items from nn distinct items, order significant:

P(n,r)=n(n1)(n2)(nr+1)=n!(nr)!P(n, r) = n(n-1)(n-2)\cdots(n-r+1) = \frac{n!}{(n-r)!}

The reasoning is the multiplication rule: nn choices for the first position, n1n-1 for the second (one is used up), and so on for rr positions.

Combinations

C(n,r)=(nr)=n!r!(nr)!C(n, r) = \binom{n}{r} = \frac{n!}{r!\,(n-r)!}
Why combinations divide by r!Advanced

Count ordered selections first: P(n,r)=n!/(nr)!P(n,r) = n!/(n-r)!.

Now notice that every unordered selection of rr items was counted multiple times — once for each way of ordering those rr items, which is r!r! ways.

So the ordered count is exactly r!r! times the unordered count:

P(n,r)=r!×C(n,r)C(n,r)=P(n,r)r!=n!r!(nr)!P(n,r) = r! \times C(n,r) \quad\Longrightarrow\quad C(n,r) = \frac{P(n,r)}{r!} = \frac{n!}{r!\,(n-r)!}

Dividing by r!r! removes the over-counting. This "count with order, then divide by the over-count" technique solves a large fraction of harder counting problems.

Two identities worth knowing by sight:

(nr)=(nnr)(choosing r to keep = choosing nr to discard)\binom{n}{r} = \binom{n}{n-r} \qquad\text{(choosing } r \text{ to keep = choosing } n-r \text{ to discard)} (nr)=(n1r1)+(n1r)(Pascal’s rule)\binom{n}{r} = \binom{n-1}{r-1} + \binom{n-1}{r} \qquad\text{(Pascal's rule)}

Permutations with repeated items

Arranging nn items where n1n_1 are identical of one type, n2n_2 of another, and so on:

n!n1!n2!nk!\frac{n!}{n_1!\,n_2!\cdots n_k!}

This is the multinomial coefficient, and it is the same divide-by-the-over-count idea: swapping two identical letters produces no new arrangement.

Solved problem 1 · Arrangements of a word with repeats

How many distinct arrangements are there of the letters in STATISTICS?

Step 1 — count letters and their multiplicities

STATISTICS has 10 letters:

S:3,T:3,A:1,I:2,C:1\text{S}: 3, \quad \text{T}: 3, \quad \text{A}: 1, \quad \text{I}: 2, \quad \text{C}: 1

Check: 3+3+1+2+1=10  3 + 3 + 1 + 2 + 1 = 10 \;\checkmark

Step 2 — apply the multinomial coefficient

10!3!3!1!2!1!\frac{10!}{3!\,3!\,1!\,2!\,1!}

Step 3 — evaluate

10!=3,628,80010! = 3{,}628{,}8003!×3!×1!×2!×1!=6×6×1×2×1=723! \times 3! \times 1! \times 2! \times 1! = 6 \times 6 \times 1 \times 2 \times 1 = 723,628,80072=50,400\frac{3{,}628{,}800}{72} = 50{,}400

Answer

50,40050{,}400 distinct arrangements.

Solved problem 2 · A committee with constraints

A department has 7 men and 5 women. How many 4-person committees contain at least one woman?

Step 1 — total committees with no constraint

Order does not matter and nobody serves twice, so this is a combination:

(124)=12!4!8!=12×11×10×94×3×2×1=11,88024=495\binom{12}{4} = \frac{12!}{4!\,8!} = \frac{12 \times 11 \times 10 \times 9}{4 \times 3 \times 2 \times 1} = \frac{11{,}880}{24} = 495

Step 2 — use the complement

"At least one woman" has many cases (1, 2, 3 or 4 women). Its complement has exactly one: no women, i.e. all 4 chosen from the 7 men.

(74)=7×6×5×44×3×2×1=84024=35\binom{7}{4} = \frac{7 \times 6 \times 5 \times 4}{4 \times 3 \times 2 \times 1} = \frac{840}{24} = 35

Step 3 — subtract

49535=460495 - 35 = 460

Step 4 — verify by direct enumeration

Summing the four cases as a check:

(51)(73)=5×35=175\binom{5}{1}\binom{7}{3} = 5 \times 35 = 175(52)(72)=10×21=210\binom{5}{2}\binom{7}{2} = 10 \times 21 = 210(53)(71)=10×7=70\binom{5}{3}\binom{7}{1} = 10 \times 7 = 70(54)(70)=5×1=5\binom{5}{4}\binom{7}{0} = 5 \times 1 = 5175+210+70+5=460  175 + 210 + 70 + 5 = 460 \;\checkmark

Answer

460460 committees. The complement route needed one binomial coefficient; direct enumeration needed four.

Combinations with repetition

Choosing rr items from nn types, repetition allowed, order irrelevant — how many ways to pick 6 doughnuts from 4 varieties?

(n+r1r)\binom{n + r - 1}{r}
The stars and bars argumentAdvanced

Represent a selection as rr stars divided into nn groups by n1n-1 bars. Six doughnuts from four varieties, taking 3 of the first, 0 of the second, 2 of the third and 1 of the fourth:

text
***||**|*

Every arrangement of 6 stars and 3 bars corresponds to exactly one selection, and every selection to exactly one arrangement. So we are counting arrangements of r+n1r + n - 1 symbols where rr are stars:

(r+n1r)=(6+416)=(96)=84\binom{r + n - 1}{r} = \binom{6 + 4 - 1}{6} = \binom{9}{6} = 84

The bijection is the whole argument — once you see that a selection is a star-and-bar string, the formula is just the multinomial count.

Counting in code

python
from math import comb, perm, factorial

print(f"P(8,3) = {perm(8, 3)}")              # 336 — medals, order matters
print(f"C(52,5) = {comb(52, 5):,}")          # 2,598,960 — poker hands
print(f"STATISTICS = {factorial(10) // (factorial(3)*factorial(3)*factorial(2)):,}")
print(f"doughnuts  = {comb(6 + 4 - 1, 6)}")  # 84 — stars and bars

# Verify Pascal's rule for a few values.
assert all(comb(n, r) == comb(n-1, r-1) + comb(n-1, r)
           for n in range(1, 20) for r in range(1, n))
print("Pascal's rule verified")

Exercise 1

From a standard 52-card deck, how many 5-card hands contain exactly 2 aces?

Show solution

Split the choice into two independent stages and multiply.

Choose 2 of the 4 aces:

(42)=6\binom{4}{2} = 6

Choose the remaining 3 cards from the 48 non-aces:

(483)=48×47×466=103,7766=17,296\binom{48}{3} = \frac{48 \times 47 \times 46}{6} = \frac{103{,}776}{6} = 17{,}296

By the multiplication rule:

6×17,296=103,7766 \times 17{,}296 = 103{,}776

As a probability:

103,7762,598,9600.0399\frac{103{,}776}{2{,}598{,}960} \approx 0.0399

The common error is choosing 3 cards from all 50 remaining, which allows a third ace and therefore counts hands with 3 or 4 aces.

Exercise 2

How many ways can 8 people be seated at a round table, if rotations are considered identical?

Show solution

Linear arrangements of 8 people: 8!=40,3208! = 40{,}320.

At a round table each distinct seating is counted once for every rotation. With 8 seats there are 8 rotations producing the same circular arrangement, so

8!8=7!=5,040\frac{8!}{8} = 7! = 5{,}040

The standard shortcut: fix one person's seat to break the rotational symmetry, then arrange the remaining 7 freely, giving 7!7! directly.

If reflections also count as identical — relevant for necklaces rather than dinner parties — divide by a further 2, giving 7!/2=2,5207!/2 = 2{,}520.

Exercise 3

A password is 6 characters from the 26 lowercase letters. How many contain at least one repeated letter?

Show solution

Total passwords, repetition allowed and order mattering:

266=308,915,77626^6 = 308{,}915{,}776

Passwords with all distinct letters — the complement:

P(26,6)=26×25×24×23×22×21P(26, 6) = 26 \times 25 \times 24 \times 23 \times 22 \times 2126×25=650,650×24=15,600,15,600×23=358,80026 \times 25 = 650, \quad 650 \times 24 = 15{,}600, \quad 15{,}600 \times 23 = 358{,}800358,800×22=7,893,600,7,893,600×21=165,765,600358{,}800 \times 22 = 7{,}893{,}600, \quad 7{,}893{,}600 \times 21 = 165{,}765{,}600

Subtract:

308,915,776165,765,600=143,150,176308{,}915{,}776 - 165{,}765{,}600 = 143{,}150{,}176

So about 46.3% of 6-letter passwords contain a repeat — a version of the birthday problem, and higher than most people guess.


Next: Inclusion–Exclusion and Pigeonhole, for counting problems where the cases overlap.