1
Discrete Mathematics
1
Course preparation group:
Nguyễn Khánh Phương
Đỗ Phan Thuận
Phạm Quang Dũng
Huỳnh Thanh Bình
Trần Vĩnh Đức
Bùi Quốc Trung
Đinh Viết Sang
Ban Hà Bằng
2
PART 1
COMBINATORIAL THEORY
(Lý thuyết tổ hợp)
PART 2
GRAPH THEORY
(Lý thuyết đồ thị)
Contents of Part 1
Chapter 0: Sets, Relations
Chapter 1: Counting problem
Chapter 2: Existence problem
Chapter 3: Enumeration problem
Chapter 4: Combinatorial optimization problem
3
Contents
1. Basic counting principles
2. Elementary combinatorial configuration
3. The inclusion-exclusion principle
4. Recurrence relation
5. Generating function
4
2
1. Basic counting principles
5
1.1. The sum rule
1.2. The product rule
1.1. The sum rule
Let us consider two tasks:
m
1
is the number of ways to do task 1
m
2
is the number of ways to do task 2
Tasks are independent of each other, i.e.,
Performing task 1 does not accomplish task 2 and vice versa.
Sum rule: the number of ways that “either task 1 or task 2 can be done,
but not both”, is m
1
+ m
2
.
Generalizes to multiple tasks ...
Task 1
Task 2
Things 1 2 3 k
ways m
1
m
2
m
3
m
k
select one of them: m
1
+m
2
+m
3
+...+ m
k
ways
1.1. The sum rule
7
Generalized sum rule: If we have tasks T
1
, T
2
, …, T
k
that can be
done in m
1
, m
2
, …, m
k
ways, respectively, and any two of these
tasks can not be done at the same time, then there are m
1
+ m
2
+
… + m
k
ways to do one of these tasks.
The sum rule can also be phrased in terms of set theory:
The
size of the union on k finite pair wise disjoint sets is the sum of
their sizes:
Let A
1
, A
2
, …, A
k
be disjoint sets. Then the number of ways
to choose any element from one of these sets is
|A
1
A
2
A
k
| = |A
1
| + |A
2
| + … + |A
k
|.
1. Basic counting principles
8
1.1. The sum rule
1.2. The product rule
3
The product rule
9
Consider two tasks:
m
1
is the number of ways to do task 1
m
2
is the number of ways to do task 2
Tasks are independent of each other, i.e.,
Performing task 1does not accomplish task 2 and vice versa.
Product rule: the number of ways that “both tasks 1 and 2 can be done”
in m
1
m
2
.
Generalize to multiple tasks ...
task 1
task 2
1.2. The product rule
10
Generalized product rule: If we have a procedure consisting of
sequential tasks T
1
, T
2
, …, T
k
that can be done in m
1
, m
2
, …, m
k
ways,
respectively, then there are m
1
* m
2
* … * m
k
ways to carry out the
procedure.
The product rule can also be phrased in terms of set theory: Let A
1
, A
2
,
…, A
k
be finite sets. Then the number of ways to choose one element
from each set in the order of A
1
, A
2
, …, A
k
is
|A
1
x A
2
x … x A
k
| = |A
1
| * |A
2
| * … * |A
k
|.
1.2. The product rule
If each element a
i
of k- tuple (a
1
, a
2
, ..., a
k
) has m
i
number of
ways to select (i = 1, 2, ..., k), then the number of tuples could be
generated is the product of these m
1
m
2
... m
k
11
Contents
1. Basic counting principles
2. Elementary combinatorial configuration
3. The inclusion-exclusion principle
4. Recurrence relation
5. Generating function
12
4
2. Elementary combinatorial configuration
2.1. Permutation
2.2. Combination
13
2. Elementary combinatorial configuration
2.1. Permutation
2.1.1. Permutation
2.1.2. Circulation permutation
2.1.3. Permutation of multisets
2.2. Combination
14
2.1.1. Permutation
A permutation of a set A of objects is an ordered arrangement of
the elements of A where each element appears only once
Example: If A = {a, b, c}, then the permutations of A are
1. abc
2. acb
3. bac
4. bca
5. cab
6. cba
The number of permutations of any set with n elements is
P(n) = n! = n(n − 1) · · · 2 · 1
(Note that by definition 0! = 1)
15
2. Elementary combinatorial configuration
2.1. Permutation
2.1.1. Permutation
2.1.2. Circulation permutation
2.1.3. Permutation of multisets
2.2. Combination
16
5
2.1.2. Circulation permutation
Circulation permutation
Example 3: 6 people A, B, C, D, E, F are seated around a round table, how
many different circular arrangements are possible, if arrangements are
considered the same when one can be obtained from the other by rotations?
17
ABCDEF,
BCDEFA,
CDEFAB,
DEFABC,
EFABCD,
FABCDE
are the same arrangements circularly
There are 6! ways to seat 6 people around the table
For each seating, there are 6 “rotations” of the seating
Thus, the final answer is 6!/6 = 5! = 120
n!/n=(n-1)!
A
B
C
D
E
F
2. Elementary combinatorial configuration
2.1. Permutation
2.1.1. Permutation
2.1.2. Circulation permutation
2.1.3. Permutation of multisets
2.2. Combination
18
2.1.4. Permutations of multisets
A multiset M is a collection whose members need not be distinct.
Example: The collection
M = (a, a, a, b, b, c, d, d, d, 1, 2, 2, 2, 3, 3, 3, 3)
is a multiset; and sometimes it is convenient to write
M = (3a, 2b, c, 3d, 1, 32, 43).
A multiset M over a set S can be viewed as a function v : S → from S
to the set ℕ of nonnegative integers; each element x S is repeated t(x)
times in M; we write M = (S; t).
19
2.1.4. Permutation of multisets
Let M be a multiset and |M| = n.
Proposition 1. Let M be a multiset of r different types where each type has
infinitely elements. Then the number of k-permutations of M equals 𝑟
Example 1. What is the number of binary numerals with at most 4 digits?
Solution: The question is to find the number of 4-permutations of the multiset
(0, 1). Thus the answer is 2
4
= 16.
20
6
2.1.4. Permutation of multisets
Proposition 2. Let M be a multiset of r different types with repetition numbers
n
1
, n
2
,…, n
r
respectively. Let n = n
1
+ n
2
+… + n
r
. Then the number of
permutations of M equals
𝒏!
𝒏
𝟏
! 𝒏
𝟐
! 𝒏
𝒓
!
Proof.
21
n
r
2. Elementary combinatorial configuration
2.1. Permutation
2.2. Combination
22
2.2. Combination
2.1.1. Definitions
2.2.2. Binomial coefficients
2.2.3. Combinations of Multisets
2.2.4. Multinomial coefficients
23
2.2.1. Definitions
A k-combination of a set of n elements is a subset of size k of n
elements.
(Note: A permutation is a sequence while a combination is a set)
Example:
The 2-permutation (sequence) of SOHN is:
SO, SH, SN, OH, ON, OS, HN, HS, HO, NS, NO, NH
The 2-combination (set) of SOHN is:
{S,O},{S,H},{S,N},{O,H},{O,N},{H,N}
24
7
2.2.1. Definitions
The number of all k-combinations of a set of n elements denoted
and read “n choose k”.
This number is also called a binomial coefficient because such numbers
occur as coefficients in the expansions of powers of binomial
expressions such as (a+b)
n
25
, or ( , )
k
n
n
C C n k
k
!
! ( )!
n
n
k
k n k
Proof ???
2.2. Combination
2.1.1. Definitions
2.2.2. Binomial coefficients
2.2.3. Combinations of Multisets
2.2.4. Multinomial coefficients
26
Binomial Coefficients
(a + b)
4
= (a + b)(a + b)(a + b)(a + b)
27
= a
4
4
0





+ a
3
b
4
1






+ a
2
b
2
4
2






+ ab
3
4
3






+ b
4
4
4






Binomial Theorem: Let x and y be variables, and let n be any nonnegative integer.
Then
(x y )
n
n
j






j 0
n
x
n j
y
j
2.2. Combination
2.1.1. Definitions
2.2.2. Binomial coefficients
2.2.3. Combinations of Multisets
2.2.4. Multinomial coefficients
28
8
2.2.3. Combinations of multisets
Let M be a multiset {a
1
, a
2
, …, a
n
} (M has n distinct objects):
A k-combination of M is an unordered collection of k objects selected from n types
of objects of M.
A k-combination of M is also called an k-combination with repetition allowed.
The number of k-combination of M is C(n+ k-1, k) = C(n+ k-1, n-1)
(the number of selections, with repetitions, of k objects from n distinct objects)
Need to divide k candies for n kids B
1
, B
2
, …,B
n
. How many different ways to divide?
Let t
j
be the number of candies for kid B
j
, j=1,…,n. At this point, the above problem
leads to the problem:
Let k and n be non-negative integers. How many non-negative integers in the following
equation have?
29
1 2 3
1 2
, , ,
n
n
t t t t k
t t t Z
2.2. Combination
2.1.1. Definitions
2.2.2. Binomial coefficients
2.2.3. Combinations of Multisets
2.2.4. Multinomial coefficients
30
2.2.4. Multinomial coefficients
The number of ordered arrangements of n objects, in which there are k
1
objects of type 1, k
2
objects of type 2, ..., and k
m
objects of type m and
where k
1
+k
2
+ ... +k
m
= n, is
31
1 2
1 2
!
, ,...,
! !... !
m
m
n
n
k k k
k k k
2.2.4. Multinomial coefficients
The Multinomial Theorem:
32
1 2
1 2 1 2
1 2
( ... ) ...
, ,...,
m
k
k kn
m m
m
n
x x x x x x
k k k
where the summation is over all sequences of non-negative integers
(k
1
, k
2
, ..., k
m
) such that k
1
+ k
2
+ ... + k
m
= n.
9
Contents
1. Basic counting principles
2. Elementary combinatorial configuration
3. The inclusion-exclusion principle
4. Recurrence relation
5. Generating function
33
3. Inclusion-exclusion principle
3.1. Inclusion-exclusion principle
3.2. Derangement
34
3.1. Inclusion-exclusion principle
The inclusion–exclusion principle is an equation relating the sizes of two sets
and their union. It states that if A and B are two (finite) sets, then
|A B| = |A| + |B| - |A B|
Similarly, for three sets A, B and C:
|A B C| = |A| + |B| + |C| - |A B| - |A C| - |B C| + |A B C|
35
The meaning of the statement is that
the number of elements in the union
of the two sets is the sum of the
elements in each set, respectively,
minus the number of elements that
are in both.
3.1. Inclusion-exclusion principle
More generally, for finite sets A
1
, A
2
,…,A
m
where:
Note: N
k
is the sum of the cardinalities of all intersections of k
from m given sets. For example:
N
1
= |A
1
| + ... + |A
m
|
N
m
= |A
1
A
2
... A
m
|
36
1 2
1 2
1 ...
| ... |, 1, 2,...,
k
k
k i i i
i i i m
N A A A k m
𝐴
𝐴
𝐴
= 𝑁
𝑁
+ + (−1)

𝑁
10
3. Inclusion-exclusion principle
3.1. Inclusion-exclusion principle
3.2. Derangement
37
3.2. Derangement
A derangement of {1, 2, …, n} is a permutation on the set such that none
of elements i is placed at position ith in the permutation.
(In other words, derangement is a permutation that has no fixed points)
Example: n = 5
Permutation (2,3,5,4,1) is not a derangement
Permutation (2,3,5,1,4) is a derangement
Denote D
n
the number of derangements of {1, 2, …, n} D
n
= ??
38
3.2. Derangement
Denote D
n
the number of derangements of {1, 2, …, n} D
n
= ??
Let S = set of all permutations of {1, 2, …, n} |S| = n!
Let A
i
= subset of permutations of {1, 2, …, n} such that the ith element = i in
the permutation.
|𝐴
𝐴
𝐴
| counts the number of permutations in which at least one
object i of the n objects appears in the ith position (its original position).
D
n
: number of permutations such that none of the n objects appears in their
original positions. Therefore:
D
n
= n! - |𝐴
𝐴
𝐴
|
Remember the inclusion-exclusion principle:
39
|𝐴
𝐴
𝐴
| ? ? ?
Contents
1. Basic counting principles
2. Elementary combinatorial configuration
3. The inclusion-exclusion principle
4. Recurrence relation
5. Generating function
40
11
4. Recurrence relations
4.1. Recurrence relations
4.2. Solve recurrence relations
41
4.1. Recurrence relations
Definition:
A recurrence relation for the sequence {a
n
} is the equation that expresses a
n
in terms of one or more of the previous terms in the sequence namely, a
0
, a
1
,
…, a
n-1
, for all integers n with n n
0
, where n
0
is a nonnegative integer.
A sequence is called a solution
to a recurrence relation if its terms satisfy the
recurrence relation.
Example: Consider the recurrence relation
a
n
= 2a
n-1
a
n-2
for n = 2, 3, 4, …
The sequence a
n
=3n is a solution of this recurrence relation?
For n 2 we see that:
2a
n-1
a
n-2
= 2(3(n 1)) – 3(n 2) = 3n = a
n
Therefore, the sequence a
n
=3n is a solution of the recurrence relation
The sequence a
n
=5 is also a solution of the this recurrence relation?
For n 2 we see that: 2a
n-1
a
n-2
= 25 - 5 = 5 = a
n
Therefore, the sequence a
n
=5 is also a solution of the recurrence relation
4.1. Recurrence relations
A recurrence without specifying any initial values (initial conditions).
can have (and usually has) multiple solutions.
Example: a
n
= 2a
n-1
a
n-2
for n = 2, 3, 4. It has the following sequences a
n
as solution:
a
n
=5
a
n
=3n
a
n
=n+1
If both the initial conditions and the recurrence relation are specified, then the
sequence is uniquely determined.
Example: a
n
= 2a
n-1
a
n-2
for n = 2, 3, 4
where a
0
=0; a
1
= 3
The sequence a
n
=5 is not the solution
The sequence a
n
=3n is the unique solution
Modeling with Recurrence Relations
Example 1: Someone deposits $10,000 in a savings account at a bank yielding 5% per year
with interest compounded annually. How much money will be in the account after 30 years?
Solution:
Let P
n
denote the amount in the account after n years.
How can we determine P
n
on the basis of P
n-1
?
We can derive the following recurrence relation:
P
n
= P
n-1
+ 0.05P
n-1
= 1.05P
n-1
.
The initial condition is P
0
= 10,000.
Then we have:
P
1
= 1.05P
0
P
2
= 1.05P
1
= (1.05)
2
P
0
P
3
= 1.05P
2
= (1.05)
3
P
0
P
n
= 1.05P
n-1
= (1.05)
n
P
0
We now have a formula to calculate P
n
for any natural number n and can avoid the iteration.
44
P
30
= (1.05)
30
10,000 = 43,219.42
12
4. Recurrence relations
4.1. Recurrence relations
4.2. Solving recurrence relations
45
4.2. Solving Recurrence Relations
Solving the recurrence relation for a sequence a
0
, a
1
, a
2
, a
3
,….a
n
,… is to give
the explicit formula to compute the value for the general term a
n
, i.e., to find an
expression for an that does not involve any other a
i
Example: Given the recurrence relation:
a
n
= 2a
n-1
a
n-2
where n = 2, 3, 4,…
a
0
=0; a
1
= 3
The explicit formula for the above recurrence relation is a
n
=3n
a
n
=3n is the solution to the above recurrence relation
Does not exist the method to solve all types of recurrence relation.
Consider method to solve the recurrence relation with following types:
A linear homogeneous recurrence relation of degree k with constant
coefficients
A linear nonhomogeneous recurrence relation of degree k with constant
coefficients
46
4.2. Solving Recurrence Relations
Definition: A linear homogeneous recurrence relation of degree
k with constant coefficients is a recurrence relation of the form:
a
n
= c
1
a
n-1
+ c
2
a
n-2
+ … + c
k
a
n-k
where c
1
, c
2
, …, c
k
are real number constants, and c
k
0.
A sequence satisfying such a recurrence relation is uniquely
determined by the recurrence relation if it also satisfying k initial
conditions:
a
0
= C
0
, a
1
= C
1
, a
2
= C
2
, …, a
k-1
= C
k-1
where C
0
, C
1
, ..., C
k-1
are constants.
47
4.2. Solving Recurrence Relations
Definition: A linear homogeneous recurrence relation of degree
k with constant coefficients is a recurrence relation of the form:
a
n
= c
1
a
n-1
+ c
2
a
n-2
+ … + c
k
a
n-k
where c
1
, c
2
, …, c
k
are real number constants, and c
k
0.
Explain:
Linear: the right-hand side is the sum of the terms before the term a
n
in the sequence where the coefficients (c
1
, c
2
, ..,c
k
) are constant (not
a function dependent on n)
Homogeneous: the right-hand side has no additional terms other
than the terms a
i
of the sequence
Degree k: the right hand side has the (n-k)th term of the sequence
48
13
A linear homogeneous recurrence relation of degree k
with constant coefficients
We try to find solution of the form a
n
= r
n
, where r is a constant.
The sequence {a
n
= r
n
} is a solution of the recurrence relation
a
n
= c
1
a
n−1
+ … + c
k
a
nk
if and only if r satisfying:
r
n
= c
1
r
n−1
+ … + c
k
r
nk
, or
r
k
c
1
r
k−1
− … − c
k
= 0
this is called the characteristic equation of the recurrence relation, and
its solution is called characteristic roots of the recurrence relation.
We will use characteristic roots to obtain
explicit formula for the
sequence.
49
(subtract the right-hand side from the left
and
×
by r
kn
)
A linear homogeneous recurrence relation of degree k
with constant coefficients
Theorem 1. Let c
1
and c
2
be real numbers.
Suppose that r
2
- c
1
r - c
2
= 0 has 2 distinct roots r
1
and r
2
. Then the
sequence {a
n
} is a solution of the recurrence relation
a
n
= c
1
a
n-1
+ c
2
a
n-2
if and only if
a
n
=
1
(r
1
)
n
+
2
(r
2
)
n
(1)
n = 0, 1, ..., where
1
and
2
are constants.
50
Example 1
Fibonacci sequence is given by the following recurrence relation:
F
n
= F
n-1
+ F
n-2
, n 2,
F
0
= 0, F
1
= 1.
Find the explicit formula for F
n
.
Solution: Solve the characteristic equation:
r
2
- r - 1 = 0,
its characteristic roots are:
51
1 2
1 5 1 5
;
2 2
r r
Leonardo Fibonacci
1170-1250
Example 1
The explicit formula:
F
n
=
1
.(r
1
)
n
+
2
.(r
2
)
n
where
1
,
2
are constants and could be determined by using
initial conditions F
0
, F
1
.
Solving these two equations, we have:
Therefore
52
1 2
1 1
;
5 5
1
1 5 1 5
, 0.
2 2
5
n n
n
F n
Muavre formula
F
0
=
1
+
2
= 0
F
1
=
1
r
1
+
2
r
2
= 1
14
The case: one characteristic root with multiplicities 2
But what happens if the characteristic equation has only one root?
Theorem 2: Let c
1
and c
2
be real numbers with c
2
0. Suppose that r
2
-
c
1
r - c
2
= 0 has only one root r
0
. Then a sequence {a
n
} is a solution of
the recurrence relation a
n
= c
1
a
n-1
+ c
2
a
n-2
if and only if
n = 0, 1, ..., where
1
,
2
are constants.
53
a r nr
n
n n
1 0 2 0
Example 2
Solving the following recurrence relation
a
n
= 6 a
n-1
- 9 a
n-2
with initial conditions a
0
= 1 and a
1
= 6.
Solution:
Characteristic equation:
r
2
- 6 r + 9 = 0 has one root r = 3. The solution is:
a
n
=
1
3
n
+
2
n 3
n
To determine
1
,
2
, using the initial conditions, we have:
a
0
= 1 =
1
,
a
1
= 6 =
1
* 3 +
2
*1* 3
Solving these equations, we have
1
= 1 and
2
= 1.
Therefore, the solution of the recurrence relation is:
a
n
= 3
n
+ n 3
n
54
General case
Theorem 3. Let c
1
, c
2
, ..., c
k
be real numbers. Assume the characteristic
equation
r
k
- c
1
r
k-1
- c
2
r
k-2
- . . . - c
k
= 0
has k distinct roots r
1
, r
2
, ..., r
k
. Then a sequence {a
n
} is a solution of
the recurrence relation:
a
n
= c
1
a
n-1
+ c
2
a
n-2
+...+ c
k
a
n-k
,
if and only if
a
n
=
1
r
1
n
+
2
r
2
n
+ . . . +
k
r
k
n
where n = 0, 1, 2,..., and
1
,
2
, ...,
k
are constants
55
Example 3
Solving the recurrence relation:
a
n
= 6 a
n-1
- 11 a
n-2
+ 6 a
n-3
where initial conditions
a
0
= 2, a
1
= 5, a
2
= 15.
Solution: Characteristic equation
r
3
- 6 r
2
+ 11 r - 6 = 0
has 3 distinct roots r
1
= 1, r
2
= 2, r
3
= 3.
Therefore, the solution is
a
n
=
1
1
n
+
2
2
n
+
3
3
n
for some constants
1,
2,
3
56
15
Example 3
Using the initial conditions, we have following equations to
determine the value for constants
1
,
2
,
3
:
a
0
= 2 =
1
+
2
+
3
a
1
= 5 =
1
+
2
.2 +
3
.3
a
2
= 15 =
1
+
2
.4 +
3
.9.
Solving above equations, we have
1
= 1,
2
= -1 and
3
= 2.
Therefore, the solution of the recurrence relation is
a
n
= 1 - 2
n
+ 2. 3
n
57
General case
Given linear homogeneous recurrence relation of degree k with constant
coefficients
Its characteristic equation is:
Theorem 4: If the characteristic equation has t distinct roots
r
1
,…,r
t
with multiplicities m
1
,…,m
t
(m
1
+…+m
t
= k). Then:
a
n
= (
,
+
,
n + … +
,

𝑛

) 𝑟
+
(
,
+
,
n + … +
,

𝑛

) 𝑟
+ ...
(
t,0
+
,
n + … +
,

𝑛

) 𝑟
where n≥0, and α
ij
are constants.
k
i
inin
aca
1
0
1
k
i
ik
i
k
rcr
58
t
i
n
i
m
j
j
jin
rna
i
1
1
0
,
Example 4
59
Solve the following recurrence relation:
c
n
=
4c
n-1
+ 3c
n-2
+ 18c
n-3
, n 3,
c
0
= 1; c
1
= 2; c
2
= 13.
Solution: Characteristic equation
r
3
+ 4r
2
3r 18 = (r
2)(r + 3)
2
= 0
Hence, the solution of the recurrence relation:
c
n
= α
10
2
n
+ (α
20
+ α
21
n)(
3)
n
where α
10
, α
20
, α
21
are constants
Example 4
2 ( 1 )( 3)
n n
n
c n
60
These constants are determined by using initial conditions:
0 = c
0
= α
10
2
0
+ (α
20
+ α
21
.0) (-3)
0
= α
10
+ α
20
2 = c
1
= α
10
2
1
+ (α
20
+ α
21
.1) (-3)
1
= 2α
10
-
20
-
21
13 = c
2
= α
10
2
2
+ (α
20
+ α
21
.2) (-3)
2
= 4α
10
+ 9α
20
+18α
21
Solving three equations above, we have: α
10
=1 ; α
20
= -1; α
21
=1
The solution of recurrence relation is:
16
Linear nonhomogeneous recurrence relation with
constant coefficients
Linear nonhomogeneous recurrence relation with constant
coefficients) has the term F(n) dependent on n (and
independent on any value of a
i
) :
a
n
= c
1
a
n−1
+ … + c
k
a
nk
+ F(n)
Linear homogeneous recurrence relation
Nonhomogeneous term
2.5. Recurrence relations and generating functions
2.5.1. Recurrence relations
2.5.2. Generating functions
62
2.5.2. Generating functions
Generating functions are a tool to solve a wide variety of counting
problems and recurrence relations.
Example 1:
63
How many ways to give 12 oranges for three children: A, B and C such that:
A gets at least four, and B and C gets at least two, but C gets no more than five
Find the number of integer solutions to
a + b + c = 12 where a 4, b ≥ 2, 2 c 5
a, b , c are the number of oranges
that A, B and C gets, respectively
2.5.2. Generating functions
Example 1:
Let
a: a(x) = x
4
+ x
5
+ x
6
+ x
7
+ x
8
(since b + c 4 a 8)
b : b(x) = x
2
+ x
3
+ x
4
+ x
5
+ x
6
(since a + c 6 b 6)
c : c(x) = x
2
+ x
3
+ x
4
+ x
5
(since 2 c 5)
The coefficient of x
12
in g(x) = a(x) b(x) c(x)
=(x
4
+ x
5
+ x
6
+ x
7
+ x
8
) (x
2
+ x
3
+x
4
+ x
5
+ x
6
)(x
2
+ x
3
+x
4
+ x
5
)
is the solution to the problem
g(x) is called a generating function.
Assume x
a
, x
b
, x
c
are terms derived from (x
4
+ x
5
+ x
6
+ x
7
+ x
8
) , (x
2
+ x
3
+x
4
+ x
5
+ x
6
), (x
2
+ x
3
+x
4
+ x
5
)
respectively when developing the right-hand side 4 a 8, 2 b 6, 2 c 5
When developing the right-hand side, these three terms give us the term x
n
where n = a +b + c:
g(x) = (x
4
+ x
5
+ x
6
+ x
7
+ x
8
) (x
2
+ x
3
+x
4
+ x
5
+ x
6
)(x
2
+ x
3
+x
4
+ x
5
)
= …. + Kx
n
+…..
The coefficient of x
n
in f(x) is the number of positive integer solutions to
a + b + c = n where 4 a 8, 2 b 6, 2 c 5
64
Find the number of integer solutions to
a + b + c = 12 where a 4, b ≥ 2, 2 c 5
Why???
n=12
=???
17
2.5.2. Generating functions
Example 1:
Let
a: a(x) = x
4
+ x
5
+ x
6
+ x
7
+ x
8
(since b + c 4 a 8)
b : b(x) = x
2
+ x
3
+ x
4
+ x
5
+ x
6
(since a + c 6 b 6)
c : c(x) = x
2
+ x
3
+ x
4
+ x
5
(since 2 c 5)
The coefficient of x
12
in g(x) = a(x) b(x) c(x)
=(x
4
+ x
5
+ x
6
+ x
7
+ x
8
) (x
2
+ x
3
+x
4
+ x
5
+ x
6
)(x
2
+ x
3
+x
4
+ x
5
)
which is 14, is the solution
g(x) is called a generating function.
65
Find the number of integer solutions to
a + b + c = 12 where a 4, b ≥ 2, 2 c 5
1. x
4
*x
3
*x
5
2. x
4
*x
4
*x
4
3. x
4
*x
5
*x
3
4. x
4
*x
6
*x
2
5. x
5
*x
2
*x
5
6. x
5
*x
3
*x
4
7. x
5
*x
4
*x
3
8. x
5
*x
5
*x
2
9. x
6
*x
2
*x
4
10. x
6
*x
3
*x
3
11. x
6
*x
4
*x
2
12. x
7
*x
2
*x
3
13. x
7
*x
3
*x
2
14. x
8
*x
2
*x
2
2.5.2. Generating functions
Definition: Let a
0
, a
1
, a
2
, … be a sequence of real numbers. The function
is called the generating function for the given sequence.
A finite sequence
a
0
, a
1
, a
2
, …, a
n
can be regarded as the infinite sequence
a
0
, a
1
, a
2
, …, a
n
, 0, 0,… [set all terms higher than n to 0]
and its generating function
g(x) = a
0
+ a
1
x + a
2
x
2
+ … + a
n
x
n
is a polynomial.
66
0 1
0
( ) ... ...
k i
k i
i
g x a a x a x a x
2.5.2. Generating functions
Example 2: For the binomial coefficients we already know that:
(x+1)
n
is the generating function for the sequence
C(n, 0), C(n, 1),…,C(n, k),…, C(n, n), 0,0,0…
67
0 0
( ) ( , ) ( 1) ( , ) ( )
n n
n k n k n k
k k
x y C n k x y x C n k x g x
2.5.2. Generating functions
Definition: Let a
0
, a
1
, a
2
, … be a sequence of real numbers. The function
is called the generating function for the given sequence.
Some useful generating function:
Ex1: (1 x
n+1
) = (1 x)(1 + x + x
2
+ x
3
+ ...+ x
n
).
So (1-x
n+1
)/(1-x) = 1 + x + x
2
+ x
3
+ ...+ x
n
,
(1-x
n+1
)/(1-x) is the generating function for the sequence:
1, 1, 1, …, 1, 0, 0, 0, … . (where the first n+1 terms are 1)
Ex2: From Ex1, If n and |x| < 1, then 1 = (1 x)(1 + x + x
2
+ x
3
+ ...).
So, 1/(1-x) = 1 + x + x
2
+ x
3
+ ...
1/(1-x) where |x| < 1 is the generating function for the sequence:
1, 1, 1, …, 1, … .
68
0 1
0
( ) ... ...
k i
k i
i
g x a a x a x a x
18
2.5.2. Generating functions
Generating functions are a tool to solve a wide variety of counting problems and
recurrence relations.
Definition: Let a
0
, a
1
, a
2
, … be a sequence of real numbers. The function
is called the generating function for the given sequence.
69
0 1
0
( ) ... ...
k i
k i
i
g x a a x a x a x
2.5.2. Generating functions
Example: Solve the recurrence relation a
n
-3a
n-1
= n, n1, a
0
=1
70
𝑔 𝑥 1 3𝑥𝑔(𝑥) =
𝑥
(1 𝑥)
𝑔 𝑥 =
1
1 3𝑥
+
𝑥
(1 3𝑥)(1 𝑥)
𝑔 𝑥 =
1
1 3𝑥
+
𝐴
(1 3𝑥)
+
𝐵
(1 𝑥)
+
𝐶
(1 𝑥)
𝐴 =
3
4
; 𝐵 =
1
4
; 𝐶 =
1
2
;
𝑔 𝑥 =
7/4
(1 3𝑥)
+
−1/4
(1 𝑥)
+
−1/2
(1 𝑥)
We find a
n
by determining the coefficient of x
n
in g(x)
determining the coefficient of x
n
in each of the three summands
0 1
0
( ) ... ...
k i
k i
i
g x a a x a x a x

Preview text:

Contents of Part 1 Chapter 0: Sets, Relations Chapter 1: Counting problem Discrete Mathematics Chapter 2: Existence problem Chapter 3: Enumeration problem Course preparation group: Nguyễn Khánh Phương Đỗ Phan Thuận
Chapter 4: Combinatorial optimization problem Phạm Quang Dũng Huỳnh Thanh Bình Trần Vĩnh Đức Bùi Quốc Trung Đinh Viết Sang Ban Hà Bằng 1 3 Contents PART 1 1. Basic counting principles COMBINATORIAL THEORY 2. E l
e mentary combinatorial configuration
3. The inclusion-exclusion principle (Lý thuyết tổ hợp) 4. Recurrence relation 5. Generating function PART 2 GRAPH THEORY (Lý thuyết đồ thị) 2 4 1 1. Basic counting principles 1.1. The sum rule 1.1. The sum rule
Generalized sum rule: If we have tasks T1, T2, …, Tk that can be
done in m1, m2, …, mk ways, respectively, and any two of these 1.2. The product rule
tasks can not be done at the same time, then there are m1 + m2 +
… + mk ways to do one of these tasks.
The sum rule can also be phrased in terms of set theory: The
size of the union on k finite pair wise disjoint sets is the sum of their sizes:
• Let A1, A2, …, Ak be disjoint sets. Then the number of ways
to choose any element from one of these sets is |A   1 A2
…  Ak| = |A1| + |A2| + … + |Ak|. 5 7 1.1. The sum rule 1. Basic counting principles Let us consider two tasks: Task 1 1.1. The sum rule
m1 is the number of ways to do task 1
m2 is the number of ways to do task 2
Tasks are independent of each other, i.e., 1.2. The product rule
Performing task 1 does not accomplish task 2 and vice versa. Task 2
Sum rule: the number of ways that “either task 1 or task 2 can be done, but not both”, is m1 + m2.
Generalizes to multiple tasks ... Things 1 2 3 … k ways m1 m2 m3 … mk
select one of them: m1 +m2 +m3 +...+ mk ways 8 2 The product rule 1.2. The product rule • Consider two tasks:
• If each element ai of k- tuple (a1, a2, ..., ak) has mi number of
– m1 is the number of ways to do task 1
ways to select (i = 1, 2, ..., k), then the number of tuples could be – m
generated is the product of these m
2 is the number of ways to do task 2 1m2 ... mk
– Tasks are independent of each other, i.e.,
• Performing task 1does not accomplish task 2 and vice versa.
Product rule: the number of ways that “both tasks 1 and 2 can be done” in m1m2. task 1 task 2
• Generalize to multiple tasks ... 9 11 1.2. The product rule Contents
Generalized product rule: If we have a procedure consisting of 1. Basic counting principles
sequential tasks T1, T2, …, Tk that can be done in m1, m2, …, mk ways, respectively, then there are m
2. Elementary combinatorial configuration
1 * m2 * … * mk ways to carry out the procedure.
3. The inclusion-exclusion principle
The product rule can also be phrased in terms of set theory: Let A 4. Recurrence relation 1, A2,
…, Ak be finite sets. Then the number of ways to choose one element 5. Generating function
from each set in the order of A1, A2, …, Ak is
|A1 x A2 x … x Ak| = |A1| * |A2| * … * |Ak|. 10 12 3
2. Elementary combinatorial configuration 2.1.1. Permutation 2.1. Permutation
A permutation of a set A of objects is an ordered arrangement of
the elements of A where each element appears only once 2.2. Combination
Example: If A = {a, b, c}, then the permutations of A are 1. abc 2. acb 3. bac 4. bca 5. cab 6. cba
The number of permutations of any set with n elements is
P(n) = n! = n(n − 1) · · · 2 · 1
(Note that by definition 0! = 1) 13 15
2. Elementary combinatorial configuration
2. Elementary combinatorial configuration 2.1. Permutation 2.1. Permutation 2.1.1. Permutation 2.1.1. Permutation 2.1.2. Circulation permutation 2.1.2. Circulation permutation
2.1.3. Permutation of multisets
2.1.3. Permutation of multisets 2.2. Combination 2.2. Combination 14 16 4 2.1.2. Circulation permutation
2.1.4. Permutations of multisets Circulation permutation n!/n=(n-1)!
A multiset M is a collection whose members need not be distinct.
Example 3: 6 people A, B, C, D, E, F are seated around a round table, how Example: The collection
many different circular arrangements are possible, if arrangements are
considered the same when one can be obtained from the other by rotations?
M = (a, a, a, b, b, c, d, d, d, 1, 2, 2, 2, 3, 3, 3, 3) ABCDEF, A
is a multiset; and sometimes it is convenient to write BCDEFA, B F
M = (3a, 2b, c, 3d, 1, 32, 43). CDEFAB,
A multiset M over a set S can be viewed as a function v : S → ℕ from S DEFABC, E C
to the set ℕ of nonnegative integers; each element x S is repeated t(x) EFABCD,
times in M; we write M = (S; t). FABCDE D
are the same arrangements circularly
 There are 6! ways to seat 6 people around the table
For each seating, there are 6 “rotations” of the seating
Thus, the final answer is 6!/6 = 5! = 120 17 19
2. Elementary combinatorial configuration
2.1.4. Permutation of multisets 2.1. Permutation
Let M be a multiset and |M| = n. 2.1.1. Permutation
Proposition 1. Let M be a multiset of r different types where each type has 2.1.2. Circulation permutation
infinitely elements. Then the number of k-permutations of M equals 𝑟
2.1.3. Permutation of multisets 2.2. Combination
Example 1. What is the number of binary numerals with at most 4 digits?
Solution: The question is to find the number of 4-permutations of the multiset
(0, 1). Thus the answer is 24 = 16. 18 20 5
2.1.4. Permutation of multisets 2.2. Combination
Proposition 2. Let M be a multiset of r different types with repetition numbers 2.1.1. Definitions
n1, n2,…, nr respectively. Let n = n1+ n2 +… + nr . Then the number of permutations of M equals 2.2.2. Binomial coefficients 𝒏! 𝒏
2.2.3. Combinations of Multisets 𝟏! 𝒏𝟐! … 𝒏𝒓! Proof.
2.2.4. Multinomial coefficients nr 21 23
2. Elementary combinatorial configuration 2.2.1. Definitions 2.1. Permutation
A k-combination of a set of n elements is a subset of size k of n elements. 2.2. Combination
(Note: A permutation is a sequence while a combination is a set) Example:
The 2-permutation (sequence) of SOHN is:
SO, SH, SN, OH, ON, OS, HN, HS, HO, NS, NO, NH
The 2-combination (set) of SOHN is:
{S,O},{S,H},{S,N},{O,H},{O,N},{H,N} 22 24 6 2.2.1. Definitions Binomial Coefficients
The number of all k-combinations of a set of n elements denoted
(a + b)4 = (a + b)(a + b)(a + b)(a + b)  n , k C or C( , n k) 4   4   4   4   4     =   a4  +   a3  b +   a2  b2
+   ab3 +   b4  n k 0 1 2 3 4             and read “n choose k”.
Binomial Theorem: Let x and y be variables, and let n be any nonnegative integer.  n n! Then    Proof ??? n    k  k !(n  k)! n
(x  y )n    x n j y j j 0  j  
This number is also called a binomial coefficient because such numbers
occur as coefficients in the expansions of powers of binomial expressions such as (a+b)n 25 27 2.2. Combination 2.2. Combination 2.1.1. Definitions 2.1.1. Definitions 2.2.2. Binomial coefficients 2.2.2. Binomial coefficients
2.2.3. Combinations of Multisets
2.2.3. Combinations of Multisets
2.2.4. Multinomial coefficients
2.2.4. Multinomial coefficients 26 28 7
2.2.3. Combinations of multisets
2.2.4. Multinomial coefficients
Let M be a multiset {a1, a2, …, an} (M has n distinct objects):
The number of ordered arrangements of n objects, in which there are k1
A k-combination of M is an unordered collection of k objects selected from n types
objects of type 1, k2 objects of type 2, ..., and km objects of type m and of objects of M. where k1+k2+ ... +km = n, is
A k-combination of M is also called an k-combination with repetition allowed.
The number of k-combination of M is C(n+ k-1, k) = C(n+ k-1, n-1)
(the number of selections, with repetitions, of k objects from n distinct objects)  n  n!    k , k ,..., k k !k !...k !  
Need to divide k candies for n kids B 1 2 m 1 2 m
1, B2, …,Bn. How many different ways to divide?
Let tj be the number of candies for kid Bj, j=1,…,n. At this point, the above problem leads to the problem:
Let k and n be non-negative integers. How many non-negative integers in the following equation have?
t  t  t   t  k 1 2 3 n  t ,t ,,t  Z 1 2 n 29 31 2.2. Combination
2.2.4. Multinomial coefficients 2.1.1. Definitions The Multinomial Theorem: 2.2.2. Binomial coefficients  n  n k k
2.2.3. Combinations of Multisets 1 2 (x  x ...x )    x x ... mk x 1 2 m 1 2 k , k ,..., m k  
2.2.4. Multinomial coefficients 1 2 m
where the summation is over all sequences of non-negative integers
(k1, k2, ..., km) such that k1 + k2 + ... + km = n. 30 32 8 Contents
3.1. Inclusion-exclusion principle 1. Basic counting principles
The inclusion–exclusion principle is an equation relating the sizes of two sets
and their union. It states that if A and B are two (finite) sets, then
2. Elementary combinatorial configuration
|A B| = |A| + |B| - |A B|
3. The inclusion-exclusion principle
The meaning of the statement is that 4. Recurrence relation
the number of elements in the union 5. Generating function
of the two sets is the sum of the
elements in each set, respectively,
minus the number of elements that are in both.
Similarly, for three sets A, B and C:
|A B C| = |A| + |B| + |C| - |A B| - |A C| - |B C| + |A B C| 33 35
3. Inclusion-exclusion principle
3.1. Inclusion-exclusion principle
3.1. Inclusion-exclusion principle
More generally, for finite sets A1, A2,…,Am 3.2. Derangement 𝐴 ∪ 𝐴 ∪ ⋯ ∪ 𝐴 = 𝑁 − 𝑁 + ⋯ + (−1) 𝑁 where: N  A A A k m k
 |  ... |, 1,2,..., 1 i 2 i k i  1 i i ..  . i  1 2 k m
Note: Nk is the sum of the cardinalities of all intersections of k
from m given sets. For example: N1 = |A1| + ... + |Am| N   m = |A1 A2 ...  Am| 34 36 9
3. Inclusion-exclusion principle 3.2. Derangement
3.1. Inclusion-exclusion principle
Denote Dn the number of derangements of {1, 2, …, n} Dn = ?? 3.2. Derangement
Let S = set of all permutations of {1, 2, …, n}  |S| = n!
Let Ai = subset of permutations of {1, 2, …, n} such that the ith element = i in the permutation.
|𝐴 ∪ 𝐴 ∪ ⋯ ∪ 𝐴 | ? ? ?
|𝐴 ∪ 𝐴 ∪ ⋯ ∪ 𝐴 | counts the number of permutations in which at least one
object i of the n objects appears in the ith position (its original position).
Dn: number of permutations such that none of the n objects appears in their original positions. Therefore:
Dn = n! - |𝐴 ∪ 𝐴 ∪ ⋯ ∪ 𝐴 |
Remember the inclusion-exclusion principle: 37 39 3.2. Derangement Contents
A derangement of {1, 2, …, n} is a permutation on the set such that none 1. Basic counting principles
of elements i is placed at position ith in the permutation.
(In other words, derangement is a permutation that has no fixed points)
2. Elementary combinatorial configuration Example: n = 5
3. The inclusion-exclusion principle
Permutation (2,3,5,4,1) is not a derangement 4. Recurrence relation
Permutation (2,3,5,1,4) is a derangement 5. Generating function
Denote Dn the number of derangements of {1, 2, …, n} Dn = ?? 38 40 10 4. Recurrence relations 4.1. Recurrence relations 4.1. Recurrence relations
A recurrence without specifying any initial values (initial conditions).
4.2. Solve recurrence relations
 can have (and usually has) multiple solutions.
Example: an = 2an-1 – an-2 for n = 2, 3, 4. It has the following sequences an as solution: an=5 an=3n an=n+1
If both the initial conditions and the recurrence relation are specified, then the
sequence is uniquely determined.
Example: an = 2an-1 – an-2 for n = 2, 3, 4 where a0=0; a1 = 3
The sequence an=5 is not the solution
The sequence an=3n is the unique solution 41 4.1. Recurrence relations
Modeling with Recurrence Relations
Example 1: Someone deposits $10,000 in a savings account at a bank yielding 5% per year Definition:
with interest compounded annually. How much money will be in the account after 30 years?
A recurrence relation for the sequence {an} is the equation that expresses an Solution:
in terms of one or more of the previous terms in the sequence namely, a0, a1, …, a
• Let Pn denote the amount in the account after n years.
n-1, for all integers n with n  n0, where n0 is a nonnegative integer. How can we determine P
A sequence is called a solution to a recurrence relation if its terms satisfy the n on the basis of Pn-1? recurrence relation.
• We can derive the following recurrence relation:
Example: Consider the recurrence relation
Pn = Pn-1 + 0.05Pn-1 = 1.05Pn-1. a • The initial condition is P
n = 2an-1 – an-2 for n = 2, 3, 4, … 0 = 10,000.
P30 = (1.05)3010,000 = 43,219.42 The sequence a Then we have:
n=3n is a solution of this recurrence relation? For n  2 we see that: 2a • P1 = 1.05P0
n-1 – an-2 = 2(3(n – 1)) – 3(n – 2) = 3n = an • Therefore, the sequence a P2 = 1.05P1 = (1.05)2P0
n=3n is a solution of the recurrence relation • P The sequence a 3 = 1.05P2 = (1.05)3P0
n=5 is also a solution of the this recurrence relation? •…
For n  2 we see that: 2an-1 – an-2 = 25 - 5 = 5 = an •P Therefore, the sequence a n = 1.05Pn-1 = (1.05)nP0
n=5 is also a solution of the recurrence relation
 We now have a formula to calculate Pn for any natural number n and can avoid the iteration. 44 11 4. Recurrence relations
4.2. Solving Recurrence Relations 4.1. Recurrence relations
Definition: A linear homogeneous recurrence relation of degree
k with constant coefficients is a recurrence relation of the form:
4.2. Solving recurrence relations
an = c1an-1 + c2an-2 + … + ckan-k where c 
1, c2, …, ck are real number constants, and ck 0.
• A sequence satisfying such a recurrence relation is uniquely
determined by the recurrence relation if it also satisfying k initial conditions:
a0 = C0, a1 = C1, a2 = C2, …, ak-1 = Ck-1
where C0, C1, ..., Ck-1 are constants. 45 47
4.2. Solving Recurrence Relations
4.2. Solving Recurrence Relations
Solving the recurrence relation for a sequence a0, a1, a2, a3,….an,… is to give
Definition: A linear homogeneous recurrence relation of degree
the explicit formula to compute the value for the general term an, i.e., to find an
k with constant coefficients is a recurrence relation of the form:
expression for an that does not involve any other ai
Example: Given the recurrence relation:
an = c1an-1 + c2an-2 + … + ckan-k a where c  0.
n = 2an-1 – an-2 where n = 2, 3, 4,…
1, c2, …, ck are real number constants, and ck a0=0; a1 = 3
The explicit formula for the above recurrence relation is an=3n Explain:
an=3n is the solution to the above recurrence relation
• Linear: the right-hand side is the sum of the terms before the term a
• Does not exist the method to solve all types of recurrence relation. n
in the sequence where the coefficients (c1, c2, ..,ck) are constant (not
• Consider method to solve the recurrence relation with following types: a function dependent on n)
• A linear homogeneous recurrence relation of degree k with constant
• Homogeneous: the right-hand side has no additional terms other coefficients
than the terms ai of the sequence
• A linear nonhomogeneous recurrence relation of degree k with constant
• Degree k: the right hand side has the (n-k)th term of the sequence coefficients 46 48 12
A linear homogeneous recurrence relation of degree k Example 1 with constant coefficients
• We try to find solution of the form a
Fibonacci sequence is given by the following recurrence relation: n = rn, where r is a constant. • The sequence {a Fn = Fn-1 + Fn-2, n  2,
n = rn } is a solution of the recurrence relation F a 0 = 0, F1 = 1. n = c1an−1 + … + ckan−k
Find the explicit formula for Fn. if and only if r satisfying:
Solution: Solve the characteristic equation: rn = c
(subtract the right-hand side from the left 1rn−1 + … + ckrn−k, or r2 - r - 1 = 0, rk − c and × by rk−n) 1rk−1 − … − ck = 0 its characteristic roots are: Leonardo Fibonacci 1 5 1  5 r  ; r  1170-1250 1 2
this is called the characteristic equation of the recurrence relation, and 2 2
its solution is called characteristic roots of the recurrence relation.
• We will use characteristic roots to obtain explicit formula for the sequence. 49 51
A linear homogeneous recurrence relation of degree k Example 1 with constant coefficients • Theorem 1. Let c • The explicit formula: 1 and c2 be real numbers. F Suppose that r2 - c n = 1.(r1)n + 2.(r2)n
1 r - c2 = 0 has 2 distinct roots r1 and r2. Then the sequence {a where 
n} is a solution of the recurrence relation
1,  2 are constants and could be determined by using initial conditions F0, F1. F a 0= 1+ 2 = 0 n = c1 an-1 + c2 an-2 F1= 1r1+ 2r2 = 1 if and only if
Solving these two equations, we have: 1 1   ;    1 2 5 5 an = 1(r1)n + 2(r2)n (1) n = 0, 1, ..., where  Muavre formula 1 and 2 are constants. Therefore n n 1     F     n  n 5   1 5  1 5  , 0. 2 2    50 52 13
The case: one characteristic root with multiplicities 2 General case
But what happens if the characteristic equation has only one root?
Theorem 3. Let c1, c2, ..., ck be real numbers. Assume the characteristic Theorem 2: Let c  equation
1 and c2 be real numbers with c2 0. Suppose that r2 - c rk - c
1 r - c2 = 0 has only one root r0. Then a sequence {an } is a solution of
1 rk-1 - c2 rk-2 - . . . - ck = 0
the recurrence relation an = c1 an-1 + c2 an-2
has k distinct roots r1, r2, ..., rk . Then a sequence {an} is a solution of if and only if the recurrence relation: a  rn  nrn  
an = c1 an-1 + c2 an-2 +...+ ck an-k, n 1 0 2 0 if and only if
n = 0, 1, ..., where 1 , 2 are constants. a n n n
n = 1 r1 + 2 r2 + . . . + k rk
where n = 0, 1, 2,..., and 1, 2, ..., k are constants 53 55 Example 2 Example 3
Solving the following recurrence relation
Solving the recurrence relation: an = 6 an-1 - 9 an-2 an = 6 an-1 - 11 an-2 + 6 an-3
with initial conditions a0 = 1 and a1 = 6. where initial conditions Solution: a Characteristic equation: 0 = 2, a1 = 5, a2 = 15.
r2 - 6 r + 9 = 0 has one root r = 3. The solution is:
Solution: Characteristic equation a r3 - 6 r2 + 11 r - 6 = 0 n = 1 3n + 2 n 3n
To determine 1, 2 , using the initial conditions, we have:
has 3 distinct roots r1 = 1, r2 = 2, r3 = 3. a0 = 1 = 1 , Therefore, the solution is a1 = 6 = 1 * 3 + 2 *1* 3 a  
n = 1 1n + 2 2n + 3 3n for some constants 1, 2, 3
Solving these equations, we have 1 = 1 and 2 = 1.
Therefore, the solution of the recurrence relation is: an = 3n + n 3n 54 56 14 Example 3 Example 4
Using the initial conditions, we have following equations to
Solve the following recurrence relation:
determine the value for constants 1, 2, 3: c a
n = – 4cn-1 + 3cn-2 + 18cn-3 , n  3, 0 = 2 = 1 + 2 + 3 c a 0 = 1; c1 = 2; c2 = 13. 1 = 5 = 1 + 2.2 + 3.3
Solution: Characteristic equation
a2 = 15 = 1 + 2.4 + 3.9.
Solving above equations, we have
r3 + 4r2 – 3r – 18 = (r – 2)(r + 3)2 = 0 
Hence, the solution of the recurrence relation:
1 = 1, 2 = -1 and 3 = 2.
Therefore, the solution of the recurrence relation is
cn = α10 2n + (α20 + α21 n)(– 3)n a where α n = 1 - 2n + 2. 3n 10, α20, α21 are constants 57 59 General case Example 4
Given linear homogeneous recurrence relation of degree k with constant
These constants are determined by using initial conditions: coefficients k 0 = c
Its characteristic equation is: a  c a n  i ni
0 = α10 20 + (α20 + α21.0) (-3)0 = α10 + α20 i1 2 = c k
1 = α10 21 + (α20 + α21.1) (-3)1 = 2α10 - 3α20 - 3α21 k r   ki c r  0 i
13 = c2 = α10 22 + (α20 + α21.2) (-3)2 = 4α10 + 9α20 +18α21 i 1 
Theorem 4: If the characteristic equation has t distinct roots
Solving three equations above, we have: α10 =1 ; α20 = -1; α21=1
r1,…,rt with multiplicities m1,…,mt (m1+…+mt = k). Then:
an = ( , +  , n + … +  , 𝑛 ) 𝑟 +
The solution of recurrence relation is: ( t m 1 n n , +  , n + … +  , 𝑛 ) 𝑟 + ... i      a  n r c 2 ( 1 n)( 3) n n   j n   ( i, j  i t,0 +  , n + … +  , 𝑛 ) 𝑟 i1  j0 
where n≥0, and αij are constants. 58 60 15
Linear nonhomogeneous recurrence relation with constant coefficients 2.5.2. Generating functions
• Linear nonhomogeneous recurrence relation with constant
Generating functions are a tool to solve a wide variety of counting
problems and recurrence relations.
coefficients) has the term F(n) dependent on n (and independent on any value of a Example 1: i ) : a
How many ways to give 12 oranges for three children: A, B and C such that:
n = c1an−1 + … + ckan−k + F(n)
A gets at least four, and B and C gets at least two, but C gets no more than five
a, b , c are the number of oranges
Linear homogeneous recurrence relation Nonhomogeneous term
that A, B and C gets, respectively
Find the number of integer solutions to
a + b + c = 12 where a ≥ 4, b ≥ 2, 2 c  5 63
2.5. Recurrence relations and generating functions 2.5.2. Generating functions 2.5.1. Recurrence relations Example 1:
Find the number of integer solutions to
a + b + c = 12 where a ≥ 4, b ≥ 2, 2 c  5 2.5.2. Generating functions Let
a: a(x) = x4 + x5 + x6 + x7 + x8
(since b + c  4  a  8)
b : b(x) = x2 + x3 + x4 + x5 + x6
(since a + c  6  b  6) c : c(x) = x2 + x3 + x4 + x5 (since 2  c  5) n=12
The coefficient of x12 in g(x) = a(x) b(x) c(x)
=(x4+ x5+ x6+ x7+ x8) (x2+ x3+x4+ x5+ x6)(x2+ x3+x4+ x5) =??? is the solution to the problem Why???
g(x) is called a generating function.
Assume xa, xb, xc are terms derived from (x4+ x5+ x6+ x7+ x8) , (x2+ x3+x4+ x5+ x6), (x2+ x3+x4+ x5)
respectively when developing the right-hand side  4 a  8, 2 b  6, 2 c  5
When developing the right-hand side, these three terms give us the term xn where n = a +b + c:
g(x) = (x4+ x5+ x6+ x7+ x8) (x2+ x3+x4+ x5+ x6)(x2+ x3+x4+ x5) = …. + Kxn +…..
The coefficient of xn in f(x) is the number of positive integer solutions to
a + b + c = n where 4 a  8, 2 b  6, 2 c  5 62 64 16 2.5.2. Generating functions 2.5.2. Generating functions Example 1:
Find the number of integer solutions to
Example 2: For the binomial coefficients we already know that:
a + b + c = 12 where a ≥ 4, b ≥ 2, 2 c  5 n n Let
(x  y)n  C(n,k) k nk x y
 (x 1)n  C(n,k) kx  g(x)
a: a(x) = x4 + x5 + x6 + x7 + x8
(since b + c  4  a  8) k 0 k 0 1. x4*x3*x5
b : b(x) = x2 + x3 + x4 + x5 + x6 (since a + c 6  b  6)
(x+1)n is the generating function for the sequence 2. x4*x4*x4 c : c(x) = x2 + x3 + x4 + x5 (since 2  c  5) 3. x4*x5*x3
C(n, 0), C(n, 1),…,C(n, k),…, C(n, n), 0,0,0…
The coefficient of x12 in g(x) = a(x) b(x) c(x) 4. x4*x6*x2
=(x4+ x5+ x6+ x7+ x8) (x2+ x3+x4+ x5+ x6)(x2+ x3+x4+ x5) 5. x5*x2*x5 which is 14, is the solution 6. x5*x3*x4
g(x) is called a generating function. 7. x5*x4*x3 8. x5*x5*x2 9. x6*x2*x4 10. x6*x3*x3 11. x6*x4*x2 12. x7*x2*x3 13. x7*x3*x2 14. x8*x2*x2 65 67 2.5.2. Generating functions 2.5.2. Generating functions Definition: Let a Definition: Let a
0, a1, a2, … be a sequence of real numbers. The function
0, a1, a2, … be a sequence of real numbers. The function   g(x)  a  a x  ... k a x  ...  a x g(x)  a  a x  ... k a x  ...  a x k  i k  i 0 1 i 0 1 i i0 i0
is called the generating function for the given sequence.
is called the generating function for the given sequence. A finite sequence
Some useful generating function: a
Ex1: (1  xn+1) = (1  x)(1 + x + x2 + x3 + ...+ xn). 0, a1, a2, …, an
So (1-xn+1)/(1-x) = 1 + x + x2 + x3 + ...+ xn,
can be regarded as the infinite sequence
 (1-xn+1)/(1-x) is the generating function for the sequence:
a0, a1, a2, …, an, 0, 0,… [set all terms higher than n to 0]
1, 1, 1, …, 1, 0, 0, 0, … . (where the first n+1 terms are 1) and its generating function
Ex2: From Ex1, If n   and |x| < 1, then 1 = (1  x)(1 + x + x2 + x3 + ...).
g(x) = a0 + a1x + a2x2 + … + anxn
So, 1/(1-x) = 1 + x + x2 + x3 + ... is a polynomial.
 1/(1-x) where |x| < 1 is the generating function for the sequence: 1, 1, 1, …, 1, … . 66 68 17 2.5.2. Generating functions
Generating functions are a tool to solve a wide variety of counting problems and recurrence relations.
Definition: Let a0, a1, a2, … be a sequence of real numbers. The function  g(x)  a  a x  ... k a x  ...  a x k  i 0 1 i i0
is called the generating function for the given sequence. 69 2.5.2. Generating functions
Example: Solve the recurrence relation an-3an-1 = n, n1, a0=1 𝑥
𝑔 𝑥 − 1 − 3𝑥𝑔(𝑥) = (1 − 𝑥) 1 𝑥 𝑔 𝑥 = + 1 − 3𝑥 (1 − 3𝑥)(1 − 𝑥) 1 𝐴 𝐵 𝐶 𝑔 𝑥 = + + + 1 − 3𝑥 (1 − 3𝑥) (1 − 𝑥) (1 − 𝑥) 3 1 1 
⇒ 𝐴 = ; 𝐵 = − ; 𝐶 = − ; g x  a  a x   k a x   i 4 4 2 ( ) ... ... a x k  0 1 i 7/4 −1/4 −1/2 i0 𝑔 𝑥 = + + (1 − 3𝑥) (1 − 𝑥) (1 − 𝑥)
We find an by determining the coefficient of xn in g(x)
 determining the coefficient of xn in each of the three summands 70 18