6.S095 Lecture 1 Notes: Basic Counting
6.S095 Lecture 1 Notes: Basic Counting
§1 Counting Techniques
This section introduces a variety of topics in discrete math with applications in probability.
We will discuss basic counting principles, permutations, combinations, and combinatorial
identities, and finally recurrences.
Lemma 1.1
(Addition principle) For n disjoint sets S1 , . . . , Sn , the cardinality of their union is:
Remark 1.2. The addition principle states that, if it is possible to split a counting
problem into disjoint cases, one can simply sum the counts from all of the cases.
Exercise 1.3. Convince yourself that it is necessary for the Si to be disjoint.
Example 1.4
Find the number of solutions in positive integers (x, y) to
x2 + y 2 < 25.
Solution. Let A be the set of all solutions and let Ai be the set of solutions where x = i.
By definition, the Ai must be disjoint. Furthermore, since x ≥ 5 =⇒ 25 ≤ x2 + y 2 , it
follows that A = A1 ∪ A2 ∪ A3 ∪ A4 . Then
A1 = {(1, 1), (1, 2), (1, 3), (1, 4)}
A2 = {(2, 1), (2, 2), (2, 3), (2, 4)}
A3 = {(3, 1), (3, 2), (3, 3)}
A4 = {(4, 1), (4, 2)},
1
6.S095 Lecture 1 Notes
We will now see how the multiplication principle can be used to find the cardinality of
sets’ Cartesian product.
Lemma 1.6
(Multiplication principle) Let Si for i ∈ [n] be finite sets. Then the size of their
Cartesian product can be expressed as
Remark 1.7. Essentially, the multiplication principle states that to count a process
with n independent choices, it suffices to count the number of cases for each choice and
multiply.
Definition 1.8. Let [n] denote the set {1, 2, . . . , n}.
Example 1.9
Suppose we have a collection of objects where each object is one of n types. Further
suppose there are ki objects of each type for i ∈ [n]. We wish to form families of
objects, where each family has exactly one object of every type. How many distinct
families can we create?
Solution. By the multiplication principle, there are ni=1 ki possible objects. Note that
Q
we disregard families with different orderings of the same n objects.
The following definition allows for a new way of counting. Suppose we wish to find |A|
for a complicated set A. If we can match elements of A one-on-one with elements of
another set B, it would suffice to count B. As shown below, a bijection can be used to
form this one-on-one matching between sets.
Definition 1.10 (Bijection). A function f : A → B between finite sets A and B is called
a bijection if the following statements hold:
These requirements guarantee that every element a ∈ A gets mapped to exactly one
element b ∈ B, which implies that |A| = |B|.
2
6.S095 Lecture 1 Notes
Example 1.11
Define the power set of a set A, denoted as P(A), to be the set containing all subsets
of A. What is P([n])?
Solution. Let B denote the set containing all binary strings of length n. By the multipli-
cation principle, |B| = 2n , as there are two choices for each of the n bits in the string.
Now let us form a bijection between P([n]) and B. Given a subset A ∈ P([n]), let
f map A to the string whose ith digit is 1 if i ∈ A and 0 otherwise for i ∈ [n]. This f
indeed defines a function from P(A) to B.
Lemma 1.13
There are n! permutations on [n].
Proof. Consider the process of constructing p one element of a time. There are n choices
for p(1). Regardless of the choice for p(1), there are n − 1 choices for p(2), since p(1) is
no longer a valid option. Repeating this process and using the multiplication principle
for independent choices proves the lemma.
Lemma 1.14
Given n distinct objects and k with k ≤ n, the number of linear orderings of length
n!
k in which no object is used more than once is (n−k)! .
Proof. As above, there are n choices for the first object, n − 1 for the second, up to
n − k + 1 for the k th . Thus there are
n!
n(n − 1) . . . (n − k + 1) =
(n − k)!
orderings.
n!
Remark 1.15. Sometimes, (n)k or Pn,k will be used to denote (n−k)! .
3
6.S095 Lecture 1 Notes
Example 1.16
For an even positive integer n, count the number of permutations of [n] such that
the sum of every two consecutive elements in the permutation is odd.
Solution. A permutation on n elements πn will have this property if and only if the
elements are alternating between even and odd. There are two cases depending on
n
whether the first element of π is odd. In either case, there are 2 ! ways to arrange the
n
even elements, and independently 2 ! ways to arrange the odd elements, leading to
n n
2 ! 2 ! permutations for each case by the multiplication principle. By the addition
principle, there are 2 n2 ! n2 ! total permutations.
Now we will discuss combinations, where we remove the linear ordering altogether and
consider only the constituents of the collection.
Lemma 1.18
For all nonnegative integers k ≤ n,
n (n)k n!
= = .
k k! k!(n − k)!
Proof. To choose an unordered k-element subset, first pick one of the (n)k k-element
linear orderings of [n]. For any such ordering, there are k! orderings with the same
constituents in different order, so each subset corresponds to k! linear orderings. Thus
there are (n)k n!
k! = k!(n−k)! orderings.
Example 1.19
Let n be a positive integer. Determine the number of solutions to x + y + z = n
where x, y, z are nonnegative integers.
Solution. Consider the following analogy: let n indistinguishable balls be lined up. Then
we can allocate some number of balls on the left to x, some number of balls on the right
to z, and the rest to y. Pictorially, we can imagine placing two dividers between the
balls: Conversely, any linear arrangement of the n balls and 2 dividers corresponds to a
distinct solution (x, y, z). Thus the number of solutions is just the number of ways to
choose the positions of the 2 dividers, which is n+2
2 .
4
6.S095 Lecture 1 Notes
Lemma 1.20
(Multinomial coefficients) Let A be a multiset of n objects and k types, where there
are ai identical objects of each type for i ∈ [k], and suppose we wish to count the
number of distinct linear orderings of A. Clearly n! will overcount the number of
permutations of A since a new linear order cannot be generated simply by exchanging
two identical objects. Instead, we must divide by the number of ways to permute
each type of object, and the number of permutations of these objects is
n! def n
= .
a1 ! · a2 ! · . . . · ak ! a1 , . . . , a n
Lemma 1.22
For positive integers n,
n n n
+ + ··· + = 2n .
0 1 n
Proof. By Example 1.11, the RHS counts the number of subsets of [n], and the LHS
counts the same by casework on the cardinality of the subset.
Proof. Consider the process of choosing a subset of size k + 1 of [n + 1]. On one hand,
n+1
there are k+1 such subsets. On the other hand, we can do casework as follows: if n + 1
n
is to be included in the subset, k more elements must be chosen from [n] in k ways.
n
Otherwise, all k + 1 elements must be chosen from [n] in k+1 ways. This establishes
the identity.
5
6.S095 Lecture 1 Notes
zero in these cases. With this extension, Pascal’s identity (and all subsequent identities)
hold as written.
Example 1.25
For positive integers n,
⌊n/2⌋
X n
= 2n−1 .
2k
k=0
Solution. The sum counts the number of subsets of [n] with even size. Notice that every
subset A of [n] with n ∈ A can be paired with A \ {n}. Every subset of [n] belongs to
exactly one of these pairs. But in each pair of subsets, exactly one has even size, so the
number of even size subsets is just the number of pairs which is 2n−1 .
Lemma 1.26
(Vandermonde’s Identity) For any m, n, k ∈ N0 , the following identity holds:
Xk
m+n m n
= .
k i k−i
i=0
Proof. We proceed with a counting argument. In an urn with m numbered red balls and
n numbered blue balls, the LHS counts the number of unordered subsets of size k from
all m + n balls. Another way to count is by casework on the the number of red balls,
k balls total, we draw i red balls and n − i blue balls, which can
denoted as i. To draw
be done in mi k−i n
ways. Summing over all cases i produces the RHS.
Proof. In the expansion of (x + y)n as (x + y)(x + y) . . . (x + y), each term will be chosen
by choosing either an x or a y from each x + y. Thus, (x + y)n will be a sum of terms of
the form xk y n−k . For a fixed k, it suffices to choose the k factors that yield an x, which
can be done in nk ways. This proves that the coefficient of the xk y n−k term will be nk ,
6
6.S095 Lecture 1 Notes
Proof. This proof is of a similar flavor to the binomial theorem, and is left as an
exercise.
For the case n = 2, it well-known that |A1 ∪ A2 | = |A1 | + |A2 | − |A1 ∩ A2 |. Indeed, we can
determine |A1 ∪ A2 | by counting the elements in A1 and A2 separately, then removing
the elements in A1 ∩ A2 that were counted twice in A1 and A2 . We now generalize this
principle to arbitrary n:
Although this equation may seem complex, the intuition is fairly straightforward: we
seek to ensure that each element in |A1 ∪ A2 ∪ . . . ∪ An | is counted exactly once, which
we accomplish by removing over-counts and adding back under-counts.
Example 2.2
A permutation on n elements πn is called a derangement if π(i) ̸= i for any i ∈ [n].
If Sn is the set containing all n-permutations, and D(n) denotes the number of
derangements in Sn , prove that
n
X n!
D(n) = (−1)k .
k!
k=0
7
6.S095 Lecture 1 Notes
D(n) = n! − |A1 ∪ A2 · · · ∪ An |.
In the formula for PIE, we must calculate |Ai1 ∩ Ai2 ∩ . . . Aik |, or the number of permuta-
tions that fix i1 , i2 , . . . , ik . But for any such permutation, it suffice to permute the n − k
remaining indices among themselves, so there are (n − k)! such permutations. Then since
there are nk such intersections represented in the sum,
n
X X
|A1 ∪ A2 ∪ . . . An | = (−1)k−1 (n − k)!
k=1 i1 ,i2 ,...,ik
n
k−1 n
X
= (−1) (n − k)!
k
k=1
n
X n!
= (−1)k−1 ,
k!
k=1
so
n n
n! X n! X n!
D(n) = − (−1)k−1 = (−1)k ,
0! k! k!
k=1 k=0
as claimed.
§3.1 Recurrences
Definition 3.1. A recurrence is a sequence {an }n≥0 such that each element aj can be
computed from the previous terms in the sequence a0 , a1 , . . . , aj−1 .
Example 3.2
The Fibonacci sequence Fn = Fn−1 + Fn−2 with F0 = 0 and F1 = 1 has a plethora
of applications in probability and combinatorics. It also describes several biological
phenomena, such as the flower of an artichoke, an uncurling fern, and the arrangement
of a pine cone’s bracts.
One way to find the closed form for a recursive sequence is by inferring the closed form
and proving by induction. More concretely, if an is a recursive sequence and f (n) is a
closed form of an , one could first verify a0 = f (0) (the base case), and then prove that
a0 = f (0), a1 = f (1), . . . , an = f (n) implies an+1 = f (n + 1) for all n (the inductive step).
This would prove that an = f (n) for all n.
8
6.S095 Lecture 1 Notes
Example 3.3
Let an = an−1 + 2n+1 and let a1 = 3. Prove that an = 2n+1 − 1 for all n ≥ 1.
For the inductive step, assume that an = 2n+1 − 1 holds for 1 ≤ n ≤ k, in partic-
ular, that ak = 2k+1 − 1. We must prove validity for k + 1. By the recurrence relation
and inductive hypothesis,
Suppose that a recursive sequence an is given. As n becomes large, using the recursion
to compute an from its previous values (which must also be calculated) can become
intractable. To avoid this, one can instead reason about the generating function of the
sequence, which encodes all of the terms into one object, and in some cases, leads to a
closed form.
Definition 3.4. The generating function A(x) of a sequence {an }n≥0 is the formal power
series
X∞
A(x) = an xn .
n=0
We will not be concerned with the convergence of this series in this class.
Example 3.5
Find an explicit formula for the Fibonacci sequence {fn } defined as f0 = 0, f1 = 1,
and fn+1 = fn + fn−1 for n ≥ 2.
Solution. Let F (x) = n≥0 fn xn be the generating function of the Fibonacci sequence.
P
By multiplying the recurrence formula by xn+1 , one gets fn+1 xn+1 = fn xn+1 + fn−1 xn+1 .
Summing over all n ≥ 1 yields
∞
X ∞
X ∞
X
fn+1 xn+1 = fn xn+1 + fn−1 xn+1 .
n=1 n=1 n=1
P∞
The LHS can be written as n=0 fn xn − f0 x0 − f1 x1 = F (x) − x. Similarly expressing
the RHS in terms of F (x) yields
−x
F (x) − x = xF (x) + x2 F (x) =⇒ F (x) = .
+x−1 x2
To simplify this, we use the method of partial fractional decomposition. Denoting the
roots of x2 + x − 1 as α and β, we wish to find constants A, B such that
−x A B
F (x) = 2 =− + .
x +x−1 x−α x−β
9
6.S095 Lecture 1 Notes
α β
With standard methods, we find that A = α−β and B = β−α . This means that
x −1
A B 1 x −1 1
F (x) = + = 1− + 1−
α−x β−x α−β α β−α β
1 P∞ n
Since 1−x = n=0 x ,
∞ ∞ ∞ ∞
1 X x n X α−n β −n
X
n 1 X x n
fn x = F (x) = + = + xn ,
α−β α β−α β α−β β−α
n=0 n=0 n=0 n=0
implying that
α−n − β −n
fn = .
α−β
√ √
Since {α, β} = { −1+2 5 −1− 5
, 2 }, it follows that
√ !n √ !n
1 1+ 5 1 1− 5
fn = √ −√ .
5 2 5 2
10