Recursive counting (CSCI 2824, Spring 2015)Topic covered:
Recursive CountingWe already saw in the previous lecture an example of recursive counting, when we count the number of ways to distribute indistinguishable objects among different bins. The idea behind recursive counting is to set up a recurrence that expresses what you wish to count. This is especially useful when what we wish to count does not neatly fit into any of the categories studied thus far. Example 1Question. How many matches need to be played between teams in a round-robin tournament? Answer
Let us look at it recursively. Let be the number of matches for teams. We know that
Can we now express in terms of ? Yes, we can say that with teams, # of matches involving all n teams = # of matches involving teams 1… (n-1) + # of matches involving team n Team plays precisely matches (one with every other team). I.e, . Therefore, the answer to the problem is governed by the recurrence relation:
The closed form solution is indeed . Example 2Question. What is the number of permutations of objects? In other words, what is ? Answer
Let us write a recurrence. To obtain a permutation of objects (numbered 1…), let us do the following:
Step 1 yields possible permutations. (We pretend not to know what it may be :-) ) Once we have fixed a permutation of the first objects, there are possible places where object #n can be inserted. Therefore the recurrence is
Once again, we know by eyeballing the recurrence that . Example 3We wish to roll a dice times to obtain a sum of . Each roll of the dice can give us a number from to . Question. For any integer and any integer , let be the number of ways to obtain a sum of from rolls of a dice. Write a recurrence relation for . Answer
Let us get rid of the base cases where or .
Now for the generic case (i.e., the non-base case where and ). Suppose we wish to roll the dice times and arrive at a sum of exactly . Let us split cases on the last roll:
Therefore, we can now write a recurrence to express the sum: . An alternative approach is to express as the cardinality of the set The above is a disjoint union, i.e., the sets whose union gives have empty intersection. Therefore by the sum rule, |