Stars and Bars
A counting trick for figuring out how many ways a fixed number of identical items can be split among a number of distinct groups, by picturing the items as stars separated by dividing bars.
A common interview question asks: in how many ways can identical items be distributed among distinct groups (say, identical trade tickets assigned across traders, with any trader allowed to get zero)? Lining the items up as a row of stars, you need "bars" placed among them to mark the boundaries between groups — everything before the first bar goes to group 1, between the first and second bar to group 2, and so on. The count of arrangements is then just the number of ways to choose which of the total symbols (stars plus bars) are bars:
For example, splitting identical trade tickets among traders (any trader can get zero) gives possible ways to divide them up, a number that would be tedious to enumerate by hand but falls out immediately once the problem is reframed as arranging stars and bars.
The same idea answers a slightly different-looking question: how many ways can a fixed total, like 10 units of risk budget, be split among 4 desks if every desk must get at least one unit? That's solved by first handing each desk its mandatory 1 unit, leaving 6 units to distribute freely among 4 desks (zero allowed), which is again . This "give everyone the minimum first, then stars-and-bars the remainder" move is one of the most reused tricks in combinatorics interview questions, since it converts an awkward at-least-one constraint into the plain, no-constraint version of the same problem.
Stars and bars counts the ways to split identical items into distinct groups (zero allowed) as , by treating the split points between groups as bars interspersed among stars representing the items.
Related concepts
Practice in interviews
Further reading
- Feller, An Introduction to Probability Theory and Its Applications, vol. 1