Counting: the four cases, and how to tell them apart
COMB · Chapter 112 min readAsked at Jane Street, Optiver, SIG, IMC
After this lesson you should be able to
- Classify a counting problem by order and replacement.
- Use stars and bars for identical objects.
- Spot when a "count" question is really a probability question.
Almost every counting question in an interview is one of four standard cases, and almost every wrong answer comes from picking the wrong one. Decide two things — does order matter, and can items repeat — and the formula follows.
| Repetition | Order matters | Order does not |
|---|---|---|
| No repetition | ||
| Repetition allowed |
Equation 1.2
The binomial coefficient
The number of ways to choose items from when order does not matter.
- Choosing what to take is the same as choosing what to leave.
- Pascal: condition on whether the first item is taken.
Proposition 1.3
The identities worth knowing
Three come up repeatedly. The hockey-stick identity sums a column of Pascal’s triangle. Vandermonde’s identity splits a choice across two groups. And the committee-and-chair argument, , is the cleanest example of the double-counting technique: count the same thing two ways and equate.
Holds when
- Hockey stick: .
- Vandermonde: .
- Double counting is usually a cleaner proof than algebra, and it is what an interviewer wants to see.
Derivation 1.4
Stars and bars
How many ways can identical items be distributed among distinct boxes?
Write the items as stars and the dividers between boxes as bars.
Every arrangement corresponds to exactly one distribution.
Example 1.5
You buy 10 identical lots and must allocate them across 4 accounts, with empty accounts allowed. How many allocations are there?
Show the worked solutionHide the worked solution
Worked solution
- Formula
- Substitute
- Solve
- Answer
Sanity check. If empty accounts were forbidden, put one lot in each first and distribute the remaining 6, giving — a useful check that the constraint changes the count in the right direction.
The rest of this lesson is in Premium
You have read the opening. 13 more sections follow, including 5 worked examples and 3 quick checks.
Nothing is charged for 7 days, and you can cancel before then. Or read Arithmetic that survives a clock in full, free.