# 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.

## Statements of theorems

The stars and bars method is often introduced specifically to prove the following two theorems of elementary combinatorics.

### Theorem one

### Theorem two

## Proofs via the method of stars and bars

### Theorem one

Suppose there are n objects (represented by 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.

The bins are distinguishable (say they are numbered 1 to k) but the n stars are not (so configurations are only distinguished by the number of stars present in each bin).

A configuration is thus represented by a k-tuple of positive integers, as in the statement of the theorem.

Instead of starting by placing stars into bins, start by placing the stars on a line:

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 it is known which is the first star going to the second bin, and the first star going to the third bin, and so on.

This can be indicated by placing k − 1 separating bars at 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:

### Theorem two

In this case, the representation of a tuple as a sequence of stars and bars, with the bars dividing the stars into bins, is unchanged.

The weakened restriction of nonnegativity (instead of positivity) means that one may place multiple bars between two stars, as well as placing bars before the first star or after the last star.

Thus, for example, when n = 7 and k = 5, the tuple (4, 0, 1, 2, 0) may be represented by the following diagram.

## Examples

### Example 1

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 n = 5 stars and k − 1 = 3 bars.

### Example 2

The graphical method was used by Paul Ehrenfest and Heike Kamerlingh Onnes – with symbol ε (quantum energy element) in place of a star – as a simple derivation of Max Planck’s expression of “complexions” .

The graphical representation would contain P times the symbol “ε” and (N - 1) times the sign “|” for each possible distribution.

In their demonstration, Ehrenfest and Kamerlingh Onnes took N = 4 and P = 7 (i.e., R = 120 combinations).

They chose the 4-tuple (4, 2, 0, 1) as the illustrative example for this symbolic representation: εεεε|εε||ε

## See also

Credits to the contents of this page go to the authors of the corresponding Wikipedia page: en.wikipedia.org/wiki/Stars and bars (combinatorics).