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 integersn and k, the number of k-tuples of positiveintegers whose sum is n is equal to the number of -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 and, 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 cardinalityk − 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,,, and, and there are of them.
Suppose there are n objects to be placed into k bins, such that all bins contain at least one object. The bins are distinguishable but the n stars are not. 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 separating bars at places betweentwo 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 gaps between stars, in each of which there may or may not be one bar. A configuration is obtained by choosing of these gaps to actually contain a bar; therefore, there are possible configurations.
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 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 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 gaps from the available gaps, or equivalently -element multisets drawn from a set of size. 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 objects. Choosing the positions for the stars leaves exactly spots left for the 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 bars.
Examples
If n = 5, k = 4, and a set of size k is, then ★|★★★||★ would represent the multiset or the 4-tuple. 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. Thus the stars and bars apply with n = 7 and k = 3, and there are ways to distribute the coins.