1. Set notation and basic counting#
Combinatorics is all about counting objects. We introduce the notation for "containers" of objects a.k.a. sets and define operations on sets. Next, we study the first two counting methods: the sum rule and product rule.
1.1 Set notation#
A set is a collection of distinct objects. We usually denote a set by a capital letter, such as
Because a set records membership rather than order,
is the set of even integers, where denotes the integers. If
, then
The symbol
1.1.1 Set operations#
Let
The intersection of
and consists of the elements belonging to both sets:
The union of
and consists of the elements belonging to at least one of the sets:
The set difference, also called the relative complement, consists of the elements of
that do not belong to :
The Cartesian product of two sets
and is the set of ordered pairs with chosen from and chosen from :
Two sets are disjoint if they have no elements in common; equivalently,
.
If
1.1.2 Cardinality and inclusion#
For a finite set
We write
We write
1.1.3 Logical quantifiers and summation notation#
The symbol
means that every element of is nonnegative. says that at least one element of has square .
The symbol
The notation
An important formula we will prove later in the course is
1.2 Introduction to counting#
1.2.1 What is a counting problem?#
A counting problem asks for the cardinality of a finite set. The first task is therefore to identify that set. We need to know:
what one outcome is;
when two outcomes are considered different;
what restrictions an outcome must satisfy.
Consider two ordinary six-sided dice, one red and one blue. How many ways can one obtain a roll whose sum is
Because the dice are distinguished by color, an outcome is an ordered pair
Now let us change the problem in two different ways:
Variant 1 Consider two ordinary six-sided dice, one red and one blue. If a roll results in both dice having the same number, we reject the roll and try again.
How many ways can one obtain a roll whose sum is
Variant 2 Consider two ordinary six-sided dice, one red and one blue. If a roll results in both dice having the same number, we reroll the red die until the two numbers are not the same. How many ways can one obtain a roll whose sum is
.
It is not fully clear what the problem is asking us. If a "way" records the entire history of rolls, then, in variant 1, rolling
However, if we count only the final accepted ordered pair, then the problem becomes simple:
This example shows that it is important to clearly understand what the problem, written in English, means at a precise mathematical level.
Next, we will develop tools that will help us solve the following challenge problem. You can try to solve it on your own, or come back to it once we covered the necessary counting techniques. For now, you should read and understand it, and use it as a motivating example for the things we will learn next
A company has 20 employees and they need to form a committee of 4 people. How many ways can this be done?
A company has 20 employees and they need to form a committee of 4 people: 1 chair and 3 other general committee members. How many ways can this be done?
1.2.2 The sum rule#
Suppose one object is chosen from either of two finite sets
If
A single character may be either a lowercase English letter or a decimal digit. How many allowed characters are there?
Solution:
Let
If uppercase English letters are also allowed, let
The same reasoning extends to any finite number of cases.
Let
Then
We can rephrase the sum rule in terms of outcomes of procedures, rather tnan sets.
Suppose the outcomes of a task are divided into mutually exclusive cases
In the character example, identify
Disjointness is important!
In the next example, let us see why checking disjointness is very important.
Suppose Amazon sells three brands of juice and Walmart sells five brands. How many different brands can a shopper choose from if they may shop at either store?
Wrong solution:
The number of brands at amazon is
The problem with this solution is that if the stores carry some of the same brands, adding gives duplicates.
Before using the sum rule, check that the cases are disjoint and that together they include every outcome being counted.
1.2.3 The product rule#
Suppose an outcome is constructed through a fixed sequence of choices. If
every complete sequence of choices produces exactly one outcome
different choices produce different outcomes,
the number of options at each step of the sequence of choices is fixed and does not depend on the choices made in the other steps,
then the total number of outcomes is obtained by multiplying the numbers of options at each step.
A two-character string is an ordered sequence a-z.
Solution:
There are
The argument allows multiple steps and also allows the specific choices at each step to depend on the other choices made. It is important that the total number of choices at each step remains the same.
Suppose every outcome is constructed uniquely by a fixed sequence of
How many strings of length 3 made with letters a-z are there?
Solution:
A string can be specified by first choosing the letter in position 1 (step 1), then the letter in position 2 (step 2), then in position 3 (step 3).
For each of the steps there are 26 choices. Every string is obtained from exactly one sequence of such choices (different choices give different strings),
so the product rule gives
How many strings of length 3 made with letters a-z are there such that no letter appears more than once?
Solution: A string can be specified by first choosing the letter in position 1 (step 1), then the letter in position 2 (step 2) and making sure that it is not the same as the letter chosen in position 1, then choosing a letter in position 3 (step 3) while making sure that it is not the letter chosen in position 1 nor in position 2.
Step 1: 26 choices
Step 2: 25 choices (26 letters except the one chosen in step 1)
Step 3: 24 choices (26 letters except the one chosen in step 1 and the one chosen in step 2)
Every valid string is obtained from exactly one sequence of such choices (different choices give different strings),
so the product rule gives
It is important to note that in this example the specific choices at steps 2 and 3 depend on the choices made in the previous step but the number of possible choices does not! This allows us to apply the product rule.
How many strings of length 3 made with letters a-z are there such that no letter appears more than twice?
Wrong/Incomplete solution: A string can be specified by first choosing the letter in position 1 (step 1), then the letter in position 2 (step 2) (without any restrictions, because the second letter can be the same as the first one and not lead to a forbidden outcome)
In step 3 we choose the letter for position 3.
Step 1: 26 choices
Step 2: 26 choices
Step 3: ?? choices (it depends, if in step 1 and 2 we chose the same letter then we cannot choose it again so we have 25 choices; if we did not choose the same letter we can choose any letter, so 26 choices. )
Possible correct solution: A string can be specified by choosing by first choosing the letter in position 1 (step 1), then the letter in position 2 (step 2), then the letter in position 3 (step 3), all while making sure not to choose a string with the same letter repeated 3 times.
Let us distinguish 2 cases:
D: In step 1 and step 2 we choose different letters
S: In step 1 and step 2 we choose the same letter
By the sum rule, the total amount of strings is going to be
Let us compute
Step 1: 26 choices
Step 2: 25 choices (cannot be the same as step 1)
Step 3: 26 choices (since the first are different, there are no restrictions)
so
Let us compute
Step 1: 26 choices
Step 2: 1 choice (must be the same letter as step 1)
Step 3: 25 choices (since the first two letters are the same we cannot choose that letter again)
so
The final answer is
1.3 Strings: an important type of counting problems#
The preceding examples illustrate an important type of counting problem: counting ordered sequences of symbols.
Let
Using set notation, a string of length
The position of each symbol is important. For example, ab and ba are different strings. Two strings are equal precisely when they have the same symbol in every position. Repetition is allowed unless the problem states otherwise.
There is also one string of length
Let
There are
Let 042 is included.
Suppose now that no symbol may occur more than once.
Let
When
Assuming that
If
Let 042 is included.