Counting? You already know how to count or you wouldn't be taking a college-level math class, right? Well yes, but what we'll really be investigating here are ways of counting efficiently. When we get to the probability situations a bit later in this chapter we will need to count some very large numbers, like the number of possible winning lottery tickets. One way to do this would be to write down every possible set of numbers that might show up on a lottery ticket, but believe me: you don't want to do this.
Basic Counting
We will start, however, with some more reasonable sorts of counting problems in order to develop the ideas that we will soon need.
OK, so now we know how to count possibilities using tables and tree diagrams. These methods will continue to be useful in certain cases, but imagine a game where you have two decks of cards (with 52 cards in each deck) and you select one card from each deck. Would you really want to draw a table or tree diagram to determine the number of outcomes of this game?
Let's go back to the previous example that involved selecting a meal from three appetizers and five main courses, and look at the second solution that used a table. Notice that one way to count the number of possible meals is simply to number each of the appropriate cells in the table, as we have done above. But another way to count the number of cells in the table would be multiply the number of rows (3) by the number of columns (5) to get 15. Notice that we could have arrived at the same result without making a table at all by simply multiplying the number of choices for the appetizer (3) by the number of choices for the main course (5). We generalize this technique as the basic counting rule:
The Basic Counting Rule can be extended when there are more than two categories by applying it repeatedly, as we see in the next example.
Permutations
In this section we will develop an even faster way to solve some of the problems we have already learned to solve by other means. Let's start with a couple examples.
In this example, we needed to calculate . This calculation shows up often in mathematics, and is called the factorial, and is notated !
Now we will consider some slightly different examples.
Note also that the order of selection was important in each example: for the three door prizes, being chosen first means that you receive substantially more money; in the Olympics example, coming in first means that you get the gold medal instead of the silver or bronze. In each case, if we had chosen the same three people in a different order there might have been a different person who received the $100 prize, or a different goldmedalist. (Contrast this with the situation where we might draw three names out of a hat to each receive a $10 gift certificate; in this case the order of selection is not important since each of the three people receive the same prize. Situations where the order is not important will be discussed in the next section.)
We can generalize the situation in the two examples above to any problem without replacement where the order of selection is important. If we are arranging in order items out of possibilities (instead of 3 out of 25 or 3 out of 8 as in the previous examples), the number of possible arrangements will be given by
If you don't see why is the right number to use for the last factor, just think back to the first example in this section, where we calculated to get In this case and so which is exactly the right number for the final factor.
Now, why would we want to use this complicated formula when it's actually easier to use the Basic Counting Rule, as we did in the first two examples? Well, we won't actually use this formula all that often, we only developed it so that we could attach a special notation and a special definition to this situation where we are choosing items out of possibilities without replacement and where the order of selection is important. In this situation we write:
In practicality, we usually use technology rather than factorials or repeated multiplication to compute permutations.
Combinations
In the previous section we considered the situation where we chose items out of possibilities without replacement and where the order of selection was important. We now consider a similar situation in which the order of selection is not important.
We can generalize the situation in this example above to any problem of choosing a collection of items without replacement where the order of selection is not important. If we are choosing items out of possibilities (instead of 3 out of 25 as in the previous examples), the number of possible choices will be given by, and we could use this formula for computation. However this situation arises so frequently that we attach a special notation and a special definition to this situation where we are choosing items out of possibilities without replacement where the order of selection is not important.
In the preceding Try it Now problem we assumed that the 19 members of the Defense Subcommittee were chosen without regard to party affiliation. In reality this would never happen: if Republicans are in the majority they would never let a majority of Democrats sit on (and thus control) any subcommittee. (The same of course would be true if the Democrats were in control.) So let's consider the problem again, in a slightly more complicated form:
Probability using Permutations and Combinations
We can use permutations and combinations to help us answer more complex probability questions
It is useful to note that these card problems are remarkably similar to the lottery problems discussed earlier.
Birthday Problem
Let's take a pause to consider a famous problem in probability theory:
Suppose you have a room full of 30 people. What is the probability that there is at least one shared birthday?
import random
random.seed(0) # <-- CHANGE the 0 to re-roll the simulation
DAYS = 365 # <-- CHANGE ME (ignoring leap years, as the book does)
def exact(n, days=DAYS):
"""P(at least one shared) = 1 - P(none), built the book's way: 365/365 * 364/365 * ..."""
if n > days:
return 1.0
none = 1.0
for k in range(n):
none *= (days - k) / days
return 1 - none
def simulate(n, trials, days=DAYS):
hits = 0
for _ in range(trials):
room = [random.randrange(days) for _ in range(n)]
if len(set(room)) < n: # a duplicate means a shared birthday
hits += 1
return hits / trials
TRIALS = 5_000 # <-- CHANGE ME: 100 is noisy, 20000 is slow but sharp
print("%8s %14s %14s %10s %s" % ("people", "exact", "simulated", "diff", "bar"))
print("-" * 66)
for n in (2, 3, 5, 10, 20, 23, 30, 50, 70): # <-- CHANGE this list
e, s = exact(n), simulate(n, TRIALS)
print("%8d %13.4f %13.4f %+10.4f %s"
% (n, e, s, s - e, "#" * int(round(e * 30))))
print("-" * 66)
print("(%s simulated rooms per row)" % "{:,}".format(TRIALS))
print()
half = next(n for n in range(1, DAYS + 2) if exact(n) > 0.5)
print("It takes only %d people for a shared birthday to be MORE likely than not." % half)
print("At 30 people it is %.1f%%; at 70 it is %.4f%%." % (exact(30) * 100, exact(70) * 100))
print()
print("Why intuition fails: you are not comparing your birthday to 29 others.")
print("You are comparing every PAIR, and 30 people make %d pairs." % (30 * 29 // 2))
print("Set DAYS = 30 (a month) and 8 people are already a coin flip.")
Take a guess at the answer to the above problem. Was your guess fairly low, like around 10%? That seems to be the intuitive answer (, perhaps?). Let's see if we should listen to our intuition. Let's start with a simpler problem, however.
This is a pretty small number, so maybe it makes sense that the answer to our original problem will be small. Let's make our group a bit bigger.
If you like to bet, and if you can convince 30 people to reveal their birthdays, you might be able to win some money by betting a friend that there will be at least two people with the same birthday in the room anytime you are in a room of 30 or more people. (Of course, you would need to make sure your friend hasn't studied probability!) You wouldn't be guaranteed to win, but you should win more than half the time.
This is one of many results in probability theory that is counterintuitive; that is, it goes against our gut instincts. If you still don't believe the math, you can carry out a simulation. Just so you won't have to go around rounding up groups of 30 people, someone has kindly developed a Java applet so that you can conduct a computer simulation. Go to this web page: http://statweb.stanford.edu/~susan/surprise/Birthday.html, and once the applet has loaded, select 30 birthdays and then keep clicking Start and Reset. If you keep track of the number of times that there is a repeated birthday, you should get a repeated birthday about 7 out of every 10 times you run the simulation.
Adapted from Math in Society by David Lippman, hosted on LibreTexts (math.libretexts.org) and licensed under CC BY-SA 3.0. Changes were made. License: CC-BY-SA-3.0.
These eBooks are a prerelease and are not yet certified conformant with WCAG 2.1 AA or ADA Title II. Every page is built against an automated accessibility gate, and the published editions will meet ADA Title II requirements when they release in late September 2026. If something is unusable, please tell us.