Skip to main content

Section 6.2 Combinatorics

Preview Activity 6.2.1.

While counting seems like a very basic mathematical task, combinatorics is the mathematics of counting quantities that are difficult to manage by hand (or even by computer).

(a)

Explain how you'd help a five-year-old count how many numbers in the set \(\{3,4,5,\dots,24,25\}\) end with a \(2\text{,}\) \(7\text{,}\) or \(9\text{.}\)

(b)

How many of the counting numbers in the set \(\{3,4,5,\dots,2024,2025\}\) end with a \(2\text{,}\) \(7\text{,}\) or \(9\text{?}\) You probably don't want deal with over two thousand numbers by hand, so first fix the list comprehension [x for x in range(21,50) if x%10 in [3,8,9]] to produce a list of all such numbers. Then use the len() tool to count them.

(c)

Without using technology, how many numbers in the set \(\{1,2,\dots,10\}\) end with a \(2\text{,}\) \(7\text{,}\) or \(9\text{?}\) How can you use that result to find how many numbers in the set \(\{1,2,\dots,100\}\) end with those digits? What about the set \(\{1,2,\dots,1000\}\text{?}\)

(d)

Use the ideas from the previous task to count the numbers in the set \(\{11,12,\dots,1008\}\) that end with a \(2\text{,}\) \(7\text{,}\) or \(9\text{.}\) Then confirm your result using technology.

Activity 6.2.2.

One of the most useful counting tools in mathematics is the multiplication principle. This principle is used when all the items to be counted come from a sequence of choices. If each item is made by making a choice from \(a\) things, then a choice from \(b\) things, then a choice from \(c\) things, and so on, then the total number of items is given by the product:

\begin{equation*} a\times b\times c\times \cdots \end{equation*}

For example, suppose that a breakfast must include either eggs \(E\text{,}\) sausage \(S\text{,}\) or pancakes \(P\) to eat, and either coffee \(c\) or juice \(j\) to drink. Then this six possible breakfasts are eggs/coffee, eggs/juice, sausage/coffee, sausage/juice, pancakes/coffee, and pancakes/juice. Symbolically, these choices are:

\begin{equation*} Ec,Ej,Sc,Sj,Pc,Pj \end{equation*}

However, this number six can be computed without listing out every choice. This is because there are \(3\) choices for food and \(2\) choices for drink, yielding \(3\times 2=6\text{.}\)

(a)

Suppose for a fancy dinner you are given four options as an appetizer, six options as an entree, three options as a beverage, and two options as a dessert. How many different dinners are possible?

(b)

Suppose you could choose an appetizer or a dessert, but not both. How many different dinners are possible in that scenario?

(c)

What if instead you consider the choice to skip any part of the meal, holding the appetizer, entree, beverage, and/or dessert. How many dinners are possible in that case?

(d)

What is the size of the sample space for the experiment of rolling a D6, then flipping a coin, then drawing a card from a shuffled 52-card deck?

Activity 6.2.3.

The multiplication principle is used to count permutations: different arragements of symbols. For example, there are six permutations of the letters \(A,B,C\text{:}\)

\begin{equation*} ABC,ACB,BAC,BCA,CAB,CBA \end{equation*}

The multiplication principle counts these six as follows: there are \(3\) choices for the first letter, then \(2\) remaining choices for the second letter, and finally only \(1\) choice for the final letter, which results in \(3\times 2\times 1=6\text{.}\)

(a)

How many permutations are there for the letters \(W,X,Y,Z\text{?}\)

(b)

A list of permutations of the letters \(A,B,C\) may be obtained in SageMath (and Python) by writing import itertools and abcs = ["".join(p) for p in itertools.permutations(["A", "B", "C"])]. Then len(abcs) would equal 6.

Create a list of all strings that are formed by the letters in ["w","x","y","z"]. Print out these strings, and count them using len() to confirm your calculation in the previous task.

(c)

Expressions such as \(5\times 4\times 3\times 2\times 1\) are commonplace in mathematics, so we use the factorial operation as a shorthand:

\begin{equation*} N! = N\times \cdots\times 3\times 2\times 1 \end{equation*}

In SageMath, factorial(5) may be used to compute \(5\times 4\times 3\times 2\times 1=120\text{.}\)

Use a Code cell to count how many permutations are there for the letters of the alphabet \(A\) to \(Z\text{.}\)

(d)

Attempting to check this by computer by actually listing out every permutation as you did for ["w","x","y","z"] would be difficult. (Try it!) What causes this difficulty? What does that suggest about the relationship between mathematics and computer science?

Activity 6.2.4.

The multiplication principle is useful when considering password security. Often, administrators make certain requirements for users' passwords. These requirements affect the number of different possible passwords, as well as the probability that a randomly chosen password would match a password that meets these requirements.

(a)

How many five-character passwords use only uppercase letters?

(b)

How many five-character passwords use only alphanumeric characters? That is, uppercase letters, lowercase letters, or digits, where htr12 is considered different than the password HtR12.

(c)

How many five-character passwords use only alphanumeric characters, when repeated characters are not allowed? (That is, both aabcd and abacd are both not allowed.)

(d)

How many five-character passwords use only alphanumeric characters, when consecutive repeated characters are not allowed? (That is, aabcd is not allowed, but abacd is okay.)

(e)

Consider the experiment where a five-character password is generated using alphanumeric characters (with repeated characters allowed). What's the probability that such a password would only have uppercase letters? Use the n() tool to obtain a decimal approximation.

(f)

The code in 6.2.1 simulates generating 100 thousand passwords and checking if the password contains all uppercase letters. Run the code as-is to confirm that it illustrates what you found in the previous task. Then annotate the code with # comments that explain how it works.

# Add comments like this throughout that explain how this code works.
points = []
all_upper_count = 0
for trial in range(1,100001):
    all_upper = True
    for _ in range(5):
        next_character = randrange(62)
        if next_character >= 26:
            all_upper = False
    if all_upper:
        all_upper_count += 1
    ex_prob = all_upper_count/trial
    points.append( (trial,ex_prob) )

show(
    line(points, color="blue")+line([(1,0.012969),(100000,0.012969)], color="red"),
    axes_labels=["Trials","Exp. Prob."],
)
Listing 6.2.1. Simulate choosing random passwords 100K times

Exercises Exercises

1.

Suppose than an ice cream shop offers single-scoop ice cream cones with a choice of fifty-seven flavors of ice cream, and the choice of a sugar cone, a dipped cone, or a waffle cone. How many different single-scoop ice cream cones does this shop offer?

2.

How many double-scoop cones does this shop offer?

3.

What is the size of the sample space for rolling three D8 dice (dice with eight different sides)?

4.

Create a Code cell that displays all the permutations of the letters \(A,E,I,O,U\text{.}\)

5.

How many permutations are there for the letters \(A,E,I,O,U\text{?}\) Show how to answer this question mathematically, and using technology.

6.

How many six-character passwords use only lowercase letters, digits, and the symbols !, ?, and #?

7.

How many six-character passwords use only lowercase letters, digits, and the symbols !, ?, and #, assuming no character is allowed to be repeated?

8.

What is the probability that a password generated to use six letters only uses consonants (for example, CbxYYt)?

9.

What is the probability that a password generated to use six letters never repeats a character? (For example, abCDeA doesn't repeat a character, but abCDea does.)