A frequently occurring problem in combinatorics arises when counting the number of ways to group identical objects, such as placing indistinguishable balls into labelled urns. We discuss a combinatorial counting technique known as stars and bars or balls and urns to solve these problems, where the indistinguishable objects are represented by stars and the separation into groups is represented by bars.
This allows us to transform the set to be counted into another, which is easier to count. As we have a bijection, these sets have the same size.
Consider the equation where are non-negative integers. We're looking for the number of solutions this equation has. At first, it's not exactly obvious how we can approach this problem. One way is brute force: fixing possibilities for one variable, and analyzing the result for other variables. But we want something nicer, something really elegant. We use the above-noted strategy: transforming a set to another by showing a bijection so that the second set is easier to count.
Suppose we have places, where we put stars and bars, one item per place. The key idea is that this configuration stands for a solution to our equation. For example, stands for the solution . Because we have star, then a bar (standing for a plus sign), then stars, again a bar, and similarly and stars follow. Similarly, denotes the solution because we have no star at first, then a bar, and similar reasoning like the previous.
We see that any such configuration stands for a solution to the equation, and any solution to the equation can be converted to such a stars-bars series. So we've established a bijection between the solutions to our equation and the configurations of stars and bars. So our problem reduces to "in how many ways can we place stars and bars in places?" This is the same as fixing places out of places and filling the rest with stars. We can do this in, of course, ways. So the number of solutions to our equation is
The stars and bars/balls and urns technique is as stated below.
The number of ways to place indistinguishable balls into labelled urns is
Here is the proof the above theorem.
We represent the balls by adjacent stars and consider inserting bars in between stars to separate the bars into groups. For example, for and , the following is a representation of a grouping of indistinguishable balls in 5 urns, where the size of urns 1, 2, 3, 4, and 5 are 2, 4, 0, 3, and 3, respectively:
Note that in the grouping, there may be empty urns. There are a total of positions, of which are stars and are bars. Thus, the number of ways to place indistinguishable balls into labelled urns is the same as the number of ways of choosing positions among spaces for the stars, with all remaining positions taken as bars. The number of ways this can be done is
Note: can be interpreted as the number of ways to instead choose the positions for bars and take all remaining positions to be stars.
Check out the following example:
How many ordered sets of non-negative integers are there such that
We first create a bijection between the solutions to and the sequences of length 13 consisting of 10 's and 3 's. In other words, we will associate each solution with a unique sequence, and vice versa.
Given a set of 4 integers , we create the sequence that starts with 's, then has a , then has 's, then has a , then has 's, then has a , then has 's. For example, if , then the associated sequence is . Now, if we add the restriction that , the associated sequence will consist of 10 's (from ) and 3 's (from our manual insert), and thus has total length 13.
Conversely, given a sequence of length 13 that consists of 10 's and 3 's, let be the length of the initial string of 's (before the first ), let be the length of the next string of 1's (between the first and second ), let be the length of the third string of 's (between the second and third ), and let be the length of the last string of 's (after the third ). These values give a solution to the equation .
This construction associates each solution with a unique sequence, and vice versa, and hence gives a bijection.
Now that we have a bijection, the problem is equivalent to counting the number of sequences of length 13 that consist of 10 's and 3 's, which we count using the stars and bars technique. There are positions from which we choose positions as 1's and let the remaining positions be 0's. By stars and bars, there are different choices.
Note: Another approach for solving this problem is the method of generating functions.
This section contains examples followed by problems to try.
Find the number of non-negative integer solutions to
We have variables, thus plus signs. So by stars and bars, the answer is
How many ways are there to choose a 5-letter word from the 26-letter English alphabet with replacement, where words that are anagrams are considered the same?
Observe that since anagrams are considered the same, the feature of interest is how many times each letter appears in the word (ignoring the order in which the letters appear). To translate this into a stars and bars problem, we consider writing 5 as a sum of 26 integers and where is the number of times letter is chosen, is the number of times letter is chosen, etc.
Thus, = 5 and = 26.
Then by stars and bars, the number of 5-letter words is
For some problems, the stars and bars technique does not apply immediately. In these instances, the solutions to the problem must first be mapped to solutions of another problem which can then be solved by stars and bars. We illustrate one such problem in the following example:
How many ordered sets of positive integers are there such that for and
Because of the inequality, this problem does not map directly to the stars and bars framework. To proceed, consider a bijection between the integers satisfying the conditions and the integers satisfying and
Now, by setting for , we would like to find the set of integers such that and
By stars and bars, this is equal to .
Try the following problems: