1
Strings
• A string is a finite sequence of characters. For instance,
abracadabra
and https
are strings of letters;
235711
is a string of numbers; and
MAT344
is a string of letters and numbers.
• The number of characters in a string is its length. Thus, abracadabra has length 11, while
MAT344 has length 6.
• Formally, let X be a set and let n ∈ N. (For us, N is the set of all positive integers.) An
X-string of length n is a function S : [n] → X where
[n] = {1, . . . , n}.
We usually write
S = x1 x2 · · · xn
or S = (x1 , x2 , . . . , xn )
to mean that xi = S(i) ∈ X for every i ∈ [n]. The elements x1 , . . . , xn are called the characters
of S.
• For instance, the string https is the same as the function S : [5] → {a, b, . . . , z} with
S(1) = h,
S(2) = t,
S(3) = t,
S(4) = p,
S(5) = s.
• Note that the order of the characters matters. For instance, https ̸= thpst.
• A binary string is a {0, 1}-string, such as 101101, 1110 and 0000001.
• Now, we are interested in counting strings. Let n ∈ N. How many binary strings of length
n are there?
Let x1 x2 · · · xn be an arbitrary binary string. There are two choices for each of the n characters
n
x1 , x2 , . . . , xn , and hence there are 2| × 2 ×
{z· · · × 2} = 2 strings in total.
n times
For instance, the binary strings of length 3 are 000, 001, 010, 011, 100, 101, 110, 111.
• More generally:
Theorem. Let X be a finite set. The number of X-strings of length n is |X|n .
Proof. For an X-string S = x1 x2 · · · xn of length n, there are |X| choices for each xi , i ∈ [n].
Thus, there are |X| × |X| × · · · × |X| = |X|n strings in total.
|
{z
}
n times
(This was not really a proof, though. If you want to be rigorous about it, you should do induction!)
Example. A standard Ontario license plate is of the form ABCD 123, with four letters
followed by three digits. So, the number of such license plates is
264 × 103 .
1
▲
2
Permutations
• A permutation is a string with no repeated characters. More precisely, given a set X and n ∈ N,
a permutation of X of length n is an X-string S = x1 x2 · · · xn such that xi ̸= xj whenever i ̸= j.
For instance, if X = {a, b, c, d}, then
abc,
ab,
a
are permutations of X of length 3, 2, and 1, whereas
aa,
aba,
bcb
are not permutations.
Example. The number of permutations of {A, B, . . . , Z} of length 5 is
26 × 25 × 24 × 23 × 22.
▲
Example. How many Ontario license plates have no repeated letters and no repeated digits?
There are
26 × 25 × 24 × 23
choices for the letter string and
10 × 9 × 8
choices for the digit string. Thus, the answer is
26 × 25 × 24 × 23 × 10 × 9 × 8.
▲
Example. How many such license plates have the property that at least one of the letter string
and the digit string has no repetition?
It is easier to count the complement. There are
264 − 26 × 25 × 24 × 23
letter strings with a repeated letter, and
103 − 10 × 9 × 8
digit strings with a repeated digit. Hence, the answer is
264 × 103 − 264 − 26 × 25 × 24 × 23 103 − 10 × 9 × 8 .
• Factorials: For a positive integer n, define
n! = n × (n − 1) × (n − 2) × · · · × 1,
and set
0! = 1.
10!
For instance, 26 × 25 × 24 × 23 = 26!
22! and 10 × 9 × 8 = 7! .
• We are also interested in counting permutations.
2
▲
Proposition. Let X be a set with |X| = m ≥ 0, and let 0 ≤ n ≤ m be an integer. The number
of permutations of X of length n is
P (m, n) = m × (m − 1) × (m − 2) × · · · × (m − (n − 1)) =
m!
.
(m − n)!
Proof. For a permutation S = x1 x2 · · · xn , there are m choices for x1 , then m − 1 choices for x2 ,
and so on, until there are m − (n − 1) choices for xn . Thus, there are P (m, n) permutations in
total.
For instance, if |X| = 11, then the number of permutations of X of length 6 is 11 × 10 × 9 × 8 ×
7 × 6 = 11!
5! .
Also, if n = m, then P (m, m) = m!. Thus, there are m! ways to order all the elements of an
m-element set.
Example. In how many ways can four different people be seated at a round table with seven
chairs, where rotations are regarded as the same?
First, suppose that we want to seat four people in seven chairs in a row in a classroom, and
call this a “linear configuration.” The number of linear configurations is P (7, 4). For a fixed
cyclic configuration of these four people around a table with seven chairs, all seven rotations will
correspond to the same cyclic configuration. So, the answer is
P (7, 4)
7!
=
= 5! = 120.
7
7 × 3!
▲
Example. The word TORONTONIAN has 11 letters. How many 11-letter words can be formed
using exactly these letters?
The number of permutations of 11 distinct letters is 11!. But, in the word TORONTONIAN,
there are two T’s, three O’s, and three N’s that are identical, and so the permutations of the
letters within each of these three groups do not produce a new word. Thus, the answer is:
11!
.
2! × 3! × 3!
▲
Exercise.
How many 11-letter words can be formed using exactly the letters from the word TORONTONIAN and with no two consecutive vowels?
3
Combinations
• A combination of size k of a finite set X is a subset of X with k elements, also called a k-subset.
For instance, if X = [5] = {1, 2, 3, 4, 5}, then
{1, 2, 3},
{1, 2, 4},
{1, 2, 5},
{1, 3, 4},
{1, 3, 5},
{1, 4, 5},
{2, 3, 4},
{2, 3, 5},
{2, 4, 5},
{3, 4, 5}
are combinations of X of size 3. There are 10 such combinations.
3
• We are interested in counting combinations. Let X be a set with |X| = n, and let 0 ≤ k ≤ n.
The main idea is to first count the permutations of X of length k. There are P (n, k) such
permutations. Every combination of X of size k gives rise to exactly k! of these permutations,
one for each ordering of its k elements. Thus,
P (n, k) = k! × (number of combinations of X of size k).
Hence, the number of combinations of X of size k is
P (n, k)
n!
=
.
k!
k!(n − k)!
5!
For instance, the number of combinations of [5] of size 3 is 3!2!
= 10, as expected. In general,
Proposition. Let X be a finite set with |X| = n, and let 0 ≤ k ≤ n be an integer. The number
of combinations of X of size k is
P (n, k)
n!
=
.
k!
k!(n − k)!
This number is denoted by
n
n!
=
,
k
k!(n − k)!
read “n choose k,” and is called a binomial coefficient.
Note that
n!
n
n
n!
=
=
.
=
k!(n − k)!
(n − k)!(n − (n − k))!
n−k
k
In other words, the number of k-subsets of [n] is, on one hand, the same as the number of ways to
choose k elements from [n] to put in the subset, and, on the other hand, the same as the number
of ways to choose n − k elements from [n] to not put in the subset.
4
Combinatorial proofs
• The main idea behind a combinatorial proof is double-counting: to count the same quantity in
two different ways and deduce that the two resulting counts are equal.
Example. Give a combinatorial proof that for every n ∈ N, we have
1 + 2 + ··· + n =
n(n + 1)
2
and 1 + 3 + · · · + (2n − 1) = n2 .
Here are proofs by picture (for n = 5). We double-count the number of dots in each array.
4
Example. For all integers 1 ≤ k ≤ n − 1, we have
n
n−1
n−1
=
+
.
k
k
k−1
This is doable by algebra. But here is a combinatorial proof: We count the number of subsets of
[n] of size k in two different ways. On one hand, the answer is nk .
On the other hand, we divide the subsets into two groups:
– those that do not contain n. Each such
subset is in fact a subset of [n − 1] of size k. Therefore,
the number of such subsets is n−1
.
k
– those that contain n. Each such subset consists
of n together with a subset of [n − 1] of size
k − 1. So the number of such subsets is n−1
k−1 .
n
n−1
n−1
Thus,
=
+
. ▲
k
k
k−1
n X
n
Example. For every n ∈ N, we have
= 2n .
k
k=0
We double-count the number of binary strings of length n. On one hand, the answer is 2n . On
the other hand,
for each k ∈ {0, 1, . . . , n}, the number of binary strings of length n with exactly
n
k ones is k (once we choose the positions of the k ones, the remaining n − k characters should
be all zeroes). Summing over all possible values of k ∈ {0, 1, . . . , n}, we get
n X
n
n
2 =
. ▲
k
k=0
Exercise.
n
X
n
Prove that for every n ∈ N, we have
k
= n2n−1 .
k
k=0
Example. For every n ∈ N, we have
n 2
X
n
k=0
k
=
2n
.
n
This one is not that easy to do by algebra! But here is a combinatorial
proof: We count the
2n
number of n-subsets of [2n]. On one hand, the answer is n . On the other hand, divide [2n]
into two sets of size n: the set {1, 3, . . . , 2n − 1} of odd numbers, and the set {2, 4, . . . , 2n} of
even numbers. Now, fix 0 ≤ k ≤ n, and consider those n-subsets of [2n] that contain exactly k
odd elements. Each such subset then must contain exactly n − k even elements. So, there are
2
n
n
n
=
k
n−k
k
such n-subsets of [2n]. Summing over all possible values of k, we obtain
2 2
2 X
n 2
2n
n
n
n
n
=
+
+ ··· +
=
. ▲
n
0
1
n
k
k=0
5
Exercise.
2
n
X
n
2n − 1
Prove that for every n ∈ N, we have
k
=n
.
k
n−1
k=0
5
The ubiquitous nature of binomial coefficients
Here we discuss some interesting applications of the binomial coefficients.
• Distributing identical objects, choosing with repetition, linear equations: Consider
the following problems:
1. How many binary strings of length 9 are there with exactly 2 ones?
2. In how many ways can we distribute 7 identical apples among 3 people?
3. In how many ways can we choose 7 hats from a store with 3 types of hats? (So, some types
are going to be repeated among the choices.)
4. How many solutions are there to the equation
x1 + x2 + x3 = 7,
x1 , x2 , x3 ∈ Z,
x1 , x2 , x3 ≥ 0.
Our goal is to observe that these four problems are all equivalent. In fact, it is easily seen that
the second and the third problems are equivalent to the fourth problem.
Let’s now argue that the first problem and the second problem are equivalent: We can represent
the apples by 7 zeroes in a row, and then insert two ones in between to divide them among the
three people. For instance, a distribution in which the three people receive 2, 4, and 1 apples,
respectively, is represented by the binary string 001000010 of length 9 with exactly 2 ones.
Note that 2 ones may be next to each other, or may appear before or after all the zeroes; this
simply means that one of the people receives no apples. So, a distribution is determined by
choosing the positions
of the
2 ones among 9 positions (and the other 7 will go to zeroes). Thus,
7+2
the answer is 7+2
=
= 36.
2
7
More generally, the same ideas show that:
Theorem. For all k, n ∈ N,
– the number of ways to distribute k identical objects among n people;
– the number of solutions to the equation
x1 + x2 + · · · + xn = k,
x1 , x2 , . . . , xn ∈ Z,
x1 , x2 , . . . , xn ≥ 0;
– the number of ways to choose k objects from n types of objects, with repetition allowed;
are all equal to the number of binary strings of length k + n − 1 with exactly n − 1 ones, which is
k+n−1
.
n−1
6
Example. In how many ways can we distribute 7 identical apples among 3 people if everyone
must receive at least one apple?
Since everyone receives at least one apple, the 2 ones must be placed in the 6 gaps between the
7 zeroes. Thus, the answer is 62 = 15.
Another approach is that we want the number of solutions to the equation
x1 , x2 , x3 ∈ Z,
x1 + x2 + x3 = 7,
xi ≥ 1.
We can do a change of variable: for each i ∈ {1, 2, 3}, let x′i = xi − 1. Then, we want the number
of solutions to the equation
x′1 + x′2 + x′3 = x1 + x2 + x3 − 3 = 4
where x′1 , x′2 , x′3 ∈ Z, x′i = xi − 1 ≥ 0. So by the above theorem, the answer is
4+3−1
3−1
6
2 . ▲
=
Example. In how many ways can we distribute 10 identical apples among Alice, Bob and Chase
if Alice must receive at least 2 apples and Bob must receive at least one apple?
We want the number of solutions to the equation
x1 + x2 + x3 = 10,
x1 , x2 , x3 ∈ Z,
x1 ≥ 2,
x2 ≥ 1,
x3 ≥ 0
Let’s do the change of variables again: let x′1 = x1 − 2 and let x′2 = x2 − 1 (we do not need to
change x3 ). So, we want the number of solutions to the equation
x′1 + x′2 + x3 = x1 + x2 + x3 − 3 = 7
where x′1 , x′2 , x3 ∈ Z, x′1 , x′2 , x3 ≥ 0. So by the above theorem, the answer is
▲
7+3−1
3−1
=
9
2
= 36.
Example. In how many ways can we buy 8 hats from a store with 4 types of hats, such that we
get at most 2 hats of type four?
For i = 1, 2, 3, 4, let xi be the number of hats of the ith type that will be bought. Then, we are
counting the solutions to the equation
x1 + x2 + x3 + x4 = 8,
x1 , x2 , x3 , x4 ∈ Z,
x1 , x2 , x3 , x4 ≥ 0,
with the extra constraint that x4 ≤ 2. Now, the number of all solutions is 8+4−1
= 11
4−1
3 . Also,
by the change-of-variables trick, the number of solutions
with
x4 ≥ 3 – which is the opposite of
8
11
8
what we want – is 5+4−1
=
.
So,
the
answer
is
−
4−1
3
3
3 . ▲
Example. Count the number of solutions to the inequality
x1 + x2 + x3 + x4 ≤ 356,
x1 , x2 , x3 , x4 ∈ Z,
x1 , x2 , x3 , x4 ≥ 0.
Here is the trick: the answer is the same as the number of solutions to the equation
x1 + x2 + x3 + x4 +x5 = 356,
x1 , x2 , x3 , x4 , x5 ∈ Z,
x1 , x2 , x3 , x4 , x5 ≥ 0.
Indeed, given x1 + x2 + x3 + x4 ≤ 356, we can set x5 = 356 − (x1 + x2 + x3 + x4 ) ≥ 0, and
conversely every solution to the equation gives a solution to the inequality. So, the answer is
356 + 5 − 1
360
=
. ▲
5−1
4
7
• Lattice paths: A lattice path is a sequence (m1 , n1 ), (m2 , n2 ), . . . , (mt , nt ) of pairs of integers
such that for every i ∈ [t − 1], either
mi+1 = mi + 1
and ni+1 = ni
or
mi+1 = mi
and ni+1 = ni + 1.
In other words, at each step we move one unit either to the right or upward.
Example. Let m, n ≥ 0 be integers. What is the number of lattice paths from (0, 0) to (m, n)?
Every such path consists of exactly m horizontal steps to the right and n vertical steps upward
– it is just a matter of order. So, we can encode the path by an R, U -string of length m + n
containing exactly m R’s and n U’s. It follows that the number of such paths is
(m + n)!
m+n
m+n
=
=
. ▲
m!n!
m
n
Example. How many lattice paths are there from (0, 0) to (11, 11) that pass through (4, 5)?
Note that each such lattice path consists of a lattice path from (0, 0) to (4, 5), followed by a
lattice path from (4, 5) to (11, 11). So, the answer is
9 13
. ▲
4
6
Example. How many lattice paths are there from (0, 0) to (11, 11) that pass through (4, 5) but
do not pass through (7, 7)?
The number of lattice
paths from (0, 0) to (11, 11) that pass through (4, 5), as seen in the previous
9 13
example, is 4 6 . Similarly, the number of lattice paths from (0, 0) to (11, 11) that pass through
both (4, 5) and (7, 7) is 94 52 84 . Therefore, the answer is
9 13
9 5 8
−
. ▲
4
6
4 2 4
Example. How many lattice paths from (0, 0) to (n, n) never go above the diagonal y = x?
Let A be the set of all lattice paths from (0, 0) to (n, n), let B be the set of those paths which
never go above the line y = x, and let
C = A \ B be the set of those which do. We know from
the previous example that |A| = 2n
n . Therefore, we have
2n
|B| + |C| = |A| =
.
n
So it remains to find |C|.
Let s = s1 s2 · · · s2n be the R, U -string corresponding to a path in C. Since this path goes above
the line y = x, it follows that, scanning s character-by-character from s1 to s2n , there comes a
time when there are more U ’s than R’s. Let i ∈ [2n] be the minimum such that among s1 , . . . , si ,
there are more U ’s than R’s. By the minimality of i, for some j, there are exactly j R’s and
j + 1 U ’s among s1 , . . . , si , and so i = 2j + 1.
Construct a new string se by keeping s1 , . . . , si unchanged and switching every R and U after si .
That is,
se = s1 s2 · · · si si+1 · · · s2n ,
8
where R = U and U = R. The number of R’s in se is
j + n − (j + 1) = n − 1,
and the number of U ’s is
j + 1 + (n − j) = n + 1.
Thus, se corresponds to a lattice path from (0, 0) to (n − 1, n + 1).
Conversely, every lattice path from (0, 0) to (n − 1, n + 1) must at some point go above the
diagonal y = x because n + 1 > n − 1. Let i be the first step at which this happens, and switch
all R’s and U ’s after the ith step. This gives a path in C, and the two operations are inverses of
each other.
s = RRU RU RU U |{z}
U RU RRU RU
s̃ = RRU RU RU U |{z}
U U RU U RU R
i
i
Hence, we have a 1-to-1 correspondence between C and the set of all lattice paths from (0, 0) to
(n − 1, n + 1). Therefore,
2n
2n
2n
1
2n
|C| =
⇒ |B| =
−
=
. ▲
n+1
n
n+1
n+1 n
1
2n
The number Cn =
is called the nth Catalan number.
n+1 n
6
The Binomial Theorem
• The binomial coefficients naturally appear in the expansion of powers of x + y:
Theorem (Binomial Theorem). For all n ∈ N and x, y ∈ R, we have
n
(x + y) =
n X
n
k=0
z
n factors
}|
k
{
Proof. We have (x + y)n = (x + y)(x + y) · · · (x + y).
xn−k y k .
Each term of the expansion comes from
choosing either x or y from each factor.
If
x
is
chosen
n
− k times and y is chosen k times, this
n
n−k
k
contributes x
y . There
are k ways to choose the k factors from which we take y. So, the
coefficient of xn−k y k is nk .
9
5 2
1 (−2)3 = −80.
3
P
As an immediate consequence, we recover the identity nk=0 nk = 2n , since
For instance, the coefficient of x2 y 3 in (x − 2y)5 is
n
n
2 = (1 + 1) =
n X
n
k=0
k
1
n−k k
1 =
n X
n
k=0
k
.
Exercise.
n
X
n
Use the binomial theorem to prove that for every n ∈ N, we have
k
= n2n−1 .
k
k=0
7
Multinomial Coefficients
• Suppose we have 8 positions and want to fill 3 of them with red dots and 5 of them with blue
dots. Equivalently, we make a R, B-string of length 8 with three R’s and five B’s. There are
8!
=
3!5!
8
8
=
5
3
ways to do this: once we choose the positions of the R’s, the B’s are also determined.
What if we have more than two colors? By the same argument, for instance, if we have 16
16!
positions and want to place 8 red, 5 blue and 3 green dots, the answer is 8!5!3!
.
More generally,
Theorem. Let r, n ∈ N and let k1 , k2 , . . . , kr ≥ 0 be integers such that n = k1 + k2 + · · · + kr .
The number of ways of partitioning a set X of size n into an ordered r-tuple (A1 , A2 , . . . , Ar ) of
pairwise disjoint subsets such that |Ai | = ki for every i ∈ [r] is
This number is denoted by
n
k1 , k 2 , . . . , k r
n!
.
k1 !k2 ! · · · kr !
and is called a multinomial coefficient.
1
Proof. There are kn1 choices for A1 . Once A1 is chosen, there are n−k
choices for A2 . Once
k2
n−k1 −k2
choices for A3 . Iterating this process, the number of ways
A1 , A2 are chosen, there are
k3
to create the ordered partition (A1 , A2 , . . . , Ar ) is equal to
kr
}|
{
z
n − k1 − k2
n
n − k1
n − k1 − k2 − · · · − kr−1
···
k3
k2
k1
kr
(
((
n!
(n
−k
n!
(n(
−(k(
1 )!
1 − k2 )!
(
=
×
.
×
( × ··· =
(
(
(
(
(
(
(
(
(k2 − k3 )!
k1 !
(n
− k1 )! k2 !(
k1 !k2 ! · · · kr !
(n(
−(k1 − k2 )! k3 !(n(
−(k(
1−
(
10
• The binomial theorem also has the following generalization:
Theorem (Multinomial Theorem). For all n, r ∈ N and x1 , . . . , xr ∈ R, we have
(x1 + x2 + · · · + xr ) =
n
X
k1 +···+kr =n
k1 ,...,kr ≥0
n
xk1 xk2 · · · xkr r .
k1 , k 2 , . . . , k r 1 2
Proof. We have
n factors
z
}|
{
(x1 + x2 + · · · + xr ) = (x1 + x2 + · · · + xr )(x1 + x2 + · · · + xr ) · · · (x1 + x2 + · · · + xr ) .
n
Therefore, each term of the expansion is of the form xk11 xk22 · · · xkr r where k1 , . . . , kr ≥ 0 are
integers with k1 + · · · + kr = n, and the number of times this term appears in the expansion is
equal to the number of ordered partitions (A1 , . . . , Ar ) of the set of all n factors, where for each
i ∈ [r], we have |Ai | = ki , and the term picks xi from all the factors in Ai . So, the coefficient of
xk11 xk22 · · · xkr r is k1 ,k2n,...,kr .
For instance, the coefficient of x9 y 3 z 5 in (2x + y − 5z)17 is
17
× 29 × 13 × (−5)5 .
9, 3, 5
Exercise.
Show that the coefficient of x8 y 4 in 2xy − x2 + y 2
11
6
is 15.
0
You can add this document to your study collection(s)
Sign in Available only to authorized usersYou can add this document to your saved list
Sign in Available only to authorized users(For complaints, use another form )