This is going to touch on some more basic math, but do it in an interesting way that we can apply to more complicated problems.
The problem is this – given a set of n distinct objects (for example, the numbers 1 to n), how many ways are there to construct a subset of size k?
For example, if we take the numbers {1,2,3}, there are 3 ways of constructing a set of size 2. {1,2}, {2,3}, {3,1}. Note that in dealing with sets, order doesn’t matter. {1,2,3} is the same set as {2,1,3}.
So, given the numbers {1,…,n}, we’ll say that there are many sets of size k. We’re going to solve for
.
Consider the set of permutations on the n objects. There are n! ways of ordering the numbers 1 to n. These are the total permutations on the whole set of objects. The 6 permutations of the numbers {1,2,3} are [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1].
We can group those n! many permutations based on the first k elements of that permutation. There are sets of size k, so consider the i-th such set, we’ll call
. Let
be the set of all permutations of the numbers 1 to n that start with the k numbers in
.
Two things to note first – Every permutation on the numbers 1 to n has -some- numbers as its first k elements. The first k elements form some k-sized subset of the numbers 1 to n. This means that every permutation occurs in one of the sets.
Second, a given permutation can’t occur in two different sets. Being in one of those sets fixes what the first k elements of that permutation are. The first k elements can’t be in two different k sets!
So those two facts, that every permutation is in some , and only one of the
, allow us to say the following.
That is, we can count the total number of permutations by counting the size of each of the sets.
For a given then, we can ask how big it is. We know what the first k elements of any permutation in that set are, which means that the last n-k elements must be everything else. Any permutation in
must be composed of some ordering of those k elements, and then some ordering of the n-k elements remaining. There are k! ways of ordering those k elements, and then (n-k)! ways of ordering the last n-k elements. Thus, there are k!*(n-k)! possible permutations that have a given set of k elements at the beginning.
Notice, nicely, that is independent of the choice of the first k elements. Going back to our previous equation, we get
So, by partitioning the total set of permutations based on what the first k elements are, we can count the total number of possible k element sets.
There are definitely easier ways of arriving at the same formula, but this technique allows us to solve a number of related problems as well. Which … I might talk about later.
Interesting stuff.

