Stars and bars counts tuples of nonnegative integers with a prescribed sum. For integers and , its statement isSuch a tuple is a weak composition of an integer. Think of labelled bins: counts identical objects in the first bin, in the second, and so on. Bin names distinguish positions even when counts agree. Stars and bars counts these count tuples; assigning individually distinct objects requires additional information. [ref]
https://math.mit.edu/~fgotti/docs/Courses/C.%20Combinatorial%20Analysis/6.%20Compositions/Compositions.pdf. Felix Gotti, MIT 18.211, Lecture 6: Compositions, Proposition 1 and Example 3
Computed example. With and , the number of weak compositions of an integer is . The string
••|•|•• encodes : two dots before the first bar, one between the bars, and two after the second. For a fixed first-bin count , the second-bin count can be any integer from to and the third is forced. Thus the direct count is .Stars and bars for five identical objects and three labelled bins: ordinary splits, adjacent bars, and bars at either end
. Details. Adjacent bars encode an empty middle bin:
••||••• gives . A bar at the left end encodes an empty first bin, as in |••|••• for ; a bar at the right end encodes an empty third bin, as in ••|•••| for . These are valid weak compositions of an integer. For every count is zero, and for the unique tuple is , consistent with .Proof outline. Replace each count by that many dots and separate successive groups with bars. Reading the group sizes reverses this construction, so it is a bijection between weak compositions of an integer and strings of dots and bars. Choose the bar positions among positions; the binomial coefficient counts the choices. The beauty is that empty bins need no separate cases: end bars and adjacent bars encode them automatically.
If every bin must be nonempty, the tuples are compositions of an integer, and their count is for ; for there are none. Subtract one from every count, setting . This is a bijection to weak compositions of an integer of , so stars and bars gives . For five objects and three bins, this is , with the six positive tuplesFor instance, shifts to , whose sum is . Sorting the six positive tuples collapses them to just two integer partitions, and . Thus named bins and unordered summands answer different questions.
Stars and bars is useful for allocating identical resources or enumerating integer solutions without listing them individually. Prescribed lower bounds can be subtracted just like the nonempty-bin requirement. Upper bounds require removing forbidden tuples; the existing bounded weak compositions article applies the inclusion-exclusion principle to those violations.
Articles by others on the same topic
"Stars and Bars" is a combinatorial method used to solve problems of distributing indistinguishable objects (stars) into distinct groups (bars). It's particularly useful for problems that involve partitioning integers or distributing identical items into different categories.
