Lecture 20: Advanced Counting... (when your toes aren't enough!).

Last time we talked about rules for counting, including the sum rule (perhaps with the annoyance of the inclusion/exclusion corrections), the product rule (for counting Cartesian products), and trees as a way of organizing a brute force approach to counting all possible examples of a set. Today we are going to look a little bit more at the idea of "changing representations" as a way to make counting things easier.

So let's start with trying to count one thing in several different ways. Be forewarned, this may become a trend. Let S be a set of size n. We are going to count the number of subsets of the set S... that is, we are going to find the size of the powerset of S, which we can write as |P(S)|.

One way to start counting things is to list several of the elements of the set. We don't really care what our set is, except that it has n elements, so lets suppose that S = {1,2,3,4...n}. So if we start listing elements of the set we get

{}, {1,2,n}, {2,n}
Now, of all these subsets, is there a way to find groups of them that we can count easily? Especially cool, would be to find independent (non-intersecting) sets, because then we could just add the size of these sets up.

One way would be to partition the subsets of S into groups that have the same number of elements. For example, how many subsets of size 0 are there? How many subsets of size 1? How many subsets of size 2? How many subsets of size k?

Then the total number of subsets is just the sum of the sizes of each group of subsets (because we're never double counting any of them, eh?!).

Sum i = 0..n, of (n choose i)

Going faster now, is there anyother way of specifying all possible subsets? Another way is to think about the characteristic function defining a subset. This function maps every element of S onto T or F, and if that element is mapped to T, then it is an element of the subset that the characteristic function defines.

So how many characteristic functions are there? Or how many functions are there from n elements onto 2 elements? This turns out to be 2n, (because each element has the choice of being in or out of the set).

So now we have a problem. We did the problem one way, and got the answer

Sum i = 0..n, of (n choose i)
and we did it another way and got the answer:
2n.

Actually, this turns out not to be a problem at all... these two quantities are the same. In fact, there is a mechanism of proof, called a "combinatorial proof", that says one way to prove 2 quantities (say A and B) are equal is to find a set whose size can be expressed by one counting method as A, and then by another counting method as B. Since it's the same set, A must be equal to B.

The idea of translating problems into problems about bit strings is a very strong and pervasive one. Not only is it often "the way computers represent things", bit strings are interesting objects in their own right, and help to extract the complex parts out of a problem and let you focus on what you're trying to count.

The goal here is to introduce you to several very different ways of transforming a combinatorial problem. Finding such a transformation is often the hardest part of a counting problem (and, in general, may be the hardest part of many mathematical or algorithmic problems!).

  1. How many ways can 4 integers sum to 12 (order matters!)? == (12 + 4 - 1 choose 4)
    if order doesn't matter, how to do this (i don't actually know this!)?