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 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:
★ ★ ★ ★ | | | ★ | | | ★ ★ |
View the n stars as fixed objects defining n − 1 gaps between stars, in each of which there may or may not be one bar (a bin partition). A configuration is obtained by choosing k − 1 of these gaps 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.
★ ★ ★ ★ | | | | | ★ | | | ★ ★ | | |
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.
Examples
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
References
- Feller, William (1950). An Introduction to Probability Theory and Its Applications. 1 (2nd ed.). Wiley.
Further reading
- Pitman, Jim (1993). Probability. Berlin: Springer-Verlag. ISBN 0-387-97974-3.
- Weisstein, Eric W. "Multichoose". Mathworld -- A Wolfram Web Resource. Retrieved 18 November 2012.