# Stars and bars (combinatorics)

In the context of combinatorial mathematics, stars and bars is a graphical aid for deriving certain combinatorial theorems. It was popularized by William Feller in his classic book on probability. It can be used to solve many simple counting problems, such as how many ways there are to put n indistinguishable balls into k distinguishable bins.[1]

## Statements of theorems

### Theorem one

For any pair of positive integers n and k, the number of distinct k-tuples of positive integers whose sum is n is given by the binomial coefficient $\textstyle{n - 1\choose k-1}$.

### Theorem two

For any pair of natural numbers n and k, the number of distinct k-tuples of non-negative integers whose sum is n is given by the binomial coefficient $\tbinom{n + k - 1}{n}$, or equivalently by the multiset number $\left(\!\tbinom{k}{n}\!\right)$ which counts the multisets of cardinality n, with elements taken from a set of k elements (for $n=k=0$ both these numbers are defined to be 1).

## Proofs

### Theorem one

Suppose one has n objects (to be represented as stars; in the example below n = 7) to be placed into k bins (in the example k = 3), such that all bins contain at least one object; one distinguishes the bins (say they are numbered 1 to k) but one does not wish to distinguish the n stars (so configurations are only distinguished by the number of stars present in each bin; in fact a configuration is represented by a k-tuple of positive integers as in the statement of the theorem). Instead of starting to place stars into bins, one starts by placing the stars on a line:

 ★ ★ ★ ★ ★ ★ ★ Fig. 1: seven objects represented by stars

where the stars for the first bin will be taken from the left, followed by the stars for the second bin, and so forth. Thus the configuration will be determined once one knows what is the first star going to the second bin, and the first star going to the third bin, and so on. One can indicate this by placing k − 1 separating bars at some places between two stars; since no bin is allowed to be empty, there can be at most one bar between a given pair of stars:

 ★ ★ ★ ★ | ★ | ★ ★
Fig. 2: two bars give rise to three bins containing 4, 1, and 2 objects

Thus one views the n stars as fixed objects defining n − 1 gaps, in each of which there may or not be one bar (bin partition). One has to choose k − 1 of them to actually contain a bar; therefore there are $\tbinom{n - 1}{k-1}$ possible configurations (see combination).

### Theorem two

If $n>0$, one can apply theorem one to n + k objects, giving $\tbinom{n+k-1}{k-1}=\tbinom{n+k-1}{n}$ configurations with at least one object in each bin, and then remove one object from each bin to obtain a distribution of n objects into k bins, in which some bins may be empty. For example, placing 10 objects in 5 bins, allowing for bins to be empty, is equivalent to placing 15 objects in 5 bins and forcing something to be in each bin. An alternative way to arrive directly at the binomial coefficient: in a sequence of $n+k-1$ symbols, one has to choose n of them to be stars and the remaining $k-1$ to be bars (which can now be next to each other).

The case k = 0 (no bins at all) allows 0 configurations, unless n = 0 as well (no objects to place), in which there is one configuration (since an empty sum is defined to be 0). In fact the binomial coefficient $\tbinom{n+k-1}{n}$ takes these values for k = 0 (since by convention $\tbinom{-1}{0}=1$ (unlike $\tbinom{n+k-1}{k-1}$, which by convention takes value 0 when $n=k=0$, which is why the former expression is the one used in the statement of the theorem).

## Example

For example, if n = 5, k = 4, and a set of size k is {a, b, c, d}, then ★|★★★||★ would represent the multiset {a, b, b, b, d} or the 4-tuple (1,3,0,1). The representation of any multiset for this example would use 5 stars (n) and 3 bars (k − 1).

Seven indistinguishable one dollar coins are to be distributed among Amber, Ben and Curtis so that each of them receives at least one dollar. Thus the stars and bars apply with n = 7 and k = 3; hence there are $\textstyle{7 - 1 \choose 3-1} = 15$ ways to distribute the coins.

## References

1. ^ Feller, W. (1950) An Introduction to Probability Theory and Its Applications, Wiley, Vol 1, 2nd ed.