Counting unordered lists (CSCI 2824, Spring 2015)On this page, we consider the problem of counting the number of ordered and unordered lists. The materials correspond to Sect 5.4 of the textbook. Recap on counting ordered listsExample 1How many ordered lists of 10 letters from have exactly 3 's? Solution
Example 2Similarly, the number of ordered lists of 10 English letters with exactly 3 's is . Counting unordered listsExample 3How many ways can I distribute 10 candies among Alice, Bob and Carlos, so that each person has at least 1 candy? Using the stars and bars technique
We can reason use the stars and bars diagram.
Example 4How many ways can I distribute 10 candies among Alice, Bob and Carlos, with the possibility that someone can have no candies? Using the stars and bars technique
Consider the following scenario:
Using the reasoning from Example 3, we see that there are possible ways of distributions. Example 5 (NEW!)How many ways can I distribute 20 candies among Alice, Bob and Carlos, so that each person has at least 3 candies? Answer
To ensure that everyone gets at least 3 candies, we can do the following:
So the number of distinct distributions is equal to the number of ways to distribute 11 candies among 3 people, which is Example 6 (NEW!)What is the cardinality of the set Answer
Counting the number of elements of the above set is the same as counting the number of ways to distribute 30 apples among 4 people so that everyone gets at least 1 apple, with:
So then we can use the stars and bars method as in Example 3, and the answer would be . Example 7 (NEW!)What is the cardinality of the set Answer
Counting the number of elements of the above set is the same as counting the number of ways to distribute 30 apples among 4 people (though someone could get none), with:
So then we can use the stars and bars method as in Example 4, and the answer would be . Example 8 (NEW!)I have a box of dollar bills. In this box, there are 10 $1 bills, 20 $10 bills and 30 $20 bills. From the box, I grab 5 bills all at onces. How many possible outcomes are there? Note that I can record all the possible results in a table like this:
For instance, the first row says I get two $1 bills, one $10 bill and one $20 bill; the second row says I get one $1 bill and three $20 bills. (I probably should list my results in a more systematic way than the above though!) Note that in this table each row contains three numbers that sum to 5. The point is that we can think of this counting problem as finding all the possible ways to distribute 5 objects (in this case bills) among 3 different bins. Answer
Hence the answer can be obtained using the stars and bars technique: Example 9 (NEW!)From a big of 8 (identical) red marbles, 5 (identical) green marbles 3 (identical) blue marbles, we grab 4 marbles all at once. How many different outcomes (in terms of color combinations) are there? Answer
Like Example 8, this counting problem is equivalent to counting the number of ways to distribute 4 objects among 3 different bins (for the three different colors), with the restriction that the last bin (for the color green) can hold at most 3 objects. Without any restriction, there are ways to distribute 4 objects in 3 different bins. There is one outcome that we don't want: that all 4 objects go into the green bin. Hence the answer is . Placing objects in binsIn general, suppose we have objects and bins, with and . Let be the number of ways of distributing the objects in the bins. Then using the above stars-and-bars technique, we get that . Note that the number of ways of distributing objects in bins is also equal to the cardinality of the following set: . Finding via recursive countingWe studied how to find using the stars-and-bar technique. Now we consider an alternative method: recursive counting. Simple cases:
Now suppose that and . We claim that . Consider the number of objects placed in the last bin.
This is an example of recursive counting. To compute using the recursive formula, we can use the following program: Program for computing T
int T(int n, int r){ assert( n >= 0 ); assert( r >= 1 ); /* Base Case */ if ( r == 1) return 1; if ( n == 0) return 1; /* Recurrence */ return T(n-1,r) + T(n,r-1); } Here are the comparison of run times (in seconds) on some instances:
|