The selection is a count per type
Choosing 5 doughnuts from 3 kinds is choosing how many of each: a solution of x₁ + x₂ + x₃ = 5 in non-negative integers.
Choosing r items from n types with repetition allowed and order irrelevant. The count is C(n+r−1, r), and the reason is a bijection with arrangements of stars and bars.
Core ideas
The last of the four counting rules, and the only one whose formula is not obvious from the statement.
Choosing 5 doughnuts from 3 kinds is choosing how many of each: a solution of x₁ + x₂ + x₃ = 5 in non-negative integers.
Write r stars and n − 1 bars; the bars split the stars into n groups. Every arrangement is a selection and conversely.
Requiring each xᵢ ≥ 1 is the same problem with r − n items to distribute freely, so the count is C(r−1, n−1).
The material
The bijection, the formula, and the variants.
The number of ways to choose r items from n types, with repetition allowed and order irrelevant, is C(n + r − 1, r).
Encode a selection as a row of r stars and n − 1 bars: the stars before the first bar are the items of type 1, those between the first and second bar are type 2, and so on. Empty groups are allowed and represent types not chosen.
This is a bijection. Every selection gives exactly one such row, and every row of r stars and n − 1 bars gives exactly one selection.
A row is an arrangement of r + n − 1 symbols of which r are stars, so there are C(n + r − 1, r) of them.
□
Five doughnuts from three kinds: C(3 + 5 − 1, 5) = C(7,5) = 21. The selection "two glazed, none jam, three chocolate" is the row ** | | ***.
The picture is worth keeping. n types need n − 1 bars, not n, because the bars go between the groups. Using n bars is the standard error and gives C(n+r, r).
The number of solutions of x₁ + ⋯ + x_n = r in non-negative integers is C(n + r − 1, r) — the same count, since a solution is exactly a selection.
The number of solutions with every xᵢ ≥ 1 is C(r − 1, n − 1).
Give each variable 1 up front, leaving r − n units to distribute freely among n variables. That is the non-negative problem with r − n in place of r, so the count is C(n + (r−n) − 1, r−n) = C(r−1, r−n), which equals C(r−1, n−1) by symmetry.
□
The substitution trick generalises. A constraint xᵢ ≥ c is handled by pre-assigning c units to that variable and solving the reduced problem; an upper bound xᵢ ≤ c is harder and needs the inclusion and exclusion of “The Inclusion-Exclusion Principle”.
Every basic counting problem in this course is one of these four. The arithmetic differs by orders of magnitude — at n = 5, r = 3 the four give 60, 10, 125 and 35 — so classifying correctly matters far more than computing carefully.
Interactive
Enumerated while enumeration is possible
Method
Look for identical items distributed among distinct types.
Five identical doughnuts, r indistinguishable units. If the items are distinct, this is not the right formula.
Three named kinds, n labelled boxes. Identical boxes give a much harder problem that this course does not cover.
x₁ + ⋯ + x_n = r with the constraints stated. This form makes the substitutions visible.
xᵢ ≥ c becomes yᵢ = xᵢ − c ≥ 0 with the total reduced by c. Upper bounds need “The Inclusion-Exclusion Principle”.
Solutions of x₁ + x₂ + x₃ = 12 with xᵢ ≥ 2 for each i.
Lower bounds are free: pre-assign and shrink the total. Upper bounds are not — counting the solutions with xᵢ ≤ 5 requires subtracting the violating cases and adding back the double violations, which is exactly “The Inclusion-Exclusion Principle”.
Take "how many ways to put 8 identical balls into 4 labelled boxes", restate it as an equation and as a stars-and-bars diagram, and compute. All three descriptions are the same problem, and recognising that is the point.
Something to change about this lesson? Write it down, tick it off when it is handled, and export the list when you want to act on it. Kept in this browser only: nothing is sent anywhere, and nobody is notified.
No recommendations yet for this lesson.