0% found this document useful (0 votes)
3 views106 pages

Chapter 3 ; Enumerative Analysis

The document discusses Enumerative Analysis, focusing on counting methods such as Basic Counting Principles, the Principle of Inclusion-Exclusion, Recurrence Relations, and Generating Functions. It emphasizes the importance of counting in various discrete problems, including algorithm runtime estimation and probability theory. Each section provides definitions, examples, and applications of the counting methods.

Uploaded by

kisamobrayson
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views106 pages

Chapter 3 ; Enumerative Analysis

The document discusses Enumerative Analysis, focusing on counting methods such as Basic Counting Principles, the Principle of Inclusion-Exclusion, Recurrence Relations, and Generating Functions. It emphasizes the importance of counting in various discrete problems, including algorithm runtime estimation and probability theory. Each section provides definitions, examples, and applications of the counting methods.

Uploaded by

kisamobrayson
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 106

Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

ENUMERATIVE ANALYSIS

Dr. E. Mujuni

June 7, 2021
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Contents

1 Introduction
2 Basic Counting Principles
The Sum Rule
The Product Rule
3 Principle of Inclusion-Exclusion
4 Recurrence Relations
Definitions & Terminologies
First Order Linear Recurrence Relations
The 2nd Order Linear Homogeneous Relation
Non-Homogeneous Recurrence Relations
Examples of Applications of Recurrence Relations
5 Generating Functions
Introduction
Definitions and Techniques
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Contents

1 Introduction
2 Basic Counting Principles
The Sum Rule
The Product Rule
3 Principle of Inclusion-Exclusion
4 Recurrence Relations
Definitions & Terminologies
First Order Linear Recurrence Relations
The 2nd Order Linear Homogeneous Relation
Non-Homogeneous Recurrence Relations
Examples of Applications of Recurrence Relations
5 Generating Functions
Introduction
Definitions and Techniques
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Contents

1 Introduction
2 Basic Counting Principles
The Sum Rule
The Product Rule
3 Principle of Inclusion-Exclusion
4 Recurrence Relations
Definitions & Terminologies
First Order Linear Recurrence Relations
The 2nd Order Linear Homogeneous Relation
Non-Homogeneous Recurrence Relations
Examples of Applications of Recurrence Relations
5 Generating Functions
Introduction
Definitions and Techniques
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Contents

1 Introduction
2 Basic Counting Principles
The Sum Rule
The Product Rule
3 Principle of Inclusion-Exclusion
4 Recurrence Relations
Definitions & Terminologies
First Order Linear Recurrence Relations
The 2nd Order Linear Homogeneous Relation
Non-Homogeneous Recurrence Relations
Examples of Applications of Recurrence Relations
5 Generating Functions
Introduction
Definitions and Techniques
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Contents

1 Introduction
2 Basic Counting Principles
The Sum Rule
The Product Rule
3 Principle of Inclusion-Exclusion
4 Recurrence Relations
Definitions & Terminologies
First Order Linear Recurrence Relations
The 2nd Order Linear Homogeneous Relation
Non-Homogeneous Recurrence Relations
Examples of Applications of Recurrence Relations
5 Generating Functions
Introduction
Definitions and Techniques
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Enumerative Analysis is concerned with counting the number of


elements of a finite set S.

The problem of counting number of element arises in many discrete


problems.

For example, in order to estimate the run time of an algorithm, we


need o count the number of times certain steps or loops were
executed.

Counting also play a crucial role in probability theory.


Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Enumerative Analysis is concerned with counting the number of


elements of a finite set S.

The problem of counting number of element arises in many discrete


problems.

For example, in order to estimate the run time of an algorithm, we


need o count the number of times certain steps or loops were
executed.

Counting also play a crucial role in probability theory.


Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Enumerative Analysis is concerned with counting the number of


elements of a finite set S.

The problem of counting number of element arises in many discrete


problems.

For example, in order to estimate the run time of an algorithm, we


need o count the number of times certain steps or loops were
executed.

Counting also play a crucial role in probability theory.


Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Enumerative Analysis is concerned with counting the number of


elements of a finite set S.

The problem of counting number of element arises in many discrete


problems.

For example, in order to estimate the run time of an algorithm, we


need o count the number of times certain steps or loops were
executed.

Counting also play a crucial role in probability theory.


Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Because of the importance of counting, a number of methods have


been developed. In this chapter we discuss the following methods

(a) Basic Counting Principles

(b) The Principle of Inclusion-Exclusio

(c) Recurrence Relations

(d) Generating Functions


Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Because of the importance of counting, a number of methods have


been developed. In this chapter we discuss the following methods

(a) Basic Counting Principles

(b) The Principle of Inclusion-Exclusio

(c) Recurrence Relations

(d) Generating Functions


Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Because of the importance of counting, a number of methods have


been developed. In this chapter we discuss the following methods

(a) Basic Counting Principles

(b) The Principle of Inclusion-Exclusio

(c) Recurrence Relations

(d) Generating Functions


Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Because of the importance of counting, a number of methods have


been developed. In this chapter we discuss the following methods

(a) Basic Counting Principles

(b) The Principle of Inclusion-Exclusio

(c) Recurrence Relations

(d) Generating Functions


Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Because of the importance of counting, a number of methods have


been developed. In this chapter we discuss the following methods

(a) Basic Counting Principles

(b) The Principle of Inclusion-Exclusio

(c) Recurrence Relations

(d) Generating Functions


Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Basic Counting Principles


Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

We have two counting principles:

the Sum rule

the Product rule


Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

We have two counting principles:

the Sum rule

the Product rule


Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

We have two counting principles:

the Sum rule

the Product rule


Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

The Sum Rule


It states:
“Suppose we have two tasks to be performed. If the first task can be
done in m ways and the second can be done in n ways, and if these
two tasks cannot be done at the same time, then there are m + n
ways to either task. ”

Example
Math Library has 40 textbooks on Calculus and 50 textbooks on
Discrete Mathematics. How many ways can a student select/choose
a book
Solution:
1 The first task is to select a Calculus Book. A student can select
in 40 different ways.
2 Second task is to select a Discrete Book. A student can select in
50 different ways
Therefore, by the sum rule, a student can select a book 40 + 50 = 90
different ways.
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

The Sum Rule


It states:
“Suppose we have two tasks to be performed. If the first task can be
done in m ways and the second can be done in n ways, and if these
two tasks cannot be done at the same time, then there are m + n
ways to either task. ”

Example
Math Library has 40 textbooks on Calculus and 50 textbooks on
Discrete Mathematics. How many ways can a student select/choose
a book
Solution:
1 The first task is to select a Calculus Book. A student can select
in 40 different ways.
2 Second task is to select a Discrete Book. A student can select in
50 different ways
Therefore, by the sum rule, a student can select a book 40 + 50 = 90
different ways.
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

The Sum Rule


It states:
“Suppose we have two tasks to be performed. If the first task can be
done in m ways and the second can be done in n ways, and if these
two tasks cannot be done at the same time, then there are m + n
ways to either task. ”

Example
Math Library has 40 textbooks on Calculus and 50 textbooks on
Discrete Mathematics. How many ways can a student select/choose
a book
Solution:
1 The first task is to select a Calculus Book. A student can select
in 40 different ways.
2 Second task is to select a Discrete Book. A student can select in
50 different ways
Therefore, by the sum rule, a student can select a book 40 + 50 = 90
different ways.
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

The Sum Rule


It states:
“Suppose we have two tasks to be performed. If the first task can be
done in m ways and the second can be done in n ways, and if these
two tasks cannot be done at the same time, then there are m + n
ways to either task. ”

Example
Math Library has 40 textbooks on Calculus and 50 textbooks on
Discrete Mathematics. How many ways can a student select/choose
a book
Solution:
1 The first task is to select a Calculus Book. A student can select
in 40 different ways.
2 Second task is to select a Discrete Book. A student can select in
50 different ways
Therefore, by the sum rule, a student can select a book 40 + 50 = 90
different ways.
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

We can extend the Sum rule to more than two tasks. Suppose the
tasks T1 , T2 , . . . , Tn can respectively be done in m1 , m2 , . . . , mn and
no two of these can be done at the same time. Then the number of
ways to do one of these tasks is m1 + m2 + . . . + mn different ways.
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Example
What is the value of k after the code below has been executed: k:=0
for i:=1 to n1 do
k:=k+1
for i:=1 to n2 do
k:=k+1
for i:=1 to n3 do
k:=k+1
.
.
for i:=1 to nm do
k:=k+1
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Solution

1 The initial value of k is zero (0).


2 The block is made up of m different loops.
3 Each time a loop is traversed, 1 is added to k.
4 Let Ti be the task of traversing the i th loop. Task Ti can be done
in ni ways.
5 Therefore, by the sum rule, the final value of k is
n1 + n2 + . . . + nm
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

The Product Rule

The Rule States


“Suppose that a procedure can be broken down into two tasks. If
there are m ways to do the first task and n ways to do the second
task, after the first task has been done. Then there are mn ways to do
the procedure. ”
We can also extend the product rule to more than two tasks. Suppose
that a procedure is carried pout by performing the task T1 , . . . , Tm . If
Ti (1 ≤ i ≤ m) can be done in ni ways after tasks T1 , . . . , Ti−1 have
been done. Then there are n1 n2 . . . nm ways to carry out the
procedure.
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Example
How many different ways to construct a bit string of length 7.

Solution
Each of the seven bits can be chosen in two ways, since each bit is
either 0 or 1. Therefore, by the product rule, there are
2 × 2 × 2 × 2 × 2 × 2 × 2 = 27 = 128 different bit string of length 7
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Example
What is the value of k after the following code has been executed:
k:=0
for i:=0 to n1 do
for i:=0 to n2 do
for i:=0 to n3 do
...
for i:=0 to nm do
k:=k+1
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Solution

1 The initial value of k is zero


2 Each nested loop is traversed, 1 is added to k
3 Let Ti be the task of traversing the i th loop. Then the number of
times the loop is visited is way to do task Ti . . . Tm .
4 Therefore, by the Product rule, the final value of k is
n1 × . . . × nm.
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Principle of
Inclusion-Exclusion
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

The Principle of Inclusion-Exclusion is used to count the number of


ways to do one of the two tasks, where these tasks can be done at
the same time. Examples will illustrate how this principle is applied.

Example
How many bits of length four either start with a 1 or end with two bits
00 are there?
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Solution

1 The first task is constructing a bit string of length 4 beginning


with a 1 bit. This can be done in 23 = 8 ways.
2 The second task is constructing a bit string of length 4 ending
with two bits 00. This can be done in 22 = 4
3 Both tasks of constructing a bit string of length 4 that begins with
1 and ends with 00. This can be done in 21 = 2 ways.
4 Therefore, the number of bits of length 4 that begin with 1 and
end with 00, which equal the number of ways to do task 1 or task
2 is equal 8+4-2=10.
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

We can phrase this counting in terms of sets. Let A1 and A2 be two


sets. Let T1 and T2 be the ways of selecting an element of A1 and A2 ,
respectively. There are |A1 | ways to do T1 and |A2 | ways to do T2 .
Therefore the number of ways to do T1 or T2 is the sum of number of
ways |A1 | and |A2 |, minus the number of the number of ways to do
both T1 and T2 (since they have been counted twice, first in T1 then in
T2 .)
Since there are |A1 ∪ A2 | ways either do T1 or T2 and |A1 ∩ T2 | ways
to do both T1 and T2 , it follows that

|A1 ∪ A2 | = |A1 | + |A2 | − |A1 ∩ A2 | (1)


Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

We can extend Equation 1 to a collection involving more than two


sets. For instance, suppose that A1 , A2 and A3 are finite sets. The
sum of their cardinality |A1 | + |A2 | + |A3 | counts the elements in
A1 ∩ A2 are counted twice, first when they appear in A1 and second
when they appear in A2 .
Similarly, the elements in A1 ∩ A2 and A2 ∩ A3 are also counted twice.
The elements in A1 ∩ A2 ∩ A3 are counted three times. However, the
sum |A1 | + |A2 | + |A3 | − |A1 ∩ A2 | − |A1 ∩ A3 | − |A2 ∩ A3 | counts only
the elements of A1 ∪ A2 ∪ A3 but not on A1 ∩ A2 ∩ A3. Thus we add
|A1 ∩ A2 ∩ A3 |. Hence, for three sets we have:

|A1 ∪A2 ∪A3 | = |A1 |+|A2 |+|A3 |−|A1 ∩A2 |−|A1 ∩A3 |−|A2 ∩A3 |+|A1 ∩A2 ∩A3 |
(2)
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

We now state the principle of Inclusion-Exclusion, which tells us how


many elements are in the union of a finite number of finite sets.

Theorem (The Principle of Inclusion-Exclusion)

Let A1 , A2 , . . . , An be finite sets. Then


X X X
|A1 ∪ A2 ∪ . . . ∪ An | = |Ai | − |Ai ∩ Aj | + |Ai ∩ Aj ∩ A
1≤i≤n 1≤i<j≤n 1≤i<j<k ≤n

. . . + (−1)n+1 |A1 ∩ A2 ∩ . . . ∩ An |

Before proving the above the above theorem, we present basic few
formulas.
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

If we start with a set A with n elements. Then each selection or


combination of r of the elements of A, with no reference to order,
corresponds to r !×permutations of size r from n elements. Thus the
number of combinations of size r from a collection of size n, denoted
by C(n, r ), 0 ≤ r ≤ n, is given by

n!
C(n, r ) =
r !(n − r )!

In addition to C(n, r ), the symbol nr is also frequently used.



Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Theorem (The Binomial Theorem)


If x and y are variables and n is a positive integer, then
         
n n n n n−1 n n−2 2 n n−1 n n
(x+y ) = x + x y+ x y +. . .+ xy + y
0 1 2 n−1 n
(3)

Proof Exercise
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Corollary

For any integer n > 0,


(a) 2n = n0 + n1 + 2 + . . . + nn
   

(b) 0 = n0 − n1 + 2 + . . . + (−1)n nn
   

Proof Exercise
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

We now present a proof of Theorem 1


Proof
Let x ∈ A1 ∪ A2 ∪ . . . ∪ An be an arbitrarily chosen element. Then, we
prove the formula by showing that x is counted once by the right-hand
side of the equation. Suppose that x is a member of r sets
A1 , A2 , . . . , Ar where 1 ≤ r ≤ n. This element is counted 1r times by
|Ai |. It is counted 2r times by
P P
|Ai ∩ Aj |. In general, it is counted
r

m times by the summation involving m sets Ai . Thus, this element is
counted exactly
       
r r r r
− + − . . . + (−1)r +1
1 2 3 r

time by the expression on the right-hand side of this equation. Our


goal is to evaluate this quantity. On the other hand, by Corollary 3 we
have
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

         
r r r r r r
− + − + . . . + (−1) =0
0 1 2 3 r
Hence
         
r r r r r
1= = − + − . . . + (−1)r +1
0 1 2 3 r

Therefore, x is counted exactly once. This finishes the proof


Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Application of the Inclusion-Exclusion Principle

Example
Determine the number of positive integers n, where 1 ≤ n ≤ 100 and
n is divisible by 2, 3 or 5.

Solution
Let A, B and C be the set of positive integers n , 1 ≤ n ≤ 100,
divisible by 2 ,3 and 5, respectively. Then the answer is |A ∪ B ∪ C|.
We now introduce the following notation. For x ∈ <, let bxc denote
the largest integer smallest than x. For example, b3.13c = 3,
b34.98c = 34 and b23.45c = 23
Then |A| = b 100 100 100
2 c = 50, |B| = b 3 c = b33.33c = 33, |C| = b 5 c = 20,
100 100 100
|A ∩ B| = b 2×3 c = b 6 c = 16, |A ∩ C| = b 2×5 c = 10,
100 100
|B ∩ C| = b 3×5 c = 6 and |A ∩ B ∩ C| = b 2×3×5 c = 3. Apply the
Inclusion-Exclusion principle we get
|A ∪ B ∪ C| = 50 + 33 + 20 − 16 − 10 − 6 + 3 = 74. Therefore, there
are 74 numbers from 1 to 100 divisible by 2, 3 or 5.
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Example
Determine the number of prime number not exceeding hundred (100).

Solution
Note that a non prime number is drivable by a prime number not
exceeding its square root. So the prime numbers not exceeding 100
are not divisible by 2, 3, 5 and 7.
Let A1 , A2 , A3 and A4 be the set of integers (≤ 100) that are divisible
0 0 0 0
by 2, 3, 5 and 7, respectively. Let A1 A2 A3 A4 be the set of positive
number not exceeding 100 divisible to none of 2,3,5 and 7.
0 0 0 0
|A1 A2 A3 A4 | = |U| − |A1 ∪ A2 ∪ A2 ∪ A4 |. (4)
Where U is the set of all positive number greater than 1 but not
exceeding 100.
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Example
Determine the number of prime number not exceeding hundred (100).

Solution
Note that a non prime number is drivable by a prime number not
exceeding its square root. So the prime numbers not exceeding 100
are not divisible by 2, 3, 5 and 7.
Let A1 , A2 , A3 and A4 be the set of integers (≤ 100) that are divisible
0 0 0 0
by 2, 3, 5 and 7, respectively. Let A1 A2 A3 A4 be the set of positive
number not exceeding 100 divisible to none of 2,3,5 and 7.
0 0 0 0
|A1 A2 A3 A4 | = |U| − |A1 ∪ A2 ∪ A2 ∪ A4 |. (4)
Where U is the set of all positive number greater than 1 but not
exceeding 100.
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

This implies |U | = 99.


By applying the principle of Inclusion-Exclusion, we have

|A1 ∪ A2 ∪ A2 ∪ A4 | = |A1 | + |A2 | + |A3 | + |A4 |


−(|A1 ∩ A2 | + |A1 ∩ A3 | + |A1 ∩ A4 | + |A2 ∩ A3 | + |A2 ∩ A4 |
+(|A1 ∩ A2 ∩ A3 | + |A1 ∩ A2 ∩ A4 | + |A1 ∩ A3 ∩ A4 | + |A2 ∩ A
−|A1 ∩ A2 ∩ A3 ∩ A4 |

Now, |A1 | = b 100


2
c = 50, |A2 | = b 100
3
c = 33, |A3 | = b 100
5
c = 20,
100 100 100
|A1 | = b 7 c = 14, |A1 ∩ A2 | = b 2×3 c = 16, |A1 ∩ A3 | = b 2×5 c = 10,
100 100 100
|A1 ∩ A4 | = b 2×7 c = 7, |A2 ∩ A3 | = b 3×5 c = 6, |A2 ∩ A4 | = b 3×7 c = 4,
100
|A3 ∩ A4 | = b 5×7 c = 2,
100 100
|A1 ∩ A2 ∩ A3 | = b 2×3×5 c = 3, |A1 ∩ A2 ∩ A4 | = b 2×3×7 c = 2,
100 100
|A1 ∩ A3 ∩ A4 | = b 2×5×7 c = 1, |A2 ∩ A3 ∩ A4 | = b 3×5×7 c = 0 and
100
|A1 ∩ A2 ∩ A3 ∩ A4 | = b 2×3×5×7 c = 1. So,
0 0 0 0
|A1 A2 A3 A4 | = 21

However 2, 3,5, and 7 are also prime. Therefore The total number of prime
number is 21 + 4 = 25.
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Example
In a certain village there are five villages. An engineer is to device a
system of two-ways road so that after the system is completed, no
village is isolated. In how many ways the engineer do this?

Solution
Call these village v1 , v2 , v3 , v4 and v5 . So, we seek the number of
simple graphs on 5 vertices without isolated vertex. Consequently, we
want to count situation like (a), (b) in Figure 1, but no situation (c).
v2 v2 v2
v1
s s v1
s s v1
s s

sv3 sv3 :Nsv3


sv5 sv5 sv5
k
sv4 sv4 sv4
/
(a) (b) (c)

Figure:
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Let S be a set of all possible systems, and for 1 ≤ i ≤ 5 let Ai be a set


of systems in which village i is isolated. So the
P answer is
|S| − |A1 ∪ A1 ∪ A2 ∪ A3 ∪ A4 ∪ A5|. Let Si = |Am1 ∩ Am2 ∩ . . . ∩ Ami |.
Now |S| = 210 , since there are 52 = 10 possible two-way roads for
these five villages, and
 each road can be included orexcluded.
|A1 | = 26 and S1 = 51 26 ; |A1 ∩ A2 | = 23 and S2 = 52 23 ;
|A1 ∩ A2 ∩ A3 | = 21 and S2 = 53 21 ; |A1 ∩ A2 ∩ A3 ∩ A4 | = 20 and


S4 = 54 20 ; |A1 ∩ A2 ∩ A3 ∩ A4 ∩ A5 | = 20 and S4 = 55 20 . Therefore,


 

by the Principle of Inclusion and Exclusion, the answer is


         
10 5 6 5 3 5 1 5 0 5 0
2 − 2 + 2 − 2 + 2 − 2 = 768.
1 2 3 4 5
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Recurrence Relations
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

In this section we will investigate numerical function a(n), preferbly,


an , n ≥ 1, where an depends upon some prior terms
a0 , a1 , a2 , . . . , an−1 .

Definition
A recurrence relation for the sequence {an } is a formula that
expresses an in terms of one or more of the previous terms of the
sequence, namely, a0 , a1 , a2 , . . . , an−1 for all integers n ≤ 0. A
sequence is called a solution of a recurrence relation if its terms
satisfy the recurrence relation.
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Example
Let {an } be a sequence that satisfies the recurrence relation
an = an−1 − an−2 for n = 2, 3, . . ., and suppose that a0 = 3 and
a1 = 5. What are a2 and a3 .

Solution
We see from the recurrence relation that a2 = a1 − a0 = 5 − 3 = 2
and a3 = a2 − a1 = 2 − 5 = −3.
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Definition
Let k ∈ Z + , and cn (6= 0), cn−1 , cn−2 , . . . , cn−k (6= 0) be real numbers. If
an , n ≥ 0, is a discrete numerical function, then

cn an + cn−1 an−1 + cn−2 an−2 + . . . cn−k an−k = f (n),

is a linear recurrence (with constant coefficients) of order k . When


f (n) = 0, for all n ≤ 0, the relation is called Homogenous, otherwise
it is nonhomogeneos.
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Example
The relation an = 5an−1 is the first order linear homogeneous
relation.
The relation fn = fn−1 + 2fn−3 is the 3rd order linear
homogeneous recurrence.

Example
2
The relation an = an−1 + an−2 is not linear.
The recurrence nn = nbn−1 does not have constant coefficients.
The recurrenceHn = 2Hn−1 + 1 is nonhomogenous.
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Example
The relation an = 5an−1 is the first order linear homogeneous
relation.
The relation fn = fn−1 + 2fn−3 is the 3rd order linear
homogeneous recurrence.

Example
2
The relation an = an−1 + an−2 is not linear.
The recurrence nn = nbn−1 does not have constant coefficients.
The recurrenceHn = 2Hn−1 + 1 is nonhomogenous.
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

First Order Linear Recurrence Relations

Consider the following sequence:

5, 15, 45, 135, . . .

In this particular geometric series, we have

an+1 = 3an

However, the recurrence an+1 = 3an does not define a unique


sequence. For example, the sequnce 7, 21, 63, . . . is also defined by
the relation an+1 = 3an .
In order to pinpoint the particular sequence described by an+1 = 3an
we need to know one of the terms of the sequnce.
So, we say that the sequence 5, 15, 45, 135, . . . is uniquely defined by
the recurrence relation

an+1 = 3an , n ≤ 0, a0 = 5
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Consider the recurrence relation an+1 = 3an , n ≤ 0, a0 = 5. Then

a0 = 5
a1 = 3a0 = 3(5)
a2 = 3a1 = 3(3a0 ) = 32 a0
a3 = 3a1 = 3(3a1 ) = 33 a0
..
.
an = 3a1 == 3n a0

Therefore
an = 3a1 == 3n a0 (5)
Equation 5 is called the general solution of the given recurrence
relation. If we wwish to compute a10 , simply calculate
a10 = 310 · · · 5 = 295, 245
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Example
Solve the recurrence relation an = 7an−1 , n ≤ 1, a2 = 98

Solution
an = a0 7n is a general solution. Since a2 = 98, it follows that
98 = a0 72 . This implies that a0 = 2. Hence, a particular solution is
an = 2(7n ).
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Example
2
Find a12 if an+1 = 5an2 , where n ≥ 0, a0 = 2.

Solution
Let bn = an2 . Then bn+1 = 5b√ n , n ≤ 0, b0 = 4, which implies that
bn = 4 · · · 5n . Hence an = 2( 5)n , n ≥ 0, a0 = 2. Hence
a12 = 31, 250
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

The 2nd Order Linear Homogeneous Relation

In this section we concentrate on the homogenous relarence relation


of the form
an + c1 an−1 + c2 an−2 = 0 (6)
where c1 , and c2 are constants. We seek solutions of the form

an = Cr n

Substitute an = Cr n in equation 6, we obtain

Cr n + c1 Cr n−1 + c2 Cr n−2 = 0 (7)

Simplify 7, to obtain
r 2 + c1 r + c2 = 0 (8)
which is a quadratic equation. Equation 8 is called the Characteristic
equation of the relation.
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Theorem
Let c1 and c2 be real numbers. Suppose that r 2 + c1 r + c2 = 0 has
two distinct roots r1 and r2 . Then the sequence {an } is a solution of
the recurrence relation an + c1 an−1 + c2 an−2 = 0 if and only if
an = α1 r1n + α2 r2n for n = 0, 1, 2, . . . , where α1 and α2 are constants.

Now, the roots of equation 8, r1 and r2 , fall into three cases:


A: r1 and r2 are real and distinct
B: r1 and r2 are real and but r1 = r2
A: r1 and r2 form a compex conjage pair
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Case A : Distinct Real Root


Example
Solve the recurrence relation

an + an−1 − 6an−2 = 0, n ≥ 2, a0 = 1, a1 = 2

Solution
Let an = Cr n , C, r 6= 0. So we obtain Cr n + Cr n−1 − 6r r −2 = 0.
Hence r 2 + r − 6 = 0, which implies r1 = 2 and r2 = −3.
Since we have two distinct real roots, an = 2n and (−3)n are both
solution. Since they are linearly independent, an = C1 2n + C2 (−3)n ,
where C1 and C2 are constants.
With a0 = 1 and a1 = 2, then we have
a0 = C1 (2)0 + C2 (−3)0 = C1 + C2 = 1
1 1
a1 = C1 (2) + C2 (−3) = 2C1 − 3C2 = 2

Solving this system, we find c1 = 1 and c2 = 0. Therefore, an = 2n is


the unique solution of the given relation.
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Example
Solve the recurrence relation

Fn+2 = Fn+1 + Fn , n ≤ 0, F0 = 0, F1 = 1

(This relation is known as Fibonacci Relation)

Solution
Let Fn = Cr n , Cr 6= 0, n ≥ 0. We substitute

in the relation,

we get
r 2 − r − 1 = 0. This implies r1 = 1+2 5 and r2 = 1−2 5 . So the general
solution is √ √
1+ 5 n 1− 5 n
Fn = C1 ( ) + C2 ( )
2 2
With F0 = 0 and F1 = 1, C1 = √1 and C1 = √1 , the unique solution is
5 5
√ √
1+ 5 n 1− 5 n
Fn = ( √ ) − ( √ )
2 5 2 5
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Case B : Equal Roots


Example
Solve the recurrence relation

an = 4an−1 − 4an−2 , n ≥ 2, a0 = 1, a1 = 3

Solution
Let an = Cr n , where C, r 6= 0. Then the characterist equation of the
relation is
r 2 − 4r + 4 = 0.
The roots of the characterist equation are r1 = r2 = 2.
In this case, the general solution is

an = C1 (2)n + C2 n(2)n

with a0 = 1 and a1 = 3, we find c1 = 1 and c2 = 12 . Hence, the


particular solution is
1
an = (2)n + n(2)n
2
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Case C : Complex Roots

Before discussing how to handle this case, we give a short review on


complex number.
Let z = x + iy be a complex number.
p Then we write
z = r (cos θ + i sin θ), where r = x 2 + y 2 and θ = arctan yx . By the


De Moivre’s theorem we have

(cos θ + i sin θ)n = cos nθ + sin nθ


Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Example

Determine (1 + i 3)10

Solution √
Let z = 1 + i 3. Then z = 2(cos π3 + i sin π3 ). Hence,
π π
z 10 = 210 (cos + i sin )10
3 3
10π 10π
= 210 (cos + i sin )
3 3
4π 4π
= 210 (cos + i sin )
3 √ 3
1 3
= 210 (− − i )
2 √2
= −29 (1 + i 3)
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

We now solve the following problem

Example
Solve the recurrence relation

an = 2an−1 − 2an−2 , n ≥ 2, a0 = 1 a1 = 2

Solution
Let an = Cr 2 , C, t 6= 0. So r 2 − 2r + 2 = 0. Hence r1 = 1 + i and
r2 = 1 − i. Consequently, the general solution is

an = C1 (1 + i)n + C2 (1 − i)n ,

where C1 and C2 are constants.


Now
√ π π
1+i = 2(cos + i sin )
4 4
√ π π
1−i = 2(cos − i sin )
4 4
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

This yields
√ π π √ π π
an = C1 ( 2)n (cos + i sin )n + C2 ( 2)n (cos − i sin )n
4 4 4 4
√ n π π n π π n
= ( 2) (C1 (cos + i sin ) + C2 (cos − i sin ) )
4 4 4 4
√ n nπ nπ nπ nπ
= ( 2) (C1 (cos + i sin ) + C2 (cos − i sin ))
4 4 4 4
√ n nπ nπ
= ( 2) (k1 cos + k2 sin )
4 4
where k1 = C1 + C2 and k2 = i(C1 − C2 ) With a0 = 1 and a1 = 2, we
find k1 = 1 and k2 = 1. Therefore, the unique solution is
√ nπ nπ
an = ( 2)n (cos + sin )
4 4
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Non-Homogeneous Recurrence Relations

We want to solve recurrence relations of the form

an + Can−1 = f (n), n ≥ 1 (9)

an + C1 an−1 + C2 an−2 = f (n), n ≥ 2 (10)


Where c1 and C2 are constants, f (n) 6= 0.
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

There are no general solution for this type of probelem. However,


when f (n) has a certain form, we can find a successfull technique.
For example, for the reccurence relation an − an−1 = f (n), it follows

an = an−1 + f (n)
a1 = a0 + f (1)
a2 = a0 + f (1) + f (2)
a3 = a0 + f (1) + f (2) + f (3)
..
.
n
X
an = a0 + f (1) + f (2) + f (3) . . . + f (n) = a0 + f (i)
i=1
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Example
Solve the relation

an − an−1 = 3n2 , n ≥ 1, a0 = 7

Solution

n
X n
X
an = a0 + f (i) = 7 + 3 i2
i=1 i=1
1
= 7 + n(n + 1)(2n + 1)
2
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Undetermined coefficient

When the formula for the summation is not know, we use a


method known as undetermined coefficient, which relies on
upon the associated homogeneous relation obtained when f (n)
is replaced by 0.

(h)
For either equation 9 and equation 10 let an and denotes the
(p)
general solution associated with homogenous, and let an be a
(p)
solution of the given non-homogenous relation (an is called a
(h) (p)
Particular solution). Then an = an + an is the general solution
of the given solution.
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Undetermined coefficient

When the formula for the summation is not know, we use a


method known as undetermined coefficient, which relies on
upon the associated homogeneous relation obtained when f (n)
is replaced by 0.

(h)
For either equation 9 and equation 10 let an and denotes the
(p)
general solution associated with homogenous, and let an be a
(p)
solution of the given non-homogenous relation (an is called a
(h) (p)
Particular solution). Then an = an + an is the general solution
of the given solution.
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Example

Solve the recurrence relation

an − 3an−1 = 5(7n ), n ≥ 1, a0 = 2.

Solution
(h)
The solution of the associated homogeneous relation is an = C(3n ).
(p)
Since f (n) = 7(5n ), we seek a particular solution an of the form A.7n .
(p)
As an is to be a solution of the given nonhomogeneous relation, we
(p)
replace an = A(7n ) into the given relation and find that
A(7n ) − an−1 = 5(7n ), n ≥ 1, a0 = 2.
35 (p) 35 n
which implies, 7A − 3A = 35. So A = 4 and an = 4 7 = 54 7n+1 .
The general solution is
5 n+1
an = C(3n ) + 7 .
4
With a0 = 2 we find C = − 27
4 and
27 n 5 5 1
an = − (3 ) + 7n+1 = 7n+1 − (3n+3 )
4 4 4 4
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Example

Solve the recurrence relation

an − 3an−1 = 5(7n ), n ≥ 1, a0 = 2.

Solution
(h)
The solution of the associated homogeneous relation is an = C(3n ).
(p)
Since f (n) = 7(5n ), we seek a particular solution an of the form A.7n .
(p)
As an is to be a solution of the given nonhomogeneous relation, we
(p)
replace an = A(7n ) into the given relation and find that
A(7n ) − an−1 = 5(7n ), n ≥ 1, a0 = 2.
35 (p) 35 n
which implies, 7A − 3A = 35. So A = 4 and an = 4 7 = 54 7n+1 .
The general solution is
5 n+1
an = C(3n ) + 7 .
4
With a0 = 2 we find C = − 27
4 and
27 n 5 5 1
an = − (3 ) + 7n+1 = 7n+1 − (3n+3 )
4 4 4 4
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Example

Solve the recurrence relation

an − 3an−1 = 5(7n ), n ≥ 1, a0 = 2.

Solution
(h)
The solution of the associated homogeneous relation is an = C(3n ).
(p)
Since f (n) = 7(5n ), we seek a particular solution an of the form A.7n .
(p)
As an is to be a solution of the given nonhomogeneous relation, we
(p)
replace an = A(7n ) into the given relation and find that
A(7n ) − an−1 = 5(7n ), n ≥ 1, a0 = 2.
35 (p) 35 n
which implies, 7A − 3A = 35. So A = 4 and an = 4 7 = 54 7n+1 .
The general solution is
5 n+1
an = C(3n ) + 7 .
4
With a0 = 2 we find C = − 27
4 and
27 n 5 5 1
an = − (3 ) + 7n+1 = 7n+1 − (3n+3 )
4 4 4 4
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Example
Solve the recurrence relation

an − 3an−1 = 5(3n ), n ≥ 1, a0 = 2

Solution
(h) (h)
As in Example 20, an = C(3n ), but here an and f (n) are not linearly
(p)
independent. As a result, we consider a particular solution an of the
n (p) n
form An(3 ). Substituting an = An(3 ) into the given relation we
have

An(3n ) − 3A(n − 1)(3n−1 ) = 5(3n ), or An − A(n − 1) = 5, so A = 5

Hence
(h) (p)
an = an + an = (C + 5n)3n , n ≥ 2.
With a0 = 2, the unique solution is

an = (2 + 5n)3n
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Examples of Applications of Recurrence Relations

Example 1
Assume that the population of a country in 2015 was 7 million and
has been growing 2.5% a year
1 Set up a recurrence relation for the number of population of the
country n years after 2015.
2 Find an explicit formula for the population of the country n year
after 2015.
3 What will the population of the country be in 2021?
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Solution
1 Let pn be the population after n years. Then

2.5
pn = pn−1 + pn−1
100
That is,
pn = 1.025pn−1
2 Solving the above equation,we obtain pn = p0 (1.025)n . Since
p0 = 7, 000, 000, it follows P0 = 4, 271, 897. Hence,

pn = 7, 000, 000(1.025n )
3 n = 2021 − 2015 = 6. Therefore

p6 = 7, 000, 000(1.025)6
= 8, 117, 854
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Examples of Applications of Recurrence Relations

Example 2
Mr. Johnson has taken a loan of 9,000,000 for a bank, and he is
required to pay back the money in 48 months. Suppose that 1.5% is
the interest rate per month for the loan.
1 Formulate this a recurrence relation in order to determine the
constant payment P that Mr. Johnson must make every month.
2 Solve the recurrence relation in (b)(i).
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Solution
1 Let an denote the amount still owed on the loan at the end of the
nth period. Then at the end of the (n + 1)st period, the amount
Paul still owes on his loan is an (amount he owed at the nth
period)+ ran (the interest that accrued during the (n + 1)st
period)-P (the payment she made at the end of the (n + 1)st
period). This gives the recurrence relation

an+1 = an + ran − P, 0 ≤ n ≤ T − 1, a0 = S, aT = 0.

Given that r = 0.015, T = 48, S = 9, 000, 000, the recurrence


relation becomes:

an+1 = (1.015)an − P, 0 ≤ n ≤ 47, a0 = 9, 000, 000, aT = 0.

which is 1st order non-homogeneous.


Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Solution, cont...
(h) (p)
2 For this relation, an = c(1 + r )n , while an = A, since −P is a
solution of the associated non-homogeneous relation. With
(p)
an = A, we find
A − (1 + r )A = −P,
so A = Pr . From a0 = S, we obtain an = (S − P/r )(1 + r )n + P/r ,
0 ≤ n ≤ T.
Since 0 = aT = (S − P/r )(1 + r )T + P/r , it follows that

(P/r ) = ((P/r ) − S)(1 + r )T and P = (Sr )[1 − (1 + r )−T ]−1 . (11)

Substituting r = 0.015, T = 48 and S = 9, 000, 000 on Equation


(11), we obtain P = 264, 375.
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Examples of Applications of Recurrence Relations

Example 3
On the first day of a new year, Joseph deposits $1000 in an account
that pays 6% interest compounded monthly. At the beginning of each
month he adds $200 to his account. If he continues to do this for the
next four years (so that he makes 47 additional deposits of $200),
how much will his account be worth exactly four years after he
opened it?
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Solution
Let pn be the value of the account n months after January 1 of the
year the account is started.

p0 = 1000
p1 = (1.005)p0 + 200
pn+1 = 1.005pn + 200 0 ≤ n ≤ 46.
(h)
The homogeneous solution is pn = C(1.005)n and The particular
(p)
solution is pp = A.

A = 1.005C = 200 =⇒ A = −40, 000.

Since p0 = C(1.005)0 − 40, 000 = 1000, it follows that C = 41, 000.


Thus, pn = (41, 000)(1.005)n − 40, 000. Hence
p47 = (41, 000)(1.005)47 − 40, 000 = 11, 830.90.
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Generating Functions
b
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Introduction

Generating functions are used to represent sequence by coding the


term of sequences as coefficients of power of a variable x in formal
power series. They are used to solve many counting problems
We first examine some examples that motivate the idea.

Example
Flora has 12 oranges and she wants to distribute these oranges to
her three children, Grace, Mary and Frank, so that Grace gets at least
4, Mary and Frank get at least 2, but Frank gets no more than 5. How
many ways Flora can distribute the oranges?

Solution
We are looking for integer solution to

x1 + x2 + x3 = 12, 4 ≤ x1 , 2 ≤ x2 , 2 ≤ x3 ≤ 5
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

The following table lists some possible distributions.


G M F
4 3 5
4 4 4
4 5 3
5 3 4
When we consider the first two cases in the table, we find the
solutions 4 + 3 + 5 = 12 and 4 + 4 + 4 = 12.
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Now, when we multiply polynomial, we add the power of the variables.


We see that in multiplying
(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 ),
two ways of obtaining x 12 are from x 4 x 3 x 5 and x 4 x 4 x 4 . Generally, the
coefficient of x 12 in

f (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 )

counts the number of distribution of the oranges.

Since f (x) = x 8 + 3x 9 + 6x 10 + 10x 11 + 14x 12 + 16x 13 + 16x 14 +


14x 15 + 10x 16 + 6x 17 + 3x 18 + x 19 , Flora can distribute the oranges in
14 different ways. f (x) is called a generating function
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Now, when we multiply polynomial, we add the power of the variables.


We see that in multiplying
(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 ),
two ways of obtaining x 12 are from x 4 x 3 x 5 and x 4 x 4 x 4 . Generally, the
coefficient of x 12 in

f (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 )

counts the number of distribution of the oranges.

Since f (x) = x 8 + 3x 9 + 6x 10 + 10x 11 + 14x 12 + 16x 13 + 16x 14 +


14x 15 + 10x 16 + 6x 17 + 3x 18 + x 19 , Flora can distribute the oranges in
14 different ways. f (x) is called a generating function
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Example
If there is at least 24 of each color Red, Green, White and Black
beans. How many ways can a child select 24 of these beans so that
he can has an even number of white and at least six black beans.
Solution
Polynomial associated with bean colors are:
Red: x 0 + x 1 + x 2 + . . . + x 24 = 1 + x + x 2 + . . . + x 24
Green: x 0 + x 1 + x 2 + . . . + x 24 = 1 + x + x 2 + . . . + x 24
White: x 0 + x 2 + x 4 + . . . + x 24 = 1 + x 2 + x 4 + . . . + x 24
Black: x 6 + x 7 + x 8 + . . . + x 24
The answer to the problem is the coefficient of x 24 in the generating
function
f (x) =
(1 + x + x 2 + . . . + x 24 )2 (1 + x 2 + x 4 + . . . + x 24 )(x 6 + x 7 + x 8 + . . . + x 24 )
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Example
If there is at least 24 of each color Red, Green, White and Black
beans. How many ways can a child select 24 of these beans so that
he can has an even number of white and at least six black beans.
Solution
Polynomial associated with bean colors are:
Red: x 0 + x 1 + x 2 + . . . + x 24 = 1 + x + x 2 + . . . + x 24
Green: x 0 + x 1 + x 2 + . . . + x 24 = 1 + x + x 2 + . . . + x 24
White: x 0 + x 2 + x 4 + . . . + x 24 = 1 + x 2 + x 4 + . . . + x 24
Black: x 6 + x 7 + x 8 + . . . + x 24
The answer to the problem is the coefficient of x 24 in the generating
function
f (x) =
(1 + x + x 2 + . . . + x 24 )2 (1 + x 2 + x 4 + . . . + x 24 )(x 6 + x 7 + x 8 + . . . + x 24 )
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Example
How many integer solutions are there for the equation

x1 + x2 + x3 + x4 = 25, 0 ≤ xi (1 ≤ i ≤ 4)

Solution
The answer to this problem is the coefficient of x 25 in the generating
function
f (x) = (1 + x + x 2 + . . . + x 25 )4
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Definition and Techniques

Let a0 , a1 , a2 , a3 , . . . be a sequence of real numbers. The function



X
f (x) = a0 + a1 x + a2 x 2 + a3 x 3 . . . = ai x i
i=0

is called the generating function of the given sequence.

Example
What is the generating function of the sequence
1, 1, 1, 1, 1, 1, 1, 1?

Solution The generating function of the sequence


1, 1, 1, 1, 1, 1, 1, 1 is 1 + x + x 2 + x 3 + x 4 + x 5 + x 6 + x 7 . We know
that (x − 1)(1 + x + x 2 + . . . + x n ) = x n+1 − 1. So,
x 8 −1 2 3 4 5 6 7 x 8 −1
x−1 = 1 + x + x + x + x + x + x + x . Hence f (x) = x−1 is the
generating function of sequence 1, 1, 1, 1, 1, 1, 1, 1.
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Definition and Techniques

Let a0 , a1 , a2 , a3 , . . . be a sequence of real numbers. The function



X
f (x) = a0 + a1 x + a2 x 2 + a3 x 3 . . . = ai x i
i=0

is called the generating function of the given sequence.

Example
What is the generating function of the sequence
1, 1, 1, 1, 1, 1, 1, 1?

Solution The generating function of the sequence


1, 1, 1, 1, 1, 1, 1, 1 is 1 + x + x 2 + x 3 + x 4 + x 5 + x 6 + x 7 . We know
that (x − 1)(1 + x + x 2 + . . . + x n ) = x n+1 − 1. So,
x 8 −1 2 3 4 5 6 7 x 8 −1
x−1 = 1 + x + x + x + x + x + x + x . Hence f (x) = x−1 is the
generating function of sequence 1, 1, 1, 1, 1, 1, 1, 1.
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Definition and Techniques

Let a0 , a1 , a2 , a3 , . . . be a sequence of real numbers. The function



X
f (x) = a0 + a1 x + a2 x 2 + a3 x 3 . . . = ai x i
i=0

is called the generating function of the given sequence.

Example
What is the generating function of the sequence
1, 1, 1, 1, 1, 1, 1, 1?

Solution The generating function of the sequence


1, 1, 1, 1, 1, 1, 1, 1 is 1 + x + x 2 + x 3 + x 4 + x 5 + x 6 + x 7 . We know
that (x − 1)(1 + x + x 2 + . . . + x n ) = x n+1 − 1. So,
x 8 −1 2 3 4 5 6 7 x 8 −1
x−1 = 1 + x + x + x + x + x + x + x . Hence f (x) = x−1 is the
generating function of sequence 1, 1, 1, 1, 1, 1, 1, 1.
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Example
By the Binomial
 Theorem,
(1 + x)n = n0 + n1 x + n2 x 2 + . . . + n−1
n
+ nn x n . So (1 + x)n is
   n−1 
x
the generating function for the sequence n0 , n1 , n2 , . . . n−1
n
    n
, n

Example
1
P∞ 1
For |x| < 1, 1−x = 1 + x + x 2 + x 3 + . . . = k=0 x k . So f (x) = 1−x is
the generating function for the sequence 1, 1, 1, 1, . . .
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Example
From Example 27

1 X
= 1 + x + x2 + x3 + . . . = xk.
1−x
k=0

1
So f (x) = 1−x . Taking derivative on both side, we get
1
P∞ 1
(1−x)2
= 1 + 2x + 3x 2 + 4x 3 + . . . = k=0 x k . So f (x) = 1−x .
1
Consequently, f (x) = (1−x) 2 is the generating function for the

sequence 1, 2, 3, 4, ....
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

We know, by the Binomial Theorem, for n ∈ Z +


         
n n n 2 n n n
(1 + x)n = + x+ x + ... + x n−1 + x .
0 1 2 n−1 n
We want to extend this idea to cases where:
a) n < 0
b) n is not necessary integer.
Recall, with n, r ∈ Z + , n ≥ r , we have
 
n n! (n)(n − 1)(n − 2) . . . (n − r + 1)
= =
r r !(n − r )! r!

/ Z + , n ≥ r , we use the same definition. So if n ∈ Z +


If n ∈
 
−n (−n)(−n − 1)(−n − 2) . . . (−n − r + 1)
=
r r!
r
(−1) (n)(n + 1)(n + 2) . . . (n + r − 1)
=
 r !
n + r − 1
= (−1)r
r
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Example
Find −7

5 .

Solution
−n
= (−1)r n+rr −1 . Substitute n = 7 and r = 5 to obtain
 
r
     
−7 5 7+5−1 11 11!
= (−1) = −1 =− = −462
5 5 5 5!6!
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Example

For n ∈ Z + , the Maclarian series expansion for

1 (−n)(−n − 1)x 2 (−n)(−n − 1)(−n − 2)x 3


= 1 + (−n)x + + +.
(1 + x)n 2! 3!

X (−n)(−n − 1) . . . (−n − r + 1)x r
= 1+
r!
r =1
∞  
X n+r −1 r
= (−1)r x
r
r =0
∞  
X −n r
= x
r
r =0

Hence, (1 + x)−n = −n −n −n −n
   2  3
0 + 1 x + 2 x + 3 x . . .. Therefore,
−n
1
 −n
f (x) = (1+x)n is a generating function of the sequence 0 , 1 ,
−n
 −n
2 , 3 , ...
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Example
1
Find the coefficient of x 5 in (1−2x)7

Solution
Let y = −2x, then by Example 30,
∞   ∞  
X −7 X −7
(1 + y )−7 = yr = (2x)r .
r r
r =0 r =0

So, the coefficient of x 5 is


   
−7 −7
(−2)5 = (−32)
5 5
 
5 7+5−1
= −32(−1)
5
 
11
= 32
5
= 14, 784
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

By replacing x with −x in Example 30, we obtain

∞  
1 r n+r −1
X
= (−1) (−x)r
(1 − x)n r
r =0
∞  
X n+r −1 r
= x
r
r =0
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

For any real number n, the Maclaurian series for

n(n − 1) 2 n(n − 1)(n − 2 3


(1 + x)n = 1 + nx + x + x + ...
2! 3!

X n(n − 1)(n − 2) . . . (n − r + 1)
= 1+ ( xr )
r!
r =1
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Example
Find the coefficient of x 5 in f (x) = (1 + 3x)−1/3

Solution


X (−1/3)(−1/3 − 1)(−1/3 − 2) . . . (−1/3 − r + 1) r r
(1+3x)−1/3 = 1+ ( 3 x ).
r!
r =1

Therefore, the coefficincient of x 5 is


−1/3(−1/3 − 1)(−1/3 − 2)(−1/3 − 3)(−1/3 − 4) 5
3
5!
(− 13 )(− 43 )(− 73 )(− 10 13
3 )(− 3 ) 5
= 3
5!
91
=−
3
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Example
Determine the coefficient of x 15 in f (x) = (x 2 + x 3 + x 4 + x 5 + . . .)4

Solution f (x) = (x 2 + x 3 + x 4 + x 5 + . . .)4 , so

f (x) = x 8 (1 + x + x 2 + x 3 + x 4 + . . .)4 (12)

Let f (x) = x 8 g(x), where

g(x) = (1 + x + x 2 + x 3 + x 4 + . . .)4 (13)

From equation 12 and 13, the coefficient of x 15 in f (x) equals to the


coefficient of x 7 in g(x).
1 4
Hence, the coefficient sought is that of x 7 in ( 1−x ) = (1 − x)−4 ,
which is 4+7−1 = 10
 
7 7 = 120
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Example

In how many ways can Mary distribute 24 oranges to her 4 children


so that each gets at least 3, but not more than 8.
The above problem is equivalent to the problem:“How many integer
solutions are there in”

c1 + c2 + c3 + c4 = 24, 3 ≤ xi ≤ 8, (i ∈ {1, 2, 3, 4})

Before solving the problem, we state (w.o.p) the following theorem

Theorem
P∞ k
P∞ k
Let f (x) = P k=0 ak x and f (x) = k=0 bk x . Then
∞ k
f (x).g(x) = k=0 ck x , where
ck = a0 bk + a1 bk−1 + a2 bk−2 + . . . + ak−1 b1 + ak b0
Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Solution of Example 34

The choice for the number of oranges each child receives is given by
(x 3 + x 4 + x 5 + x 6 + x 7 + x 8 ). Since there are 4 children, the resulting
generating function is

f (x) = (x 3 + x 4 + x 5 + x 6 + x 7 + x 8 )4
= x 12 (1 + x + x 2 + x 3 + x 4 + x 5 )4
4
1 − x6

12
= x
1−x

Therefore, the answer is the coefficient of x 12 in (1 − x 6 )4 (1 − x)−4 .


Introduction Basic Counting Principles Principle of Inclusion-Exclusion Recurrence Relations Generating Functions

Let f (x) = (1 − x 6 )4 = 1 − 41 x 6 + 42 x 12 − 43 x 18 + 44 x 24 and


   

g(x) = (1 − x)−4 = −4 −4 −4 2
  
0 + 1 (−x) + 2 (−x) + . . .
12 6 4 −4
Hence, the coefficient of x in (1 − x ) (1 − x) , by above theorem,
is
              
−4 4 −4 4 −4 15 4 9 4
1 − + = − + = 125
12 1 6 2 0 12 1 6 2

You might also like