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

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

Theorem one

For any pair of positive integers n and k, the number of k-tuples of positive integers whose sum is n is equal to the number of (k − 1)-element subsets of a set with n − 1 elements.

Both of these numbers are given by the binomial coefficient . For example, when n = 3 and k = 2, the tuples counted by the theorem are (2, 1) and (1, 2), and there are of them.

Theorem two

For any pair of positive integers n and k, the number of k-tuples of non-negative integers whose sum is n is equal to the number of multisets of cardinality k − 1 taken from a set of size n + 1.

Both numbers are given by the multiset number , or equivalently by the binomial coefficient or multiset number . For example, when n = 3 and k = 2, the tuples counted by the theorem are (3, 0), (2, 1), (1, 2), and (0, 3), and there are of them.

Proofs via the method of stars and bars

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 possible configurations (see combination).

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.

||| |
Fig. 3: four bars give rise to five bins containing 4, 0, 1, 2, and 0 objects

This establishes a one-to-one correspondence between tuples of the desired form and selections with replacement of k  1 gaps from the n + 1 available gaps, or equivalently (k  1)-element multisets drawn from a set of size n + 1. By definition, such objects are counted by the multichoose number .

To see that these objects are also counted by the binomial coefficient , observe that the desired arrangements consist of n + k  1 objects (n stars and k  1 bars). Choosing the positions for the stars leaves exactly k  1 spots left for the k  1 bars. That is, choosing the positions for the stars determines the entire arrangement, so the arrangement is determined with selections. Note that , reflecting the fact that one could also have determined the arrangement by choosing the positions for the k  1 bars.


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.

Many elementary word problems in combinatorics are resolved by the theorems above. For example, if one wishes to count the number of ways to distribute seven indistinguishable one dollar coins among Amber, Ben, and Curtis so that each of them receives at least one dollar, one may observe that distributions are essentially equivalent to tuples of three positive integers whose sum is 7. (Here the first entry in the tuple is the number of coins given to Amber, and so on.) Thus the stars and bars apply with n = 7 and k = 3, and there are ways to distribute the coins.

See also


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

Further reading

This article is issued from Wikipedia - version of the 11/16/2016. The text is available under the Creative Commons Attribution/Share Alike but additional terms may apply for the media files.