Counting by Bijection
When a direct count gets messy, find a one-to-one correspondence to something you already know how to count. If every object in the hard pile matches exactly one object in the easy pile, the two piles are the same size.
How many ways are there to place 5 identical balls into 3 distinct boxes?
Try it directly first — you'll likely start listing cases (5-0-0, 4-1-0, 3-2-0, ...) and it gets tedious fast, with lots of room to miss a case or double-count one. There's a cleaner way that sidesteps the listing entirely.
The idea: count something else instead
A bijection is a pairing between two collections where every item in the first matches exactly one item in the second, and vice versa — nothing left over on either side. If you can build such a pairing between your hard-to-count objects and some easy-to-count objects, the counts must be identical, because the pairing itself proves it item by item. You never touch the original messy pile again; you just count the tidy one.
The stars-and-bars bijection
For balls-in-boxes, the standard bijection is stars and bars. Represent 5 identical balls as 5 stars: . To split them among 3 boxes, insert 2 dividers ("bars") among the stars — 2 bars because 3 boxes need 2 walls to separate them. For instance:
Every arrangement of 5 stars and 2 bars in a row corresponds to exactly one way of splitting the balls, and every split corresponds to exactly one star-bar arrangement — that's the bijection, and it's obviously reversible in both directions. So the question "how many ways to split 5 balls into 3 boxes" becomes "how many ways to arrange a row of 5 stars and 2 bars," which is just: choose which 2 of the 7 total symbols are bars (the rest are automatically stars).
Answer: 21 ways. Compare that to listing every case (5-0-0 and its 3 orderings, 4-1-0 and its 6 orderings, 3-2-0 and its 6 orderings, 3-1-1 and its 3 orderings, 2-2-1 and its 3 orderings — ): it checks out, but the bijection got there without any of that bookkeeping.
If direct counting means listing cases and hoping you didn't miss or repeat one, look instead for a reversible pairing to a shape you already know how to count — a binary string, a path on a grid, a sequence of choices. The pairing is the proof; you just count the easy side.
A second example: handshakes at a party
20 people are at a party. Everyone shakes hands with everyone else exactly once. How many handshakes happen?
A handshake is fully described by which two people are involved — order doesn't matter, "Alice shakes Bob" is the same handshake as "Bob shakes Alice." So handshakes are in exact bijection with unordered pairs of the 20 people. Counting unordered pairs: pick a first person (20 ways) and a second (19 remaining ways), giving 380 ordered picks, but each unordered pair got counted twice (once as A-then-B, once as B-then-A), so divide by 2:
The bijection here is simple but easy to skip past: recognizing that "count the handshakes" is identical to "count the 2-element subsets of a 20-element set" is what turns a story problem into a formula you already have memorized.
Whenever a puzzle's objects are naturally described by "choose a subset of size from things," stop enumerating and reach for — that's the signature of a bijection to combinations hiding in plain sight.
Where this generalizes
The stars-and-bars bijection extends immediately to counting non-negative integer solutions of (it's the identical picture: stars, bars), which is the combinatorial engine behind counting lattice paths, distributing indistinguishable trades across distinguishable accounts, or splitting a fixed budget across categories. The broader habit — find a bijection to something countable — is the same instinct that turns hard geometry counts into binary-string counts, turns balanced-parenthesis counts into Catalan-number counts, and turns "how many ways" into "how many subsets," which is usually a formula you already know.
Related concepts
Practice in interviews
Further reading
- Engel, Problem-Solving Strategies (ch. 5, Combinatorics)
- Andreescu & Feng, A Path to Combinatorics for Undergraduates