![](counting_files/figure-html/fig-outfit-counting-1.png)
2 Techniques for Counting
To compute probabilities, we need to be able to count the number of outcomes in different sample spaces and events. For most of the examples in Chapter 1, this counting could be done by listing all the possible outcomes (e.g., see Figure 1.7). However, problems like Cardano’s (Example 1.1), involve larger sample spaces and are less straightforward. To tackle these more difficult problems, we’ll need tools from combinatorics, the branch of mathematics concerned with counting.
Like probability, combinatorics is a tricky subject that can be daunting and counterintuitive at first. But, with a principled approach and some practice, solving combinatorics problems becomes a routine and even fun endeavor!
2.1 The Fundamental Principle of Counting
We illustrate the central idea behind counting with a simple example.
Our solution in Example 2.1 is an example application of the fundamental principle of counting.
In Example 2.1, we made outfits by performing three actions: choosing a pair of shoes, choosing a pair of pants, and choosing a shirt. Each way of performing the actions results in a unique outfit, and each possible outfit results from a unique way of peforming the actions. Thus, the number of different outfits is the same as the number of unique ways we can perform these actions. Since there are \(3\) ways to perform the first action, then always \(2\) ways to perform the second, and then always \(4\) ways to perform the third, Theorem 2.1 tells us that there are \(2 \times 3 \times 4 = 24\) unique ways of doing so. Note if we imagined picking our shoes, pants, and shirt in a different order (e.g., first pick the pants, then shirt, then shoes), we would’ve arrived upon the same answer.
2.2 Selecting Items from a Collection
When solving combinatorics problems, we often need to know the number of ways we can select \(k\) items from a collection of \(n\) unique items. In this section, we discuss four classic variations of this problem. These variations arise from (1) whether we care about the order of selection or not and (2) whether we perform selection with or without replacement.
2.2.1 With Replacement, Order Matters
In our first variation, we’ll suppose that the order of selection matters (i.e., selecting item 1 and then item 2 is not the same as selecting item 2 and then item 1) and that we select items with replacement, meaning items can be selected multiple times.
As an illustrative example, suppose we want to select \(k = 2\) animals from the following collection of \(n=4\) animals:
We’ll record our selections as entries in an ordered tuple. To start, we select one of the four animals as our first animal:
Then, because we are selecting with replacement, we can still select any of the four to be our second animal, including possibly selecting the same animal again:
In total, we see that there are \(4 \times 4 = 16\) different ways to select the two animals.
What if we wanted to select a third animal? For each of these two-animal selections, there would still be \(4\) choices for the third animal, making for a total of \(4 \times 4 \times 4 = 64\) ways to select \(k=3\) animals.
The same reasoning applies when we want to make an ordered selection of \(k\) items from a size-\(n\) collection with replacement. There are \(n\) ways to select the first item, then again \(n\) ways to select the second item, and so on, until \(k\) items have been selected. Therefore, Theorem 2.1 tells us that there are \(n^k\) ways to select the \(k\) items.
Corollary 2.1 enables us to count the number of different possible outcomes an experiment that involves repeating a smaller experiment many times can have.
2.2.2 Without Replacement, Order Matters
We’ll now consider making an ordered selection of items without replacement, meaning that each item can only be selected once.
Again, suppose that we want to select \(k = 2\) animals from the following collection of \(n=4\) animals:
We select one of the four animals to be our first animal:
But now, because we are selecting without replacement, we cannot select the same animal again. For each of our first selections, there are only three animals we can select to be our second animal:
In total, we see that there are \(4 \times 3 = 12\) different ways to select the two animals.
What if we want to select a third animal? The third animal must be different from the previously two selected animals. Thus, for each of these two-animal selections, there are only \(2\) possible choices for the third animal, making for a total of \(4 \times 3 \times 2 = 24\) ways to select \(k=3\) animals .
Again, the same reasoning applies to the general case. Suppose we want to make an ordered selection of \(k\) items from a size-\(n\) collection without replacement. There are \(n\) ways to select the first item, then \(n-1\) ways to select the second item (because it must differ from the first item), then \(n-2\) ways to select the third item (because it must differ from the first two items), and so on, until \(k\) items have been selected. Therefore, Theorem 2.1 tells us there are \(n \times (n-1) \times \dots (n - k + 1)\) ways to select the \(k\) items.
Prior to formally stating the result, we recall that \(n!\) (pronounced “\(n\) factorial”) is defined to be
\[n! = n \times (n-1) \times \dots \times 1 \] when \(n\) is a positive integer, and \(0!\) is defined to be \(1\).
Corollary 2.2 enables us to count the number of ways we can order \(n\) objects. A particular arrangement or ordering of objects is referred to as a permutation of the objects.
The result from Example 2.3 informs us of how many outcomes there would be in a more general version of the random babies experiment from Example 1.6.
2.2.3 Without Replacement, Order Doesn’t Matter
Perhaps the most useful variation of our problem is when we make an unordered selection of items without replacement.
Again, we’ll consider the collection of \(n=4\) animals
but now we’ll consider making an unordered selection of \(k=3\) animals without replacement. We can make this selection by specifying a size-\(3\) subset of the animals, each possible one resulting from choosing an animal to leave out:
The approach of leaving out an animal only works when \(k=n-1\), and we’ll need a more general approach to tackle other cases. Recall from earlier that there are \(24\) different ways of making an ordered selection of \(k=3\) animals without replacement. Because there are \(3! = 6\) ways of ordering \(k = 3\) animals (see Example 2.3), we can partition the ordered selections into size-\(6\) groups that select the same animals (just in different orders). Each group corresponds naturally to one way of selecting \(k=3\) animals without order:
We see that there are \(6\) times as many different ordered selections as unordered selections, and therefore \(24/6 = 4\) different unordered selections of \(k=3\) animals.
What if we want to make \(k=2\) unordered selections? We know from before that there are \(12\) different ordered selections of two animals. Example 2.3 tells us that there are \(2!=2\) ways to order any two animals, and we can thus partition these ordered selections into size-\(2\) groups that share the same animals. Each group corresponds to a unique way of selecting \(k=2\) animals without order, and vice-versa. Therefore, there should be \(12/2 = 6\) unordered ways of selecting the \(k=2\) animals. We list them here:
This approach generalizes easily to any \(n\) and \(k\). Corollary 2.2 tells us that there are \(n!/(n-k)!\) ways to make an ordered selection of \(k\) items from a size-\(n\) collection without replacement. Because there are \(k!\) ways to order \(k\) animals (see Example 2.3), we can partition these ordered selections into size-\(k!\) groups that share the same animals. Each group corresponds to one unique way of making an unordered selection of \(k\) animals without replacement, and vice-versa. Therefore, there must be \(n!/((n-k)!k!)\) different ways of making an unordered selection of \(k\) items without replacement.
Prior to formally stating the result, we recall that, for two non-negative integers \(n \geq k\), \[{n \choose k} = \frac{n!}{(n-k)!k!}\] We refer to \(n \choose k\) as “\(n\) choose \(k\)” because making an unordered selection of \(k\) items without replacement from a size-\(n\) collection can be viewed as “choosing” \(k\) of the items.
Selecting items without replacement and without regard for ordering is a crucial step in many counting problems.
2.2.4 With Replacement, Order Doesn’t Matter
Finally, we consider the case where we select items with replacement and the order of selection doesn’t matter. Such selections are characterized by the number of times we select each item. For example, the \(10\) different ways to select \(k=2\) of the \(n=4\) animals
with replacement but without regard for order are given by the tables:
In general, it turns out that there are \({n + k - 1 \choose n-1}\) ways to make an unordered selection of \(k\) items from a size-\(n\) collection with replacement.
Corollary 2.4 tends to come up less in practice, but the “stars and bars” method used to prove it is itself instructive.
2.2.5 Summary
Table 2.1 summarizes the results from this section and will serve as a nice reference for when you’re solving combinatorics problems.
Order Matters | Order Doesn’t Matter | |
---|---|---|
Without Replacement | \(\frac{n!}{(n-k)!}\) | \(n \choose k\) |
With Replacement | \(n^k\) | \(n + k -1 \choose n-1\) |
2.3 Examples
With our new tools for counting, we can compute some interesting and non-trivial probabilities. To start, we give a correct solution to Cardano’s problem (Example 1.1) from Chapter 1.
Next, we examine a classic brainteaser: what is the probability that two people in a room share a birthday? The answer may be surprising!
Our last example comes from the poker, one of the world’s most popular gambling card games. We provide a brief introduction to poker for those who are unfamiliar with the game.
2.4 Exercises
Exercise 2.1 (Galileo’s Problem) Coming soon!