0% found this document useful (0 votes)
7 views49 pages

1_1_counting

Uploaded by

Ngô Linh Chi
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)
7 views49 pages

1_1_counting

Uploaded by

Ngô Linh Chi
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/ 49

Hanoi University of Science and Technology

TRƯỜNG ĐẠI HỌCSchool


BÁCH of KHOA
Information and Communications Technology
HÀ NỘI
VIỆN CÔNG NGHỆ THÔNG TIN VÀ TRUYỀN THÔNG
PART 1
COMBINATORIAL THEORY
(Lý thuyết tổ hợp)
Discrete Mathematics

Nguyễn Khánh Phương PART 2


Department of Computer Science
School of Information and Communication Technology GRAPH THEORY
E-mail: [email protected]
(Lý thuyết đồ thị) 2

Contents of Part 1: Combinatorial Theory Contents of Part 1: Combinatorial Theory


Chapter 1. Counting problem Chapter 1. Counting problem
• This is the problem aiming to answer the question: “How many ways are there that satisfy • This is the problem aiming to answer the question: “How many ways are there that satisfy
given conditions?” The counting method is usually based on some basic principles and some given conditions?” The counting method is usually based on some basic principles and some
results to count simple configurations . results to count simple configurations .
• Counting problems are effectively applied to evaluation tasks such as calculating the • Counting problems are effectively applied to evaluation tasks such as calculating the
probability of an event, calculating the complexity of an algorithm (how long the algorithm probability of an event, calculating the complexity of an algorithm
will take to run), ....
Chapter 2. Existence problem
Given N paintings in a row over a In the counting problem, configuration existence is obvious; in the existence problem, we need to
distance of M centimeters.
answer the question: "Is there a combinatorial configuration that satisfies given properties ?”
Each painting i (1 ≤ i ≤ N) will be drawn
on a length of ti cm, so t1+t2+..+tn = M. Chapter 3. Enumeration problem
The K city's most famous artists have This problem is interested in giving all the configurations that satisfy given conditions.
been selected to do this work, each artist
will be assigned to draw at least one Chapter 4. Combinatorial optimization problem
painting. To facilitate the artist's work, if • Unlike the enumeration problem, this problem only concerns the "best" configuration in a
someone is assigned to draw more than
certain sense.
one painting, the paintings must be
• In the optimization problems, each configuration is assigned a numerical value (which is the
Street art adjacent to each other on the street art
use value or the cost to construction the configuration), and the problem is that among the
configurations that satisfy the given conditions, find the configuration with the maximum or
3
minimum value assigned to it
Hanoi University of Science and Technology
Contents of Part 1 TRƯỜNG ĐẠI HỌCSchool
BÁCH of KHOA
Information and Communications Technology
HÀ NỘI
VIỆN CÔNG NGHỆ THÔNG TIN VÀ TRUYỀN THÔNG
Chapter 0: Sets, Relations
Chapter 1: Counting problem
Chapter 2: Existence problem Chapter 1
Chapter 3: Enumeration problem counting problem
Chapter 4: Combinatorial optimization problem

Contents Contents
• Combinatorics is the branch of mathematics devoted to calculate the 1. Basic counting principles
number of ways in which a specified process can be carried out.
Problems of this type often occur in computing. A typical problem is 2. Elementary combinatorial configuration
to determine how many times a particular sequence of steps in an
algorithm will be executed. You might need to know this in order to 3. The inclusion-exclusion principle
estimate how long the algorithm will take to run.
4. Recurrence relation
• For example: determine the shortest path for a signal to travel through
a communication network 5. Generating function
– Algorithm 1 (simplest): calculate the lengths of all the possible paths through the
network.
– Algorithm 2: just calculate the lengths of some selected paths
 In order to determine how efficient these algorithms are, and to be
able to compare them with each other and with other algorithms, we
must first answer the question: ‘How many such paths are there
altogether?’ 7 8
1. Basic counting principles 1.1. The sum rule
1.1. The sum rule Example:
• 40 textbooks on Mathematics; 50 textbooks on English
1.2. The product rule • to select 1 book: 40+50 choices
• What about selecting 2 books?
problem decompose combine
Task 1
Independent tasks
Let us consider two tasks:
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.,
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.

9
Generalizes to multiple tasks ...

1.1. The sum rule 1.1. The sum rule


Let us consider two tasks: Task 1 Example:
m1 is the number of ways to do task 1
m2 is the number of ways to do task 2 • 40 textbooks on Mathematics; 50 textbooks on English
Tasks are independent of each other, i.e., • to select 1 book: 40+50 choices
Performing task 1 does not accomplish task 2 and vice versa.
Task 2 • What about selecting 2 books?
Sum rule: the number of ways that “either task 1 or task 2 can be done, but not
both”, is m1 + m2.
problem decompose combine
Independent tasks
Generalizes to multiple tasks ...

Things 1 2 3 … k
Generalized sum rule:
ways m1 m2 m3 … mk Tasks 1 2 3 … k
ways m1 m2 m3 … mk
select one of them: m1 +m2 +m3 +...+ mk ways
select one of them: m1 +m2 +m3 +...+ mk ways
1.1. The sum rule 1.1. The sum rule
Example: How many 6-character strings are there, each of which is Generalized sum rule: If we have tasks T1, T2, …, Tk that can be
taken from the set {A, B, C, D, E} containing at least 3 different done in m1, m2, …, mk ways, respectively, and any two of these
characters? For example, the string ABCCAC is the string that satisfies tasks can not be done at the same time, then there are m1 + m2 +
the problem condition, while the string ABABAB does not.
… + mk ways to do one of these tasks.

problem decompose combine


The sum rule can also be phrased in terms of set theory: The
Independent tasks
Generalized sum rule: size of the union on k finite pair wise disjoint sets is the sum of
their sizes:
Tasks 1 2 3 … k • Let A1, A2, …, Ak be disjoint sets. Then the number of ways
ways m1 m2 m3 … mk to choose any element from one of these sets is
select one of them: m1 +m2 +m3 +...+ mk ways |A1  A2  …  Ak| = |A1| + |A2| + … + |Ak|.

14

1.1. The sum rule 1.1. The sum rule


Example 1: A student can choose a computer project from one of three Example 3: What is the value of k once this program is executed?
lists. The three lists contain 23, 15, and 19 possible projects respectively. n1=10; n2=20; n3=30;
How many possible projects are there to choose from? k=0;
for (i1= 1; i1<=n1;i1++) k=k+1;
23+15+19 
for (i2= 1; i2<=n2;i2++) k=k+1;
Example 2: How many strings of 4 decimal digits, have exactly three for (i3= 1; i3<=n3;i3++) k=k+1;
digits that are 9s?
Answer: At the beginning, the value of k is assigned to 0. There are 3
The string can have: independent “for” loops. After each for loop, the value of k is increased by one:
• The non-9 as the first digit (x999)
• The first “for” loop iterates 10 times,
• OR the non-9 as the second digit (9x99)
• OR the non-9 as the third digit (99x9) • The second “for” loop iterates 20 times,
• OR the non-9 as the fourth digit (999x) • The last “for” loop iterates 30 times
Thus, we use the sum rule: Therefore, at the end, the value of k = 10 + 20 + 30 = 60
• For each of those cases, there are 9 possibilities for the non-9 digit
(any number other than 9) 15 16
• Thus, the answer is 9+9+9+9 = 36
1. Basic counting principles The sum rule
Object type 1
1.1. The sum rule Consider 2 types of objects:
m1 is number of object type 1
1.2. The product rule m2 is number of object type 2 Object type 2
The decision to choose object type 1 or 2 is independent of each other, that is,
• the decision to choose object type 1 does not affect the decision to choose
object type 2, and vice versa.
Sum rule: The number of ways to choose an object type 1 or an object type 2 is m1
+ m2

Generalize to multiple types of objects:

Object type 1 2 3 … k
Quality m1 m2 m3 … mk

The number of ways to choose one object from these k types of objects
17
= m1 +m2 +m3 +...+ mk 18

The product rule The product rule


• Consider 2 types of objects: • Consider two tasks:
– m1 is number of object type 1 – m1 is the number of ways to do task 1
– m2 is number of object type 2
– m2 is the number of ways to do task 2
The decision to choose object type 1 or 2 is independent of each other, that is,
– Tasks are independent of each other, i.e.,
• the decision to choose object type 1 does not affect the decision to choose
object type 2, and vice versa. • Performing task 1does not accomplish task 2 and vice versa.
Product rule: The number of ways to choose an object type 1 and an object type 2 Product rule: the number of ways that “both tasks 1 and 2 can be done”
is m1 m2 in m1m2.
Object type1 Object type2 task 1 task 2

• Generalize to multiple types of objects:


Object type 1 2 3 … k
Quality m1 m2 m3 … mk • Generalize to multiple tasks ...
The number of ways to select exact k objects, not any 2 objects of same type
19 20
= m1 m2 m3 … mk
Analysis 1.2. The product rule

License Plate LL-DDDD 2 letters – 4 digits

Suppose a procedure can be constructed by a


# of possible plates = ? series of steps

Step 1 Step 2 Step 3 Step k



m1 ways m2 ways m3 ways mk ways

Number of possible ways to complete the procedure is

m1 * m2 *  *mk

Analysis 1.2. The product rule


Generalized product rule: If we have a procedure consisting of
License Plate LL-DDDD 2 letters – 4 digits
sequential tasks T1, T2, …, Tk that can be done in m1, m2, …, mk
ways, respectively, then there are m1 * m2 * … * mk ways to
# of possible plates = ? carry out the procedure.
Procedure:
Step 1: Step 3: The product rule can also be phrased in terms of set theory:
Step 2: Step 4: Let A1, A2, …, Ak be finite sets. Then the number of ways to
Step 5: choose one element from each set in the order of A1, A2, …,
Step 6: Ak is
|A1 x A2 x … x Ak| = |A1| * |A2| * … * |Ak|.

24
The product rule The product rule
• If each element ai of k- tuple (a1, a2, ..., ak) has mi number of In many counting problems, it is only after building the first element, we just know how

ways to select (i = 1, 2, ..., k), then the number of tuples could be to build the second element; after building the first two elements we only know how to
generated is the product of these m1m2 ... mk build the third element,… In that case, we use the general product rules:
Suppose we construct a k-tuple (a1, a2, ..., ak) by building each element in turnand
• a1 can be chosen by m1 way;
• After a1 is selected, a2 can be chosen by m2 way;
• ...
• After a1, a2, ..., ak-1 are chosen, ak can be chosen by mk ways;
Then the number of k-tuples generated is m1m2 ... mk
Example: 6 persons are competing for 4 prizes. How many different outcomes are
A B C
possible? 1st prize 2nd prize 3rd prize 4th prize
D E F

25 A 4-tuple = (1st prize, 2nd prize, 3rd prize, 4th prize) 26

1.2. The product rule 1.2. The product rule


Example 1: There are 18 math majors and 325 CS majors. How many Example 3: How many functions are there from set A to set B?
ways are there to pick one math major and one CS major?
So, how many Boolean
Total is 18 * 325 = 5850 A B
functions on n variables?
Example 2: The license plate: 2 letters-4 digits
(a) no letter or digit can be repeated n
22
26  25  10  9  8  7
(b) with repetitions allowed
26  26  10  10  10  10 To define each function we have to make 3 choices, one for each element of A.
Each has 4 options (to select an element from B).
(c) same as (b), but only vowels and even digits
How many ways can each choice
52x54 4 x 4 x 4 be made?

43= 64 = |B| |A|

27 28
1.2. The product rule 1.2. The product rule
Example 4: How many strings of 4 decimal digits Example 5: Consider the following nested loop:
(a) do not contain the same digit twice? for (i=1;i<=9;i++)
We want to choose a digit, then another that is not the same, then for (j=1;j<=7;j++) {
another…
[ Statement 1;
• 1st digit: 10 possibilities (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
Statement 2; ]
• 2nd digit: 9 possibilities (all but not first digit)
• 3rd digit: 8 possibilities
}
• 4th digit: 7 possibilities How many times the statements in the inner loop will be executed?
Total = 10*9*8*7 = 5040 Solution: 9 × 7 = 63 times (based on the product rule)

(b) end with an even digit?


First three digits have 10 possibilities (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
Last digit has 5 possibilities (0, 2, 4, 6, 8)
Total = 10*10*10*5 = 5000 29 30

More complex counting problems More complex counting problems


Example 1: How many BASIC variables: single letter
or single letter+single digit
26 + 26 * 10=286

• Combining the product rule and the sum rule. rule of sum rule of product
Example 2: How many integers from 1 through 999 do not have any repeated
• Thus we can solve more interesting and complex problems. digits?
Let A = integers from 1 to 999 not having repeated digits.
Partition A into 3 sets:
• A1=one-digit integers not having repeated digits;
• A2=two-digit integers not having repeated digits;
• A3=three-digit integers not having repeated digits.
 |A| = |A1| + |A2| + |A3| (by the sum rule)
31 32
= 9 + 9×9 + 9×9×8 = 738 (by the product rule)
Count the number of ways to put things together into various combinations. Count the number of ways to put things together into various combinations.

Example 3: Passwords consist of character strings of 6 to 8 characters. Each Example 3: Passwords consist of character strings of 6 to 8 characters. Each
character is an upper case letter or a digit. character is an upper case letter or a digit.
26 (A-Z) 10 (0-9) 26 (A-Z) 10 (0-9)
Each password must contain at least one digit. How many passwords are Each password must contain at least one digit. How many passwords are
possible? constraint possible? constraint
– Let P – total number of possible passwords – Let P – total number of possible passwords
– Pi – total number of passwords of length i, i = 6,7,8  P = P6 + P7 + P8 = 366-266 + 367 - 267 + 368 – 268 =2,684,483,063,360
 P = P6 + P7 + P8 (the sum rule)
Pi – computing it directly is tricky (hmm…) How?? Comment: If your computer can try 200 million passwords per second, then how
– “popular” counting trick: let’s calculate all of them, including those with no long can the password be determined, so the intruder could penetrate this computer
digits and then subtract the ones with no digits. system?
P6 = (# possibilities without constraint) – (# passwords with no digits) (2 684 483 063 360/200 000 000) / (60 * 60) hours
= 366 – 266 Nearly 4 hours!
P7 = 367 - 267
P8 = 368 – 268
33 34
 P = P6 + P7 + P8 = 366-266 + 367 - 267 + 368 – 268 =2,684,483,063,360

IP Address Example (Internet Protocol v. 4) Wedding picture

Example 4: An address is a string of 32 bits – it begins with a network id Example 5: Consider a wedding picture of 6 people
(netid), followed by a host number (hostid), which identifies a computer as a – There are 10 people, including the bride and groom
member of a particular network. (a) How many possibilities are there if the bride must be in the picture?
• Main computer addresses are in one of 3 types: • Product rule: place the bride AND then place the rest of the party
– Class A (largest networks): address contains a 0 followed by 7-bit
• First place the bride:
“netid”, and a 24-bit “hostid”
 She can be in one of 6 positions
– Class B (medium networks): address contains a 10 followed by a 14-bit
netid and a 16-bit hostid. • Next, place the other 5 people via the product rule:
– Class C (smallest networks): address contains a 110 has 21-bit netid and  There are 9 people to choose for the second person, 8 for the
an 8-bit hostid. third, etc.  Total = 9*8*7*6*5 = 15120
Netids all 1s are not allowed. Hostids that are all 0s or all 1s are not allowed.
 Product rule yields 6 * 15120 = 90,720 possibilities

35
How many valid IP addresses are there?
Wedding picture Wedding picture
Example 5: Consider a wedding picture of 6 people Example 5: Consider a wedding picture of 6 people
– There are 10 people, including the bride and groom – There are 10 people, including the bride and groom
c) How many possibilities are there if only one the bride or the groom must be in the
b) How many possibilities are there if the bride and the groom must be picture?
in the picture? Sum rule: place only the bride
• Product rule: place the bride/groom AND then place the rest of the party • Product rule: place the bride AND then place the rest of the party
• First place the bride and groom: – First place the bride
 She can be in one of 6 positions  She can be in one of 6 positions
– Next, place the other 5 people via the product rule (We can’t choose the
 He can be in one of 5 remaining positions groom!!!)
 Total of 6*5 = 30 possibilities  There are 8 people to choose for the second person, 7 for the third, etc.
• Next, place the other 4 people via the product rule:  Total = 8*7*6*5*4 = 6720
 There are 8 people to choose for the 3rd, 7 for the 4th, etc.  Product rule yields 6 * 6720 = 40,320 possibilities
 Total = 8*7*6*5 = 1680 OR place only the groom (hmm… quickly, how many?)
• Same possibilities as for bride: 40,320
 Product rule yields 30 * 1680 = 50,400 possibilities
 Sum rule yields 40,320 + 40,320 = 80,640 possibilities

Alternative way to get the answer ???

Wedding picture Contents


Example 5: Consider a wedding picture of 6 people
– There are 10 people, including the bride and groom
1. Basic counting principles
a) How many possibilities are there if the bride must be in the picture? 2. Elementary combinatorial configuration
90,720 possibilities
b) How many possibilities are there if the bride and the groom must be in the 3. The inclusion-exclusion principle
picture?
50,400 possibilities 4. Recurrence relation
c) How many possibilities are there if only one the bride or the groom must be in
the picture? 5. Generating function
• Total ways to place the bride (with or without groom): 90,720
 See (a).
• Total ways for both the bride and groom: 50,400
 See (b).
• Total ways to place ONLY the bride:
90,720 – 50,400 = 40,320
• Same number for the groom
40
• Total = 40,320 + 40,320 = 80,640
2. Elementary combinatorial configuration 2. Elementary combinatorial configuration
2.1. Permutation 2.1. Permutation
2.2. Combination 2.2. Combination

Fruit salad is a combination of apples, grapes and bananas. We don't


care what order the fruits are in.

The permutation that will open the lock is 942, we do care about the
order.

41 42

2. Elementary combinatorial configuration 2.1.1. Permutation


Example 1: A PIN is defined as a sequence of any 4 digits from the set {0, 1, …, 9}.
2.1. Permutation Question 1. How many different PINs are possible if repetitions are allowed?
2.1.1. Permutation Solution. Choosing a PIN is a 4-step operation:
• Step 1: Choose the 1st symbol (10 different ways).
2.1.2. k-permutation • Step 2: Choose the 2nd symbol (10 different ways).
2.1.3. Circulation permutation • Step 3: Choose the 3rd symbol (10 different ways).
• Step 4: Choose the 4th symbol (10 different ways).
2.1.4. Permutation of multisets  Based on the product rule:
10×10×10×10 = 10,000 PINs are possible.
2.2. Combination Question 2. How many different PINs are possible if repetitions are NOT allowed?
Solution. Choosing a PIN is a 4-step operation:
• Step 1: Choose the 1st symbol (10 different ways).
• Step 2: Choose the 2nd symbol (9 different ways).
• Step 3: Choose the 3rd symbol (8 different ways).
• Step 4: Choose the 4th symbol (7 different ways).
 Based on the product rule:
43 44
10×9×8×7 = 5,040 PINs are possible.
2.1.1. Permutation 2.1.1. Permutation
• A permutation of a set A of objects is an ordered arrangement of • The number of permutations of any set with n elements is
the elements of A where each element appears only once P(n) = n! = n(n − 1) · · · 2 · 1
Example: If A = {a, b, c}, then the permutations of A are
Proof: (by product rule)
1. abc
Forming a permutation is an n-step operation:
2. acb
• Step 1: Choose the 1st element ( n different ways).
3. bac
• Step 2: Choose the 2nd element ( n-1 different ways).
4. bca
• …
5. cab
• Step n: Choose the nth element (1 way).
6. cba
Based on the product rule, the number of permutations is
• The number of permutations of any set with n elements is n  (n-1) … 2  1 = n!
P(n) = n! = n(n − 1) · · · 2 · 1
(Note that by definition 0! = 1)
Proof: 45 46

2.1.2. k-permutation 2.1.2. k-permutation


• A permutation of a set A of n objects x1, x2, ..,xn is an ordered • A permutation of a set A of n objects x1, x2, ..,xn is an ordered
arrangement of the elements of A where each element appears arrangement of the elements of A where each element appears
only once. only once.
• A k-permutation of a set A of n objects x1, x2, ..,xn is an ordered • A k-permutation of a set A of n objects x1, x2, ..,xn is an ordered
arrangement of k distinct elements of A. arrangement of k distinct elements of A.
1st 2nd 3rd  k-th
 “permutations” means “n-permutations”.

x1 x2 x3  xn

Example: 3-permutation of a set A of 4 objects x1, x2, x3, x4

x1
1st
x2
2nd
x3
3rd
 x2
1st
x1
2nd
x3
3rd

47 48
2.1.2. k-permutation 2.1.2. k-permutation
• A k-permutation of a set A of n objects x1, x2, ..,xn is an ordered Example 2: Suppose you “have” time to listen to 10 songs on your daily
arrangement of k distinct elements of A. jog around campus. There are 6 A tunes, 8 B tunes, and 3 C tunes
 The number of k-permutations of a set A with n=|A| elements is to choose from.
P(n, k) = n(n−1)…(n−k+1) = n! / (n−k)!
Finally, suppose you still want 4 A, 4 B, and 2 C tunes, and the order
of the groups doesn’t matter, but you get dizzy and fall down if all the
Example 1: 6 persons are competing for 4 prizes. How many different
outcomes are possible? songs by any one group aren’t played together.
How many playlists are there?
1st prize 2nd prize 3rd prize 4th prize

D F C E B A

6!
P(6, 4)  6*5* 4*3 
2!
P(n, k): k unique choices out of n objects, order matters
49 50

2.1.2. k-permutation 2. Elementary combinatorial configuration


Example 3. How many ways are there to arrange 4 students to sit on the 2.1. Permutation
bench of 10 seats provided that sitting on the lap of each other is not
allowed. 2.1.1. Permutation
Solution. The students are numbered 1 to 4, seats 1 through 10. Each 2.1.2. k-permutation
placement of the students can be represented by an ordered set (s1, s2, s3,
s4), where si  {1, 2, ..., 10} are the seat of student ith. 2.1.3. Circulation permutation
As si sj, i j, each placement is a 4-permutation of 10: P(10, 4) = 2.1.4. Permutation of multisets
10*9*8*7=5040.
2.2. Combination
Note: We can also argue by directly using the Product rule:
We take turns putting the students into their seats.
• 1st student: there are 10 seats to be selected to sit
• 2nd student: put him one of the remaining 9 seats,…
According to the Product rule, there are 10*9*8*7 ways of placement 51 52
2.1.3. Circulation permutation Hoán vị vòng tròn
Circulation permutation n!/n=(n-1)! • A circulation permutation of a set A of n objects is an ordered of all n
Example 3: 6 people A, B, C, D, E, F are seated around a round table, objects of A arranged as a circle; there is not the beginning object and
how many different circular arrangements are possible, if arrangements the ending object.
are considered the same when one can be obtained from the other by "The number of circulation permutations of an n-set equals n!/n = (n-1)!”
rotations? Proof ????
A
ABCDEF, B
BCDEFA, F
CDEFAB,
DEFABC, E C
EFABCD,
FABCDE D
1 circulation
are the same arrangements circularly permutation of set
4 objects A, B, C, D
 There are 6! ways to seat 6 people around the table
For each seating, there are 6 “rotations” of the seating
4 permutations of
Thus, the final answer is 6!/6 = 5! = 120 53 set 4 objects A, B,
C, D

2.1.3. Circulation permutation 2.1.3. Circulation permutation


• A circulation permutation of a set A of n objects is an ordered of all n Example 4: How many ways to arrange 3 couples in a round table with
objects of A arranged as a circle; there is not the beginning object and alternating sex
the ending object.
"The number of circulation permutations of an n-set equals n!/n = (n-1)!” F

• A circular k-permutation of a set A of n objects is an ordered k objects


of A arranged as a circle; there is not the beginning object and the
ending object. Prove the following result:
"The number of circular k-permutations of an n-set equals P(n,k)/k".

55 56
2. Elementary combinatorial configuration 2.1.4. Permutations of multisets
2.1. Permutation • A multiset M is a collection whose members need not be distinct.
Example: The collection
2.1.1. Permutation
M = (a, a, a, b, b, c, d, d, d, 1, 2, 2, 2, 3, 3, 3, 3)
2.1.2. k-permutation is a multiset; and sometimes it is convenient to write
2.1.3. Circulation permutation M = (3a, 2b, c, 3d, 1, 32, 43).
2.1.4. Permutation of multisets • 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
2.2. Combination t(x) times in M; we write M = (S; t).
• Let M be a multiset and |M| = n.
– A k-permutation of M is an ordered arrangement of k objects
selected from n objects of M.
– A n-permutation of M is called a permutation of M.

57 58

2.1.4. Permutation of multisets 2.1.4. Permutation of multisets


• Let M be a multiset and |M| = n. • Let M be a multiset and |M| = n.
– A k-permutation of M is an ordered arrangement of k objects selected – A k-permutation of M is an ordered arrangement of k objects selected
from n objects of M. from n objects of M.
– A n-permutation of M is called a permutation of M. – A n-permutation of M is called a permutation of M.

Proposition 1. Let M be a multiset of r different types where each type has 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 𝑟 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? 1st position 2nd position 3rd position …. kth position
Solution: The question is to find the number of 4-permutations of the
r choice r choice r choice
multiset (0, 1). Thus the answer is 24 = 16.

Example 2. What is the number of ternary numerals with at most 4 digits? The total = rk
• Solution: The question is to find the number of 4-permutations of the
59 60
multiset (0, 1, 2). Thus the answer is 34 = 81.
2.1.4. Permutation of multisets 2.1.4. Permutation of multisets
Proposition 2. Let M be a multiset of r different types with repetition numbers n1, Proposition 2. Let M be a multiset of r different types with
n2,…, nr respectively. Let n = n1+ n2 +… + nr . Then the number of permutations of M
equals repetition numbers n1, n2,…, nr respectively. Let n = n1+ n2
𝒏! +… + nr . Then the number of permutations of M equals
𝒏𝟏 ! 𝒏𝟐 ! … 𝒏𝒓 !
Proof.
𝒏!
• List the elements of M as
nr 𝒏𝟏 ! 𝒏 𝟐 ! … 𝒏 𝒓 !
• Let S be the set consisting of the elements
𝑎 ,𝑎 ,…,𝑎 , 𝑏 ,𝑏 ,…,𝑏 ,…,𝑑 ,𝑑 ,…,𝑑 ,
Example 3: The number of 0-1 words of length n with exactly
Let X be the set of all permutations of S, and let Y be the set of all permutations of M.
There is a map f : X → Y, sending each permutation of S to a permutation of M by
m ones and (n – m) zeros equals to
removing the subscripts of the elements. Note that for each permutation  of M there
are n1!, n2!,…,nr! ways to put the subscripts of the first, the second, ..., and the rth type n! n 
elements back, respectively.  Cnm    .
Thus there are n1!n2! … nr! elements of X sent to Y by f. Therefore m !( n  m)! m
|X| n!
| Y |  61 62
n1 ! n2 !...nr ! n1 ! n2 !...nr !

2.1.4. Permutation of multisets 2. Elementary combinatorial configuration


Example 4: Find the number of 8-permutations of the multiset 2.1. Permutation
M = (a, a, a, b, b, c, c, c, c) = (3a, 2b, 4c).
Solution: 2.2. Combination
How to select 8 elements from (3+2+4) = 9 elements ???
(2a,2b,4c)
(3a, b, 4c)
(3a, 2b, 3c)
• The number of 8-permutations of (2a, 2b, 4c): 8!/(2!2!4!)
• The number of 8-permutations of (3a, b, 4c): 8!/(3!1!4!)
• The number of 8-permutations of (3a, 2b, 3c): 8!/(3!2!3!)
 Thus the answer is
8!/(2!2!4!) + 8!/(3!1!4!) + 8!/(3!2!3!) = 420 + 280 + 560 = 1260
63 64
2.2. Combination 2.2.1. Definitions
2.1.1. Definitions • A k-combination of a set of n elements is a subset of size k of n
elements.
2.2.2. Binomial coefficients (Note: A permutation is a sequence while a combination is a set)
2.2.3. Combinations of Multisets
2.2.4. Multinomial coefficients 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}

65 66

2.2.1. Definitions k-combination


• The number of all k-combinations of a set of n elements denoted Example: X = {a, b, c}; n = 3, r = 2
n k k-permutation k-combination
  , Cn or C ( n, k ) select 2 from 3 elements of X: select 2 from 3 elements of X:
k
and read “n choose k”. 1. (a, b) 1. {a,b}
2. {a, c} Order is not the matter
2. (a, c)
n n! 3. {b, c}
  Proof ??? 3. (b, a)
 k  k ! (n  k )!
Ordered sequence
4. (b, c)

This number is also called a binomial coefficient because such


numbers occur as coefficients in the expansions of powers of
5. (c, a)
6. (c, b) 2!
binomial expressions such as (a+b)n
n! n!
Pnk  n(n  1)...(n  k  1)  Cnk 
67 (n  k )! k !(n  k )! 68
k-combination k-combination of a set
Example: X = {a, b, c}; n = 3, r = 2 Example: Consider the following nested loop
k-permutation k-combination for a:=1 to n
Select 2 from 3 elements of X: for b:=1 to a-1
Select 2 from 3 elements of X:
1. {a,b} for c:=1 to b-1
1. (a, b)
2. {a, c} Order is not the matter [Statements]
2. (a, c)
3. {b, c} endfor
3. (b, a)
Ordered sequence endfor
4. (b, c) n!
Pnk  n(n  1)...(n  k  1)  endfor
5. (c, a) (n  k )!
Question: How many times the statements in the innermost loop will be
6. (c, b)
Consider the set A of all k-permutation of n elements. Divide them into subset so that the two permutations executed?
belonging to the same subset differ only in order. Obviously, these subsets are a partition on the set A, and each such
subset corresponds to a k-combination of n elements. There are the same number of k-permutation in each subset,
Answer: Each iteration corresponds to a triple of integers (a, b, c) where a > b >
and is equal to k! (number of permutations). The number of subsets is the number of k-combination of n. According c . The set of all this kind of triples corresponds to all 3-combinations of {1, …,
to the sum rule, product of k! and the number of subsets is equal to the number of k-permutation of n, that is, equal
to n (n-1) ... (n - k + 1). Therefore, the number of k-combination of n is:
n}. Thus, the total number of iterations is C(n,3).
n(n  1)(n  2)...(n  k  1) n! 69
or
k! k !( n  k )!

Difference between permutation and combination Difference between permutation and combination
• A combination is a set while a permutation is a sequence. When dealing with any counting problem, we should ask
Let’s consider the difference between unordered and ordered selections: ourselves about the importance of order in the problem:
1. Two ordered selections are the same if • When order is relevant, we think in terms of permutations
– the elements chosen are the same; and arrangements and the rule of product.
– the elements chosen are in the same order.
• When order is not relevant, combinations could play a key
• Ordered selections correspond to k-permutations.
• The number of all k-permutations is P(n, k) = n! / (n−k)!
role in solving the problem.
2. Two unordered selections are the same if
– the elements chosen are the same (regardless of the order in which the
elements are chosen)
• Unordered selections correspond to k-combinations
• The number of all k-combinations is C(n, k) = n! / k! (n−k)!

71 72
Difference between permutation and combination 2.2. Combination
Example: A club has 25 members. 2.1.1. Definitions
a. How many ways are there to choose 4 members of the club 2.2.2. Binomial coefficients
to serve on an executive committee?
2.2.3. Combinations of Multisets
2.2.4. Multinomial coefficients
b. How many ways are there to choose a president, vice
president, secretary, and treasurer of the club?

73 74

Binomial Coefficients Binomial Coefficients


n  
(a + b)4 = (a + b)(a + b)(a + b)(a + b) n
4  4  4  4  4  (x  y )n   x n  j y j
=0a4 +1 a3b +2a2b2 +3 ab3 +4 b4 j
j 0  

Binomial Theorem: Let x and y be variables, and let n be any nonnegative integer.
Then What is the coefficient of a8b9 in the expansion of (3a +2b)17?
n n  What is n? 17
(x  y )  n
 j x nj
y j
What is j? 9
17  8 9  17  8 9 8 9
  (3a ) (2b)    3 2 a b
j 0 9
  9
What is x? 3a

What is y? 2b

75 76
Binomial Coefficients Binomial Coefficients
n  
Sum each row of Pascal’s Triangle:  n  2 n
n  
n
(x  y)n   x n  j y j
j 
 What is coefficient
j 0 j
j 0  
(a + b)2 = a2 + 2ab + b2 of a9b3 in (a + b)12? Powers of 2
Proof ???
(a + b)3 = a3 + 3a2b + 3ab2 + b3
(a + b)4 = a4 + 4a3b + 6a2b2 + 4ab3 + b4 Suppose you have a set of size
n. How many subsets does 2n
A. 36
Pascal’s triangle it have?
B. 220
C. 15
How many subsets of size 0 𝑛
D. 6
does it have? 0
E. No clue
How many subsets of size 1 𝑛
does it have?
1

How many subsets of size 2 𝑛


does it have?
2

77 Add them up we have the result. 78

Binomial Coefficients Pascal Identity


Sum each row of Pascal’s Triangle:  n  2 n
n  
A relationship between the entries in Pascal’s triangle: n n -1 n -1
     
j j j -1  j 
j 0  
Proof ??? Suppose T is a set, |T|=n. Let a be an
Alternative (clever) proof? Look at binomial theorem… element in T, and let S = T - {a}. So,
n  
n |S| = n-1.
(x  y)n   x n  j y j n 
j
j 0  
Let’s count the  j  subsets of size j.
 
Note that some of these contain a, and
x and y are variables; can pick some don’t.
any numbers… hmm… n - 1
 
Pick x=1 and y=1 ! How many contain a?  j-1
n n  n  j
j 1 1 j  (1  1)n S T How many don’t? n - 1 
j 0 n-1 items n items  
n   j 
n
a
j  2 n

j 0
2.2. Combination 2.2.3. Combinations of multisets
• Let M be a multiset {a1, a2, …, an} (M has n distinct objects):
2.1.1. Definitions – A k-combination of M is an unordered collection of k objects selected from n
2.2.2. Binomial coefficients types of objects of M.
– A k-combination of M is also called an k-combination with repetition allowed.
2.2.3. Combinations of Multisets – 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)
2.2.4. Multinomial coefficients

Need to divide k candies for n kids B1, 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?

t1  t2  t3    tn  k
81 t1 , t2 ,, tn  Z  82

The number of r-combination of M is C(n+ r-1, r) 2.3.3. Combinations of multisets


Proof: When k objects are selected from the multiset M, we put them into the following Example 1: Example 1: How many ways to divide 10 candies for 4 kids
n boxes (there may be kids without any candies)
How many solutions are there to the equation x 1  x 2  x 3  x 4  10
When the variables are nonnegative integers (xi ≥ 0)?
so that the ith type objects are contained in the ith box, 1 ≤ i ≤ n.
Since the objects of the same type are identical, we may use the symbol "O" to denote Answer 1: 11 locations for bars. Pick 3 locations allowing repetitions
any object in the boxes, and the objects in different boxes are separated by a stick "|".  k-combination with repetition allowed (n=11, k = 3). C(11+3-1,3)
For example, for n = 4 and k = 7:

Convert the symbol "O" to zero 0 and the stick "|" to one 1, any such placement is 1  3  6  0  10
converted into a 0-1 sequence of length k+n–1 with exactly k zeros and n–1 ones
Answer 2: (bài toán chia kẹo)
 Now the problem becomes counting the number of 0-1 words of length k+(n–1) with Select with repetition from x1, x2, x3, x4 10 times.
exactly k zeros and n–1 ones For example if x1 is selected twice then x1= 2 in the final solution.
Therefore: k-combination with repetition allowed (n = 4, k =10):
= C(n+ k-1, k) = C(n+ k-1, n-1) 83 84
C(4+10-1,10)
2.3.3. Combinations of multisets The number of k-combination of M is C(n+ k-1, k)
Example 2: How many nonnegative integer solutions are there to the inequality Equivalence of the following: The number C(n+k–1, k) equals
x1  x 2  x 6  10 ? • the number of selections, with repetition, of size k from a
collection of n types objects
It is equivalent to
• the number of nonnegative integer solutions of the equation
x1  x2    x6  x7  10, 0  xi , 1  i  6, 0  x7
x1 + x2 + … + xn = k
which can be transformed to
y1  y2 y6  y7  9, y i  0 integer • the number of ways to place k identical objects into n
distinct containers.
where y i  x i for 1  i  6
• the number of non decreasing sequences of length k whose
and y7  x7  1
terms are taken from the set {1, 2, …, n}.
 Ans1: 10 locations for bars, pick 6 locations allowing repetitions [k = 6, n = 10]
 k-combination with repetition C(6+10-1,6)=C(15,6) =5005

 Ans2: 7 types of objects to select (y1,..,y7) and 9 times of selections [k = 9, n = 7]


 k-combination with repetition C(7+9-1,9)= C(15, 9) = 5005 86

2.2. Combination 2.2.4. Multinomial coefficients


2.1.1. Definitions The number of ordered arrangements of n objects, in which
there are k1 objects of type 1, k2 objects of type 2, ..., and km
2.2.2. Binomial coefficients objects of type m and where k1+k2+ ... +km = n, is
2.2.3. Combinations of Multisets
2.2.4. Multinomial coefficients  n  n!
 
 k1 , k2 ,..., km  k1 !k2 !...km !

87 88
2.2.4. Multinomial coefficients Summary: select or order k objects from n distinct objects
• The Multinomial Theorem: Order matters Order does not matter
1 𝑛! 2 𝑛!
Repetition 𝑃 𝑛, 𝑘 = 𝐶 𝑛, 𝑘 =
 n  k1 k2 km 𝑛−𝑘 ! 𝑘! 𝑛 − 𝑘 !
( x1  x2  ...xm ) n   
not allowed
 x1 x2 ...xm (k-permutation of n-set) (k-combination of n-set)
k ,
 1 2 k ,..., k m
3 𝑛 4 𝑛+𝑘−1 !
Repetition 𝐶 𝑛 + 𝑘 − 1, 𝑘 =
allowed (k-permutation with repetition 𝑘! 𝑛 − 1 !
where the summation is over all sequences of non-negative integers allowed) (k-combination with repetition allowed)
(k1, k2, ..., km) such that k1 + k2 + ... + km = n. The set A = {S,O,H,N}
The 2-permutation (sequence) of set A is: P(4,2) = 12 The 2-combination (set) of set A is: C(4, 2) = 6
SO, SH, SN, OH, ON, OS, HN, HS, HO, NS, NO, NH {S,O},{S,H},{S,N},{O,H},{O,N},{H,N}
1 2
The multi set B = {S, O, H, N}
The 2-permutation with repetition allowed of set B is: 42 = 16 The 2-combination with repetition allowed of
SS, OO, HH, NN, set B is: C(4+2-1,2)=10
SO, SH, SN, OH, ON, OS, HN, HS, HO, NS, NO, NH
{S, S}, {O, O}, {H, H}, {N, N},
89 {S,O},{S,H},{S,N},{O,H},{O,N},{H,N}
3 4

Contents 3. Inclusion-exclusion principle


1. Basic counting principles 3.1. Inclusion-exclusion principle
2. Elementary combinatorial configuration 3.2. Derangement
3. The inclusion-exclusion principle
4. Recurrence relation
5. Generating function

91 92
3.1. Inclusion-exclusion principle 3.1. Inclusion-exclusion principle
The inclusion–exclusion principle is an equation relating the sizes of two sets More generally, for finite sets A1, A2,…,Am
and and their union. It states that if A and B are two (finite) sets, then
|A B| = |A| + |B| - |A B|
𝐴 ∪ 𝐴 ∪ ⋯ ∪ 𝐴 = 𝑁 − 𝑁 + ⋯ + (−1) 𝑁
where:

The meaning of the statement is that
the number of elements in the union Nk  | Ai1  Ai2  ...  Aik |, k  1, 2,..., m
1i1  i2 ... ik  m
of the two sets is the sum of the
elements in each set, respectively,
Note: Nk is the sum of the cardinalities of all intersections of k
minus the number of elements that
are in both. from m given sets. For example:
𝐴 ∪𝐴 ∪𝐴 ∪𝐴 =?
N1 = |A1| + ... + |Am|
Nm = |A1  A2  ...  Am|
Similarly, for three sets A, B and C: m

|A B C| = |A| + |B| + |C| - |A B| - |A C| - |B C| + |A B C| | A1  A2  ...  Am |  | Ai |   | Ai  A j |   | Ai  A j  Ak | ...
i 1 pairs ( ij ) triples ( ijk )
This can be seen by counting how many times each region in the figure is 93  (  1) m 1 | Ai  A j  Ak  ...  Am | 94
included in the right hand side.

3.1. Inclusion-exclusion principle 3.1. Inclusion-exclusion principle


Example 1: How many integers from 1 to 1000 are either multiples of 3 • A = set of all integers from 1 to 1000 that are multiples of 3  |A| = ?
or multiples of 5? From 1 to 1000, every third integer is a multiple of 3, each of this
• A = set of all integers from 1 to 1000 that are multiples of 3. multiple can be represented as 3p, for any integer p from 1 through
[1000/3]=333, Hence |A| = 333.
• B = set of all integers from 1 to 1000 that are multiples of 5.
• B = set of all integers from 1 to 1000 that are multiples of 5 |B| = ?
• AB =?
Similarly for multiples of 5, each multiple of 5 is of the form 5q for
The set of all integers from 1 to 1000 that are multiples of either 3 or 5. some integer q from 1 through [1000/5]=200. Hence, we have |B| = 200.
• AB =? • A  B: set of all integers from 1 to 1000 that are multiples of 15 |A  B|=?
The set of all integers that are both multiples of 3 and 5, which also is To determine the number of multiples of 15 from 1 through 1000, each
the set of integers that are multiples of 15. multiple of 15 is of the form 15r for some integer r from 1 through
• To use the inclusion-exclusion principle to obtain |A  B|, we need [1000/15]=66.  |A  B| = 66.
– |A| • From the principle, we have the number of integers either multiples of
– |B| 3 or multiples of 5 from 1 to 1000 given by
– |A  B| |A  B| = |A| + |B| - |A B|
=333 + 200 – 66 = 467
95 96
3.1. Inclusion-exclusion principle 3.1. Inclusion-exclusion principle
Example 2: There are 350 applicants to a job, and Example 3: In a class of students undergoing a computer course the following were
observed:
• (i) 220 with major in CS
– Out of a total of 50 students: 30 know Java, 18 know C#, 26 know C, 9 know
• (ii) 147 with major in Business both Java and C#, 16 know both Java and C, 8 know both C# and C, 47 know at
• (iii) 51 with major in both CS and Business least one of the three languages.
From this we have to determine:
How many applicants have major neither in CS nor Business ?
a. How many students know none of these languages?
Answer: b. How many students know all three languages?
• A: set of applicants with major in CS
• B: set of applicants with major in Bussiness a. 50 – 47 = 3
 AB: b.
Set of applicants with major both in CS and bussiness A = All the students who know Java in class.
 AB: B = All the students who know C# in the class.
Set of applicants with major in CS or business or both C = All the students who know C in class.
 Students know all three languages, so we need to find |A  B  C|
|A  B| = |A| + |B| - |A B| = 220 + 147 – 51 = 316
We have to derive the inclusion-exclusion formula for three sets
 The desired answer : 350 – 316 = 34 97 |A  B  C| = (|A| + |B| + |C|) –(|B  C| + |A  B| + |A  C|) + |A  B  C| 98

3.1. Inclusion-exclusion principle 3.1. Inclusion-exclusion principle


– Out of a total of 50 students: 30 know Java, 18 know C#, 26 know C, 9 know Example 4: How many binary strings of length 10 such that either start
both Java and C#, 16 know both Java and C, 8 know both C# and C, 47 know at with 00 or end with 11?
least one of the three languages.
A = All the students who know Java in class.
Answer:
B = All the students who know C# in the class. A: set of binary strings of length 10 that start with 00 00xxxxxxxx
C = All the students who know C in class. B: set of binary strings of length 10 that end with 11 8 positions
 Students know all three languages, so we need to find |A  B  C|.  Need to calculate |A  B| Each position: 0/1
|A  B  C| = (|A| + |B| + |C|) – (|B  C| + |A  B| + |A  C|) + |A  B  C|
The inclusion-exclusion formula for 2 sets:
47 = (30+18+26) – (8+9+16) + |A  B  C|
|A B| = |A| + |B| - |A B|
 |A  B  C| = 6

99 100
3. Inclusion-exclusion principle 3.2. Derangement
3.1. Inclusion-exclusion principle 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.
3.2. Derangement (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 Dn the number of derangements of {1, 2, …, n} Dn = ??

101 102

3.2. Derangement 3.2. Derangement


• Denote Dn the number of derangements of {1, 2, …, n} Dn = ?? Let Ai = subset of permutations of {1, 2, …, n} such that the ith element = i in
the permutation.
• 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). • |Ai| = (n-1)! since if exactly one of the n objects is placed at its original
 Dn: number of permutations such that none of the n objects appears in their position, that leaves the other (n-1) objects to be freely permuted in (n-1)!
original positions. Therefore: possible ways. Hence,
Dn = n! - |𝐴 ∪ 𝐴 ∪ ⋯ ∪ 𝐴 |
Remember the inclusion-exclusion principle: since there are n terms in the sum.
• |AiAj| = (n-2)! since if exactly two of the n objects are placed at their
original positions, that leaves the other (n-2) objects to be freely permuted in
(n-2)! possible ways. Hence,

since there are C(n,2) terms in the sum


103 104
3.2. Derangement 3.2. Derangement
Let Ai = subset of permutations of {1, 2, …, n} such that the ith element = i in
Let Ai = subset of permutations of {1, 2, …, n} such that the ith element = i in
the permutation.
the permutation.
1
1

• |Ai Aj Ak | = (n-3)! since if exactly three of the n objects are placed at their
original positions, that leaves the other (n-3) objects to be freely permuted in
(n-3)! possible ways. Hence,

since there are C(n,3) terms in the sum.


The pattern should be clear. When we reach the final term of 1 , we have
|A1 A2 …. An |=1 We have:
which corresponds to all n objects being placed at their original positions. Dn = n! - |𝐴 ∪ 𝐴 ∪ ⋯ ∪ 𝐴 |
105 106

3.2. Derangement 3.2. Derangement


• An example of derangements arises in a very famous problem called It is amusing to note that as n → ∞, the probability that a permutation of n
the hat-check problem: values is a derangement is given by
“n people walk into a party and give their hats to hat-check girl.
Unfornately, she completely loses track of which of n hats belong to
which owners. Therefore, when the party finishes, their hats are returned
at random.”  if n is large (in practical applications, any n greater than about 10 can be
Question: What is the probability that nobody receives their own hat considered to be large), then the probability that the permutation of the n values
back? is a derangement is approximately 1/e almost independently of the precise value
of n. n n! Probability #Derangements
This is equivalent to asking for the probability that a permutation of n 0 1 1
1 1 0 0
objects is a derangement. 2 2 0.5 1
3 6 0.333333333 2
4 24 0.375 9
 = What is the value in number???? 5
6
120
720
0.3666666667
0.368055556
44
265
! 7 5040 0.367857143 1854
since there are Dn possible derangements and n! possible permutations. 8
9
40320
362880
0.367881944
0.367879189
14833
133496
10 3628800 0.367879464 1334961
107 Note: 1/e  0.367879441 108
Contents 4. Recurrence relations
1. Basic counting principles 4.1. Recurrence relations
2. Elementary combinatorial configuration 4.2. Solve recurrence relations
3. The inclusion-exclusion principle
4. Recurrence relation
5. Generating function

109 110

4.1. Recurrence relations 4.1. Recurrence relations


Definition: A recurrence without specifying any initial values (initial conditions).
A recurrence relation for the sequence {an} is the equation that expresses an  can have (and usually has) multiple solutions.
in terms of one or more of the previous terms in the sequence namely, a0, a1, Example: an = 2an-1 – an-2 for n = 2, 3, 4. It has the following sequences an as solution:
…, an-1, for all integers n with n  n0, where n0 is a nonnegative integer. • an=5
A sequence is called a solution to a recurrence relation if its terms satisfy the • an=3n
recurrence relation. • an=n+1
Example: Consider the recurrence relation
an = 2an-1 – an-2 for n = 2, 3, 4, … The sequence an=n+1?? If both the initial conditions and the recurrence relation are specified, then the
sequence is uniquely determined.
• The sequence an=3n is a solution of this recurrence relation?
Example: an = 2an-1 – an-2 for n = 2, 3, 4
For n  2 we see that: 2an-1 – an-2 = 2(3(n – 1)) – 3(n – 2) = 3n = an where a0=0; a1 = 3
Therefore, the sequence an=3n is a solution of the recurrence relation  The sequence an=5 is not the solution
• The sequence an=5 is also a solution of the this recurrence relation?  The sequence an=3n is the unique solution
For n  2 we see that: 2an-1 – an-2 = 25 - 5 = 5 = an
Therefore, the sequence an=5 is also a solution of the recurrence relation
the same recurrence relation can have multiple solutions.  Why???
4.1. Recurrence relations Modeling with Recurrence Relations
Some applications of 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
1. To solve many counting problems we can try construct recurrence after 30 years?
relations. Solution: P30 = (1.05)3010,000 = 43,219.42
2. Complexity analysis of the recursive algorithm is a recurrence • Let Pn denote the amount in the account after n years.
relation on the number of operations. How can we determine Pn on the basis of Pn-1?
• We can derive the following recurrence relation:
Pn = Pn-1 + 0.05Pn-1 = 1.05Pn-1.
• The initial condition is P0 = 10,000.
Then we have:
• P1 = 1.05P0
• P2 = 1.05P1 = (1.05)2P0
• P3 = 1.05P2 = (1.05)3P0
•…
•Pn = 1.05Pn-1 = (1.05)nP0
 We now have a formula to calculate Pn for any natural number n and can avoid the
iteration. 114

Example 2: Fibonacci Modeling with Recurrence Relations


A pair of rabbits is placed on an island. After 2 months old, a pair of rabbits Example 2: Fibonacci
produces another pair each month. How many rabbits are there after n months?
 n = 1: f1 = 1 A pair of rabbits is placed
 n = 2: f2 = 1 Fibonacci sequence: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233,etc. on an island. After 2
months old, a pair of
 n > 2: fn = fn-1 + fn-2
rabbits produces another
The n > 2 formula is true since each new pair comes from a pair at least 2 months old. pair each month. How
New-born Month 1-month rabbits >=2-month rabbits Total fn
rabbits
many rabbits are there after
n months?
1 1 0 1
2 0 1 1
3 1 1 2
4 1 2 3
 n = 1: f1 = 1
5 2 3 5  n = 2: f2 = 1
6 3 5 8  n > 2: fn = fn-1 + fn-2
7 5 8 13
The n > 2 formula is true since each new pair comes from a pair at least 2 months
8 8 13 21
old.
Modeling with Recurrence Relations Modeling with Recurrence Relations
Example 3: Let an denote the number of bit strings of length n that do Example 4: The Tower of Hanoi, consists of three towers (a), (b), (c) together with
not have two consecutive 0s (“valid strings”). Find a recurrence relation n disks of different sizes. Initially these disks are stacked on the tower (a) in an
and give initial conditions for the sequence {an}. ascending order, i.e. the smaller one sits over the larger one.
The objective of the game is to move all the disks from tower (a) to tower (c),
Solution:
following 3 rules:
Idea: The number of valid strings equals the number of valid strings • Only one disk can be moved at a time.
starting with a 0 plus the number of valid strings starting with a 1. • Only the top disk can be moved
• The sum rule: an = |A| + |B|. • No large disk can be sit over a smaller disk.
• We have: Let hn denote the minimum number of moves needed to solve the Tower of Hanoi
– A = {1??????}  |A| = an-1 problem with n disks. What is the recurrence relation for hn?
– B = {0??????}  2nd place is 1  |B| = an-2
• Therefore
an = an-1 +an-2, n > 2 fn = fn-1 + fn-2 , n > 2
a1 = 2; a2 = 3; f1=1, f2=1
This sequence satisfies the same recurrence relation as the Fibonacci sequence. 117 118
Since a1 = f3 and a2 = f4, we have an = fn+2 Tower a Tower c Tower b

Tower of Hanoi: n=5 Tower of Hanoi


The objective of the game is to move all the disks from tower (a) to tower (c), following • h1 = 1
3 rules: • For n ≥ 2, we need to do 3 following steps to transfer all disks from tower (a) to tower (c):
1. Only one disk can be moved at a time. (1) Move the top n - 1 disks (following the rules of the game) from tower (a) to tower (b)
2. Only the top disk can be moved
3. No large disk can be sit over a smaller disk. (2) Move the largest disk to the tower (c)

(3) Move the n-1 disks (following the rules of the game) from tower (b) to tower (c), placing
them on top of the largest disk

Tower a Tower c
Toán rời rạc
Tower b Tower a Tower c
Toán rời rạc
Tower b
Tower of Hanoi Tower of Hanoi: n=5
• h1 = 1 (1) Move the top n - 1 disks (following the rules of the game) from tower (a) to tower (b)
• For n ≥ 2, we need to do 3 following steps to transfer all disks from tower (a) to tower (c):
The problem of n-1 disks  #moves = hn-1
(1) Move the top n - 1 disks (following the rules of the game) from tower (a) to tower (b)
(2) Move the largest disk to the tower (c)
The problem of n-1 disks  #moves = hn-1  #moves = 1
(2) Move the largest disk to the tower (c) (3) Move the n-1 disks (following the rules of the game) from tower (b) to tower (c) , placing
 #moves = 1 them on top of the largest disk
(3) Move the n-1 disks (following the rules of the game) from tower (b) to tower (c), placing The problem of n-1 disks  #moves = hn-1
them on top of the largest disk
The problem of n-1 disks #moves = hn-1

hn = 2hn-1 + 1, n ≥ 2
h1 = 1

Tower a Tower c
Toán rời rạc
Tower b Tower a Tower c
Toán rời rạc
Tower b

Tower of Hanoi History “Tower of Hanoi”


Find the formula to calculate hn for any natural number n and can avoid Legend: a group of Eastern monks are the keepers of three towers on
the iteration. which sit 64 golden rings. Originally all 64 rings were stacked on one
hn = 2 hn−1 + 1 tower with each ring smaller than the one above. The monks are to move
the rings from this first tower to the third tower one at a time but never
= 2 (2 hn−2 + 1) + 1 = 22 hn−2 + 2 + 1
moving a larger ring on top of a smaller one. Once the 64 rings have all
= 22(2 hn−3 + 1) + 2 + 1 = 23 hn−3 + 22 + 2 + 1 been moved, the world will come to an end.
…  Number of moves = 264-1 = 18 446 744 073 709 551 615
= 2n−1 h1 + 2n−2 + … + 2 + 1  which would require more than five billion centuries!
= 2n−1 + 2n−2 + … + 2 + 1 (because h1 = 1)
It was invented by the French mathematician Eduoard Lucas
n
=2 −1
in 1883
4.1. Recurrence relations 4.1. Recurrence relations
Some applications of recurrence relations: Example 5. Recall the factorial function
1. To solve many counting problems we can try construct recurrence
relations.
2. Complexity analysis of the recursive algorithm is a recurrence
relation on the number of operations. Consider the following (recursive) algorithm for computing n!

4.1. Recurrence relations 4.1. Recurrence relations

Factorial(n); Factorial(n);

How many times is function Factorial called when we execute the statement Factorial(n); ? T(n) = T(n − 1) + 1, n >1
• When n = 1, Factorial is called 1 T(1) = 1 = [T(n-2) +1] + 1 [has 2 ones]
• Otherwise: =[[T(n-3)+1]+1]+1 [has 3 ones]
– We perform 1. T(n) = 1 + T(n-1) =….
– Plus the number of calls in the recursive call in Factorial(n − 1)  T(n-1) = T(n – (n-1)) + (n-1) [has n-1 ones]
This can be expressed as a formula (similar to the definition of n!): = T(1) + (n-1)
T(1) = 1 Find the formula to calculate T(n) for = 1 + (n-1)
T(n) = 1 + T(n − 1), n >1 any natural number n and can avoid the =n
This is known as a recurrence relation. iteration. explicit formula
4.1. Recurrence relations 4.1. Recurrence relations
Example 6. Performance of Recursive Binary Search
Input: An array A consists of n elements: A[0],…,A[n-1] in ascending
order; Value key with the same data type as array A.
Output: the index in array if key is found, -1 if key is not found

To solve this problem, the divide and conquer technique is built based on the following
argument: The given key is either
How many multiplications M(n) does Factorial perform? equal to the element at the middle of array A
• When n = 1 we don’t perform any  M(1) = 0 or equal to the element at the left (L) half of array A
or equal to the element at the right (R) half of array A.
• Otherwise:
or not in array
– We perform 1.
– Plus the number of multiplications we perform in the recursive call, Factorial(n − 1)  M(n-1)
This can be expressed as a formula (similar to the definition of n!):
M(0) = 0; M(1) = 0 Find the formula to calculate T(n) for
M(n) = 1 + M(n − 1), n >1 any natural number n and can avoid the 130
This is known as a recurrence relation. iteration.

4.1. Recurrence relations Example: Binary Search


Input: An array A consists of n elements: A[0],…,A[n-1] in ascending order; int binsearch(int low, int high, int A[], int key)
{
Value key with the same data type as array A. if (low <= high)
Output: the index in array if key is found, -1 if key is not found {
mid = (low + high) / 2;
To solve this problem, the divide and conquer technique is built based on the following if (A[mid]== key) return mid;
else if (key < A[mid])
key=33
argument: The given key is either return binsearch(low, mid-1, A, key);
equal to the element at the middle of array A else
or equal to the element at the left (L) half of array A return binsearch(mid+1, high, A, key);
}
or equal to the element at the right (R) half of array A. else return -1;
or not in array }
int binsearch(int low, int high, int A[], int key)
{ 6 13 14 25 33 43 51 53 64 72 84 93 95 96 97
if (low <= high)
{ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
mid = (low + high) / 2;
if (A[mid]==key) return mid;
lo hi
else if (key < A[mid])
return binsearch(low, mid-1, A, key); binsearch(0, 14, A, 33);
else
return binsearch(mid+1, high, A, key);
}
else return -1; 131 132
}
Example: Binary Search Example: Binary Search
int binsearch(int low, int high, int A[], int key) int binsearch(int low, int high, int A[], int key)
{ {
if (low <= high) if (low <= high)
{ {
mid = (low + high) / 2; mid = (low + high) / 2;
if (A[mid]== key) return mid;
else if (key < A[mid])
key=33 if (A[mid]== key) return mid;
else if (key < A[mid])
key=33
return binsearch(low, mid-1, A, key); return binsearch(low, mid-1, A, key);
else else
return binsearch(mid+1, high, A, key); return binsearch(mid+1, high, A, key);
} }
else return -1; else return -1;
} }

6 13 14 25 33 43 51 53 64 72 84 93 95 96 97 6 13 14 25 33 43 51 53 64 72 84 93 95 96 97
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14

lo mid hi lo hi
binsearch(0, 14, A, 33); binsearch(0, 14, A, 33);
The section to be binsearch(0, 6, A, 33); binsearch(0, 6, A, 33);
investigated is halved
133 134
after each iteration

Example: Binary Search Example: Binary Search


int binsearch(int low, int high, int A[], int key) int binsearch(int low, int high, int A[], int key)
{ {
if (low <= high) if (low <= high)
{ {
mid = (low + high) / 2; mid = (low + high) / 2;
if (A[mid]== key) return mid;
else if (key < A[mid])
key=33 if (A[mid]== key) return mid;
else if (key < A[mid])
key=33
return binsearch(low, mid-1, A, key); return binsearch(low, mid-1, A, key);
else else
return binsearch(mid+1, high, A, key); return binsearch(mid+1, high, A, key);
} }
else return -1; else return -1;
} }

6 13 14 25 33 43 51 53 64 72 84 93 95 96 97 6 13 14 25 33 43 51 53 64 72 84 93 95 96 97
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14

lo mid hi lo hi

binsearch(0, 14, A, 33); binsearch(0, 14, A, 33);


The section to be binsearch(0, 6, A, 33); binsearch(0, 6, A, 33);
investigated is halved binsearch(4, 6, A, 33); binsearch(4, 6, A, 33);
135 136
after each iteration
Example: Binary Search Example: Binary Search
int binsearch(int low, int high, int A[], int key) int binsearch(int low, int high, int A[], int key)
{ {
if (low <= high) if (low <= high)
{ {
mid = (low + high) / 2; mid = (low + high) / 2;
if (A[mid]== key) return mid;
else if (key < A[mid])
key=33 if (A[mid]== key) return mid;
else if (key < A[mid])
key=33
return binsearch(low, mid-1, A, key); return binsearch(low, mid-1, A, key);
else else
return binsearch(mid+1, high, A, key); return binsearch(mid+1, high, A, key);
} }
else return -1; else return -1;
} }

6 13 14 25 33 43 51 53 64 72 84 93 95 96 97 6 13 14 25 33 43 51 53 64 72 84 93 95 96 97
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14

lo mid hi lo
hi
binsearch(0, 14, A, 33); binsearch(0, 14, A, 33);
The section to be binsearch(0, 6, A, 33); binsearch(0, 6, A, 33);
investigated is halved binsearch(4, 6, A, 33); binsearch(4, 6, A, 33);
137 138
after each iteration binsearch(4, 4, A, 33); binsearch(4, 4, A, 33);

Example: Binary Search Example: Binary Search


int binsearch(int low, int high, int A[], int key) int binsearch(int low, int high, int A[], int key)
{ {
if (low <= high) if (low <= high)
{ {
mid = (low + high) / 2; mid = (low + high) / 2;
if (A[mid]== key) return mid;
else if (key < A[mid])
key=33 if (A[mid]== key) return mid;
else if (key < A[mid])
key=33
return binsearch(low, mid-1, A, key); Value 33 is located @index=4
return binsearch(low, mid-1, A, key);
else else

}
return binsearch(mid+1, high, A, key);
}
return binsearch(mid+1, high, A, key);
key=31??
else return -1; else return -1;
} }

6 13 14 25 33 43 51 53 64 72 84 93 95 96 97 6 13 14 25 33 43 51 53 64 72 84 93 95 96 97
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14

lo lo
hi hi
mid binsearch(0, 14, A, 33); mid binsearch(0, 14, A, 33);
binsearch(0, 6, A, 33); binsearch(0, 6, A, 33);
binsearch(4, 6, A, 33); binsearch(4, 6, A, 33);
139 140
binsearch(4, 4, A, 33); binsearch(4, 4, A, 33);
4.1. Recurrence relations 4.1. Recurrence relations
Example 6. Performance of Recursive Binary Search Example 6. Performance of Recursive Binary Search
int binsearch(int low, int high, int A[], int key)
Input: An array A consists of n elements: A[0],…,A[n-1] in ascending {
order; Value key with the same data type as array A. if (low <= high)  T(0) = ?
{
 binsearch(0, -1, A, key);
Output: the index in array if key is found, -1 if key is not found mid = (low + high) / 2;
int binsearch(int low, int high, int A[], int key)
if (A[mid]==key) return mid;  T(1) = ?
else if (key < S[mid])
{ return binsearch(low, mid-1, A, key);  binsearch(0, 0, A, key);
if (low <= high) else
{ return binsearch(mid+1, high, A, key);
 binsearch(0, -1, A, key);
mid = (low + high) / 2; }  binsearch(1, 0, A, key);
if (A[mid]==key) return mid; else return -1;
else if (key < S[mid]) }
return binsearch(low, mid-1, A, key);  binsearch(0, n-1, A, key);
else
return binsearch(mid+1, high, A, key);
Let T(n): the number of times that binsearch is called in the worst case when array A has n elements
} • T(0) = 1 Recurrence relation:
else return -1;
} • T(1) = 2 T(n) = T(n/2) + 1
 binsearch(0, n-1, A, key); • T(2) = T(1) + 1 = 3 T(0) = 1
How many times is binsearch called in the worst case ? • T(4) = T(2) + 1 = 4 T(1) = 2
141
• T(8) = T(4) + 1 = 4 + 1 = 5 142
• T(n) = T(n/2) + 1

4. Recurrence relations 4.2. Solving Recurrence Relations


Solving the recurrence relation for a sequence a0, a1, a2, a3,….an,… is to give
4.1. Recurrence relations the explicit formula to compute the value for the general term an, i.e., to find an
4.2. Solving recurrence relations expression for an that does not involve any other ai
Example: Given the recurrence relation:
an = 2an-1 – an-2 where n = 2, 3, 4,…
a0=0; a1 = 3
 The explicit formula for the above recurrence relation is an=3n
 an=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
143 144
4.2. Solving Recurrence Relations 4.2. Solving Recurrence Relations
Definition: A linear homogeneous recurrence relation of degree Definition: A linear homogeneous recurrence relation of degree
k with constant coefficients is a recurrence relation of the form: k with constant coefficients is a recurrence relation of the form:
an = c1an-1 + c2an-2 + … + ckan-k an = c1an-1 + c2an-2 + … + ckan-k
where c1, c2, …, ck are real number constants, and ck  0. where c1, c2, …, ck are real number constants, and ck  0.

• A sequence satisfying such a recurrence relation is uniquely Explain:


determined by the recurrence relation if it also satisfying k initial
conditions: • Linear (tuyến tính): the right-hand side is the sum of the terms
before the term an in the sequence where the coefficients (c1, c2,
a0 = C0, a1 = C1, a2 = C2, …, ak-1 = Ck-1 ..,ck) are constant (not a function dependent on n)
where C0, C1, ..., Ck-1 are constants. • Homogeneous (thuần nhất): the right-hand side has no additional
terms other than the terms ai of the sequence
• Degree k: the right hand side has the (n-k)th term of the sequence
145 146

A linear homogeneous recurrence relation of degree k with


A linear homogeneous recurrence relation of degree k with constant coefficients
constant coefficients
Example 1: Which one is the linear homogeneous recurrence • We try to find solution of the form an = rn, where r is a constant.
relation of degree k with constant coefficients • The sequence {an = rn } is a solution of the recurrence relation
1) an = 4an-1 +2nan-3 an = c1an−1 + … + ckan−k
if and only if r satisfying:
2) hn = 2hn-1 + 1
rn = c1rn−1 + … + ckrn−k, or (substract the right-hand side from the left
3) bn = 5bn-2 + 2(bn-3)2 rk − c1rk−1 − … − ck = 0 and × by rk−n)
4) qn = 3 qn-6 + qn-8
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.

147 148
A linear homogeneous recurrence relation of degree k with
constant coefficients
Example 1
• Theorem 1. Let c1 and c2 be real numbers. Fibonacci sequence is given by the following recurrence relation:
Fn = Fn-1 + Fn-2, n  2,
Suppose that r2 - c1 r - c2 = 0 has 2 distinct roots r1 and r2. Then the F0 = 0, F1 = 1.
sequence {an} is a solution of the recurrence relation Find the explicit formula for Fn.
an = c1 an-1 + c2 an-2 Solution: Solve the characteristic equation:
r2 - r - 1 = 0,
if and only if its characteristic roots are:
an = 1(r1)n + 2(r2)n (1) r1 
1 5
; r2 
1 5
2 2
n = 0, 1, ..., where 1 and 2 are constants. Leonardo Fibonacci
1170-1250

Recurrence relation: an = c1 an-1 + c2 an-2


Characteristic equation: r2 − c1r − c2 = 0
149 150

Example 1 The case: one characteristic root with multiplicities 2


• The explicit formula: But what happens if the characteristic equation has only one root?
Fn = 1.(r1)n + 2.(r2)n Theorem 2: Let c1 and c2 be real numbers with c2  0. Suppose that r2 -
where 1,  2 are constants and could be determined by using c1 r - c2 = 0 has only one root r0. Then a sequence {an } is a solution of
initial conditions F0, F1. F0= 1+ 2 = 0 the recurrence relation an = c1 an-1 + c2 an-2
F1= 1r1+ 2r2 = 1
if and only if
Solving these two equations, we have: 1  1 ;  2   1
5 5 an   1r0n   2 nr0n
Muavre formula n = 0, 1, ..., where 1 , 2 are constants.

Therefore
1 
    
n n
1 5 1 5  , n  0.
Fn  
5 2 2 
 

151 152
Example 2 General case
Solving the following recurrence relation Theorem 3. Let c1, c2, ..., ck be real numbers. Assume the characteristic
an = 6 an-1 - 9 an-2
equation
with initial conditions a0 = 1 and a1 = 6.
Solution: rk - c1 rk-1 - c2 rk-2 - . . . - ck = 0
Characteristic equation: has k distinct roots r1, r2, ..., rk . Then a sequence {an} is a solution of
r2 - 6 r + 9 = 0 has one root r = 3. The solution is:
the recurrence relation:
an = 1 3n + 2 n 3n
To determine 1, 2 , using the initial conditions, we have: an = c1 an-1 + c2 an-2 +...+ ck an-k,
a0 = 1 = 1 , if and only if
a1 = 6 = 1 * 3 + 2 *1* 3
Solving these equations, we have 1 = 1 and 2 = 1.
an = 1 r1n + 2 r2n + . . . + k rkn
Therefore, the solution of the recurrence relation is: where n = 0, 1, 2,..., and 1, 2, ..., k are constants
an = 3n + n 3n
Recurrence relation: an = c1an−1 + … + ckan−k
Characteristic equation: rk − c1rk−1 − … − ck = 0
153 154

Example 3 Example 3
Solving the recurrence relation: Using the initial conditions, we have following equations to
an = 6 an-1 - 11 an-2 + 6 an-3 determine the value for constants 1, 2, 3:
where initial conditions a0 = 2 = 1 + 2 + 3
a0 = 2, a1 = 5, a2 = 15. a1 = 5 = 1 + 2.2 + 3.3
Solution: Characteristic equation
a2 = 15 = 1 + 2.4 + 3.9.
r3 - 6 r2 + 11 r - 6 = 0
Solving above equations, we have
has 3 distinct roots r1 = 1, r2 = 2, r3 = 3.
Therefore, the solution is
1 = 1, 2 = -1 and 3 = 2.
an = 1 1n + 2 2n + 3 3n for some constants 1, 2, 3 Therefore, the solution of the recurrence relation is
an = 1 - 2n + 2. 3n

Recurrence relation: an = c1an−1 + … + ckan−k


Characteristic equation: rk − c1rk−1 − … − ck = 0
155 156
General case Linear nonhomogeneous recurrence relation with constant coefficients

Given linear homogeneous recurrence relation of degree k with constant • Linear nonhomogeneous recurrence relation with constant
coefficients k
an  ci ani coefficients) has the term F(n) dependent on n (and
Its characteristic equation is: i 1 independent on any value of ai ) :
k
r k  ci r k i  0 an = c1an−1 + … + ckan−k + F(n)
i 1

Theorem 4: If the characteristic equation has t distinct roots


Linear homogeneous recurrence relation Nonhomogeneous term
r1,…,rt with multiplicities m1,…,mt (m1+…+mt = k). Then:
an = ( , + , n+…+ , 𝑛 )𝑟 +
( + n+…+ 𝑛 ) 𝑟 + ... t  mi 1 
an   i, j n j rin
, , ,
(t,0 +  , n + … +  𝑛 )𝑟
i 1  j 0 
,

where n≥0, and αij are constants.

157

Solving Linear nonhomogeneous recurrence relation Solving Linear nonhomogeneous recurrence relation
The following result is the basis for solving the nonhomogeneous Then, we have the method for solving linear nonhomogeneous recurrence relation:
recurrence relation: 1) Find the solution h(n) of linear homogeneous part.
– If an = p(n) is a particular solution of linear nonhomogeneous 2) Find particular solution p(n) of linear nonhomogeneous recurrence relation.
recurrence relation 3) The solution of linear nonhomogeneous recurrence relation is of the form:
 k 
an   ci ani   F (n) an = h(n) + p(n)
 i1  4) Determine the constants from equations obtained by initial conditions

Then the solution of linear nonhomogeneous recurrence relation is of


the form:
an = p(n) + h(n),
where an = h(n) is the solution of the linear homogeneous part:
k
an   ci an i
i 1
Solving Linear nonhomogeneous recurrence relation Example 1: Tower of Hanoi
How to find particular solution p(n) of linear nonhomogeneous recurrence Example 4: The Tower of Hanoi, consists of three towers (a), (b), (c) together with n
relation? disks of different sizes. Initially these disks are stacked on the tower (a) in an
ascending order, i.e. the smaller one sits over the larger one.
The objective of the game is to move all the disks from tower (a) to tower (c),
following 3 rules:
There is no known general method for solving nonhomogeneous linear • Only one disk can be moved at a time.
recurrence relation. However, we can develop a method for solving the • Only the top disk can be moved
• No large disk can be sit over a smaller disk.
special case:
Let an denote the minimum number of moves needed to solve the Tower of Hanoi
F(n) = G(n)  sn = (btnt + bt-1nt-1 + ... + b0)sn problem with n disks. What is the recurrence relation for an?

where s is a constant; G(n) is polynomial in n


• If s is not equal to characteristic root, then particular solution p(n) is of
the form F(n)
• If s is equal to characteristic root with multiplicities m, then particular
solution p(n) is the form of nmQ(n)sn where Q(n) is of the form G(n) 162
Tower a Tower c Tower b

Example 1: Tower of Hanoi Example 1: Tower of Hanoi

To solve the recurrence relation, we could use the substitution method: Solving:
an = 2 an−1 + 1 an = 2an-1 + 1, n  1;
= 2 (2 an−2 + 1) + 1 = 22 an−2 + 2 + 1 a1 = 1.
= 22(2 an−3 + 1) + 2 + 1 = 23 an−3 + 22 + 2 + 1 Solution:
… (1) Linear homogeneous part: an = 2an-1
= 2n−1 a1 + 2n−2 + … + 2 + 1  Characteristic equation: r - 2 = 0 has one root r = 2
= 2n−1 + 2n−2 + … + 2 + 1 (as a1 = 1)  Solution of linear homogeneous part is: h(n) = c12n
= 2n − 1 (2) Linear Nonhomogenenous part F(n) = 1, then the particular solution is
of the form
p(n) = C

Substitute to the nonhomogeneos recurrent relation: C = 2C+1  C = -1


163
Hence the particular solution is: p(n) = -1.
Example 1: Tower of Hanoi Example 2
Solving: Solving the recurrence relation
an = 2an-1 + 1, n  1; an=5an-1 - 6an-2+7n, n2,
a1 = 1. a0 = 0; a1 = 1
Solution:
(1) Linear homogeneous part: an=5an-1 - 6an-2
(3) The solution of linear nonhomogeneous recurrence relation:
Characteristic equation: r2 – 5r +6 = 0 has 2 distinct roots r1 = 3, r2 = 2
an = h(n) + p(n) = c12n – 1 Thus the solution of linear homogeneous part is:
(4) Determnine c1 by using initial condition: h(n) = c13n + c22n
(2) The nonhomogeneous part: F(n) = 7n and 7 is not characteristic root, thus
a1 = c121 -1 = 1
the particular solution is of the form:
 c1 = 1 p(n) = C.7n
Hence, the solution of linear nonhomogeneous recurrence relation: Substitute to the recurrence relation:
an = 2n -1, n  1. C7n = 5C7n-1 – 6C7n-2 + 7n  C = 49/20
Hence the particular solution is p(n) = (49/20)7n

Example 2 Example 3
Solving the recurrence relation Solving recurrence relation:
an=5an-1 - 6an-2+7n, n2, an = an-1 + n, n  1; a1 = 2
a0 = 0; a1 = 1 Solution:
Solution: (1) Linear homogeneous part: an = an-1
(3) The solution of linear nonhomogeneous recurrence relation is Characteristic equation r - 1 = 0 has the root r = 1
an = p(n) + h(n) = (49/20)7n + c13n + c22n  The solution of linear homogeneous part is: h(n) = c11n
(2) Nonhomogeneous part F(n) = n1n, and 1 is the root of multiplicities 1,
(4) The constants c1, c2 are determined by using initial conditions:
thus the particular solution is of the form
a0 = c1 + c2 + 49/20 = 0
p(n) = n1(C2 + C3n)1n
a1 = 3c1 + 2c2 +(49/20).7 = 1
 c1 = ?, c2 = ? Substitute to the recurrence relation, we have:
Hence, the solution of linear nonhomogeneous recurrence relation is n (C2 + C3n) = (n-1) [C2 + C3(n-1)] + n
an = … Thus, C2 = ½ and C3 = ½ . The particular solution is
p(n) = (n+1)n/2
Example 3 Example 4
Solving recurrence relation: Solving the recurrence relation: an = 6an-1 -9an-2 + F(n)
an = an-1 + n, n  1; a1 = 2 Characteristic equation: r2 – 6r + 9 = (r - 3)2=0
 Characteristic root with multiplicities 2: r = 3
Consider some cases F(n) = G(n)sn where G(n) is polynomial of n:
• (1) Assume F(n) = n22n
(3) The solution of linear nonhomogeneous recurrence relation is – As: F(n) = G(n)sn = n22n
 Degree of G(n) is t = 2, s = 2 is not the characteristic root
an = c1+ (n+1)n/2
– Thus, the particular solution is of the form:
(4) The constant c1 is determined by using initial condition: (ptnt + pt-1nt-1 + ... + p0)sn
a 1 = c1 + 1 = 2 =(p2n2 + p1n + p0)2n
• (2) Assume F(n) = n23n
 c1 = 1 – As F(n) = G(n)sn = n23n
The solution of linear nonhomogeneous recurrence relation is  Degree of G(n) is t = 2, s = 3 is characteristic root with multiplicities 2
– Thus, the particular solution is of the form:
an = 1+ (n+1)n/2, n  1
nm(ptnt + pt-1nt-1 + ... + p0)sn
=n2(p2n2 + p1n1 + p0)3n

Example 4 Recurrence tree method


Solving the recurrence relation: an = 6an-1 -9an-2 + F(n) In this method, we draw a recurrence tree :
Characteristic equation: r2 – 6r + 9 = (r - 3)2=0
 Characteristic root with multiplicities 2: r = 3
• Each node of the tree corresponds to an input data function.
Consider some cases F(n) = G(n)sn where G(n) is polynomial of n: As going down the tree, the size of the input data will
• (3) Assume F(n) = 3n decrease.
– As: F(n) = G(n)sn = 13n • The last level of the tree corresponds to the smallest input
 Degree of G(n) is t = 0, s = 3 is characteristic root with multiplicities 2
data size.
– Thus, the particular solution is of the form:
nm(ptnt + pt-1nt-1 + ... + p0)sn We calculate the time taken by every level of tree, and finally,
=n2(p0)3n we sum the work done at all levels.
• (4) Assume F(n) = n3n
– As F(n) = G(n)sn = n3n
 Degree of G(n) is t = 1, s = 3 is characteristic root with multiplicities 2
– Thus, the particular solution is of the form:
nm(ptnt + pt-1nt-1 + ... + p0)sn
=n2(p1n1 + p0)3n
Example 1: Solving the recurrence relation:
Example 2: Performance of Recursive Binary Search
T(n) = 2T(n/2) + n, T(1) = 4
int binsearch(int low, int high, int A[], int key)
{
if (low <= high)
{
mid = (low + high) / 2;
if (A[mid]==key) return mid;
else if (key < S[mid])
return binsearch(low, mid-1, A, key);
else
return binsearch(mid+1, high, A, key);
}
else return -1;
}

n*4  binsearch(0, n-1, A, key);


Let T(n): the number of times that binsearch is called in the worst case when array A has n elements
• The last level log2n has the value = 4n, thus we have: • T(0) = 1 Recurrence relation:
• T(1) = 2 T(n) = T(n/2) + 1
• T(2) = T(1) + 1 = 3 T(0) = 1
• T(4) = T(2) + 1 = 4 T(1) = 2
• T(8) = T(4) + 1 = 4 + 1 = 5 174
• T(n) = T(n/2) + 1

Example 3: Solving the recurrence relation


Example 3: Solving the recurrence relation T(n) = T(n/) + f(n), T() = c
T(n) = T(n/) + f(n), T() = c Iteration Cost
0 TT(n) f(n)

1 f(n/)
T(n/) T(n/)    T(n/)

2 T(n/2) 2f(n/2)
   T(n/2) T(n/2)    T(n/2)
. .
. .
i i f(n/i)
. .
log n
• The value of T(n) is the sum of the cost of all level on the tree:
2.5. Recurrence relations and generating functions 2.5.2. Generating functions

2.5.1. Recurrence relations Generating functions are a tool to solve a wide variety of counting
problems and recurrence relations.
2.5.2. Generating functions Example 1:
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

a, b , c are the number of oranges


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

177 178

2.5.2. Generating functions 2.5.2. Generating functions


Example 1: Find the number of integer solutions to Example 1: Find the number of integer solutions to
a + b + c = 12 where a ≥ 4, b ≥ 2, 2 c  5 a + b + c = 12 where a ≥ 4, b ≥ 2, 2 c  5
Let Let
a: a(x) = x4 + x5 + x6 + x7 + x8 (since b + c  4  a  8) 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) b : b(x) = x2 + x3 + x4 + x5 + x6 (since a + c 6  b  6)
1. x4*x3*x5
c : c(x) = x2 + x3 + x4 + x5 (since 2  c  5) c : c(x) = x2 + x3 + x4 + x5 (since 2  c  5)
The coefficient of x12 in g(x) = a(x) b(x) c(x)
n=12 The coefficient of x12 in g(x) = a(x) b(x) c(x)
2. x4*x4*x4
3. x4*x5*x3
=(x4+ x5+ x6+ x7+ x8) (x2+ x3+x4+ x5+ x6)(x2+ x3+x4+ x5) =??? =(x4+ x5+ x6+ x7+ x8) (x2+ x3+x4+ x5+ x6)(x2+ x3+x4+ x5) 4. x4*x6*x2
is the solution to the problem which is 14, is the solution 5. x5*x2*x5
g(x) is called a generating function.
Why??? g(x) is called a generating function. 6. x5*x3*x4
Assume xa, xb, xc are terms derived from (x4+ x5+ x6+ x7+ x8) , (x2+ x3+x4+ x5+ x6), (x2+ x3+x4+ x5) 7. x5*x4*x3
respectively when developing the right-hand side  4 a  8, 2 b  6, 2 c  5 8. x5*x5*x2
When developing the right-hand side, these three terms give us the term xn where n = a +b + c: 9. x6*x2*x4
g(x) = (x4+ x5+ x6+ x7+ x8) (x2+ x3+x4+ x5+ x6)(x2+ x3+x4+ x5) 10. x6*x3*x3
= …. + Kxn +….. 11. x6*x4*x2
 The coefficient of xn in f(x) is the number of positive integer solutions to 12. x7*x2*x3
a + b + c = n where 4 a  8, 2 b  6, 2 c  5 13. x7*x3*x2
179 14. x8*x2*x2 180
2.5.2. Generating functions 2.5.2. Generating functions
Example 2: Four kinds of jelly beans: Red, Green, White, Black. In how many Definition: Let a0, a1, a2, … be a sequence of real numbers. The function

ways can we select 24 jelly beans so that we have an even number of white
beans and at least six black ones? g ( x )  a0  a1 x  ...  ak x k  ...   ai xi
i 0
• White: 1+ x2+ x4+….+ x16 + x18 is called the generating function for the given sequence.
• Black: x6+ x7+….+ x16+ x18 • A finite sequence
• Red (green): 1+ x1+ x2+….+ x16+ x18 a0, a1, a2, …, an
g(x)=(1+ x2+ x4+….+ x16+ x18)(x6+ x7+….+ x16+ x18) (1+ x1+ x2+….+ x16+ x18)2 can be regarded as the infinite sequence
The coefficient of x24 is the solution. a0, a1, a2, …, an, 0, 0,… [set all terms higher than n to 0]
and its generating function
Example 3: How many nonnegative integer solutions are there for g(x) = a0 + a1x + a2x2 + … + anxn
c1+c2+c3+c4=25? is a polynomial.
Example 4: For the binomial coefficients we already know that:
• g(x)=(1+ x1+ x2+….+ x24+ x25)4 n n

• The coefficient of x25 is the solution ( x  y )n   C (n, k ) x k y n  k  ( x  1)n   C ( n, k ) x k  g ( x)


k 0 k 0

(x+1)n is the generating function for the sequence


181 C(n, 0), C(n, 1),…,C(n, k),…, C(n, n), 0,0,0… 182

2.5.2. Generating functions 2.5.2. Generating functions


Definition: Let a0, a1, a2, … be a sequence of real numbers. The function • If we have two generating functions F(x) and G(x), we define the sum and

product as follows:
g ( x )  a0  a1 x  ...  ak x  ...   ai x
k i
 

i 0 F ( x)   ak x k G ( x)   bk x k
is called the generating function for the given sequence. k 0

k 0

Some useful generating function: F ( x)  G ( x)    ak  bk  x k Match all terms with equal powers in x.
k 0
Ex1: (1  xn+1) = (1  x)(1 + x + x2 + x3 + ...+ xn).   k 
So (1-xn+1)/(1-x) = 1 + x + x2 + x3 + ...+ xn, F ( x)G( x)     a j bk  j  x k
k 0  j 0 
 (1-xn+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) Ex4: Example why multiplying generating functions is useful:
Ex2: From Ex1, If n   and |x| < 1, then 1 = (1  x)(1 + x + x2 + x3 + ...). = =(1+x+x2+x3+...)(1+x+x2+x3+...) where |x| < 1
( )
So, 1/(1-x) = 1 + x + x2 + x3 + ...   k  k 
   1 x k  *   1 x k      1 x   ( k  1) x
    k
 1/(1-x) where |x| < 1 is the generating function for the sequence:  k 0   k 0  k  0  j 0  k 0
1, 1, 1, …, 1, … .
Ex3: From Ex2, set x = ay  |ay| < 1, then  1/(1-x)2 is the generating function for the sequence 1,2,3,4,….
1/(1-x) = 1/(1-ay) = 1 + ay + (ay)2 + (ay)3 + ….
183 184
 1/(1-ay) where |ay| < 1 is the generating function for the sequence 1, a, a2, a3,…
2.5.2. Generating functions 2.5.2. Generating functions
Another way to show that 1/(1-x)2 is the generating function of the sequence 1, Ex5: Show that x/(1-x)2 is the generating function for the sequence 0,1,2,3,….
2,3, 4…: We have
1 1
= 1 + 2𝑥 + 3𝑥 + ⋯
=1+𝑥+𝑥 +𝑥 +⋯ (1 − 𝑥)
(1 − 𝑥)
 = 𝑥(1 + 2𝑥 + 3𝑥 + ⋯ )
( )
 = 1+𝑥+𝑥 +𝑥 +⋯
= 0x0 + x1 + 2x2 + 3x3+….
( )
= 1 + 2𝑥 + 3𝑥 + ⋯
Ex6: Show that (x+1)/(1-x)3 is the generating function for the sequence 12,22,32,42,….
 1/(1-x)2is the generating function for the sequence 1,2,3,4,…. From Ex5 we have:
Ex5: Show that x/(1-x)2 is the generating function for the sequence 0,1,2,3,…. 𝑥
= 𝑥 + 2𝑥 + 3𝑥 + ⋯
We have (1 − 𝑥)
1
= 1 + 2𝑥 + 3𝑥 + ⋯  = 𝑥 + 2𝑥 + 3𝑥 + ⋯
( )
(1 − 𝑥)
 ( ) = 𝑥(1 + 2𝑥 + 3𝑥 + ⋯ )  =1+2 𝑥+3 𝑥 +⋯
( )

= 0x0 + x1 + 2x2 + 3x3+….


185 186

2.5.2. Generating functions 2.5.2. Generating functions


Ex6: Show that (x+1)/(1-x)3 is the generating function for the sequence 12,22,32,42,…. Generating functions are a tool to solve a wide variety of counting problems and
From Ex5 we have: recurrence relations.
𝑥
= 𝑥 + 2𝑥 + 3𝑥 + ⋯ Definition: Let a0, a1, a2, … be a sequence of real numbers. The function
(1 − 𝑥) 
g ( x )  a0  a1 x  ...  ak x k  ...   ai xi
 = 𝑥 + 2𝑥 + 3𝑥 + ⋯ i 0
( )
is called the generating function for the given sequence.
 =1+2 𝑥+3 𝑥 +⋯
( ) Example 1: Solve the recurrence relation an-3an-1 = n, n1, a0=1
Let 𝑔 𝑥 = 𝑎 𝑥 be the generating function for a0, a1,…, an
Ex7: Show that x(x+1)/(1-x)3 is the generating function for the sequence 02, 12, 22, 32,
42, ….
𝑎 𝑥 −3 𝑎 𝑥 = 𝑛𝑥

𝑔 𝑥 −𝑎 −3𝑥 𝑎 𝑥
= 𝑥 + 2𝑥 + 3𝑥 + ⋯

𝑔 𝑥 −1 − 3𝑥𝑔(𝑥) = 𝑥 + 2𝑥 + 3𝑥 + ⋯

187 Remember that (see Ex5) = 𝑥 + 2𝑥 + 3𝑥 + ⋯ 188


( )
2.5.2. Generating functions 2.5.2. Generating functions
Example 1: Solve the recurrence relation an-3an-1 = n, n1, a0=1 Example 1: Solve the recurrence relation an-3an-1 = n, n1, a0=1
𝑥
𝑔 𝑥 − 1 − 3𝑥𝑔(𝑥) = 7/4 −1/4 −1/2
(1 − 𝑥) 𝑔 𝑥 = + +
(1 − 3𝑥) (1 − 𝑥) (1 − 𝑥)
1 𝑥
𝑔 𝑥 = + We find an by determining the coefficient of xn in each of the three summands
1 − 3𝑥 (1 − 3𝑥)(1 − 𝑥)
1. (7/4)/(1-3x) = (7/4) [1/(1-3x)]
1 𝐴 𝐵 𝐶 See Ex3.
𝑔 𝑥 = + + + = (7/4) [1 + 3x + (3x)2 + (3x)3+….]
1 − 3𝑥 (1 − 3𝑥) (1 − 𝑥) (1 − 𝑥)
 The coefficient of xn is (7/4)3n
3 1 1
⇒𝐴= ;𝐵 = − ;𝐶 = − ; 2. (-1/4)/(1-x) = (-1/4) [1/(1-x)]
4 4 2 See Ex2.
= (-1/4) [1 + x + (x)2 + (x)3+….]
1 3/4 −1/4 −1/2
𝑔 𝑥 = + + +  The coefficient of xn is (-1/4)
1 − 3𝑥 (1 − 3𝑥) (1 − 𝑥) (1 − 𝑥)
3. (-1/2)/(1-x)2 = (-1/2) [1/(1-x)2]
7/4 −1/4 −1/2 = (-1/2) [1 + 2x + 3(x)2 + 4(x)3+….] See Ex4.
𝑔 𝑥 = + + 
(1 − 3𝑥) (1 − 𝑥) (1 − 𝑥)
g ( x)  a0  a1 x  ...  ak x  ...   ai x
k i
 The coefficient of xn is (-1/2)(n+1)
i 0
We find an by determining the coefficient of xn in g(x) Therefore, an = (7/4) 3n – (1/2)n -3/4, n ≥ 0
 determining the coefficient of xn in each of the three summands 189 190

2.5.2. Generating functions 2.5.2. Generating functions


Example 2: Tower of Hanoi Example 2: Tower of Hanoi
Solve the recurrence relation an = 2 an−1 + 1, n1, a0=0 Solve the recurrence relation an = 2 an−1 + 1, n1, a0=0
Let 𝑔 𝑥 = 𝑎 𝑥 be the generating function for a0, a1,…, an
(1 − 2𝑥)𝑔(𝑥) = (1 + 𝑥 + 𝑥 + 𝑥 + ⋯)-1

Remember that (see Ex2) =1+𝑥+𝑥 +𝑥 +⋯


( )
𝑎 𝑥 =2 𝑎 𝑥 + 𝑥
(1 − 2𝑥)𝑔(𝑥) = ( )
-1=
𝑔 𝑥 −𝑎 = 2𝑥 𝑎 𝑥 +( 𝑥 ) −𝑥 𝑥
𝑔(𝑥) =
(1 − 2𝑥)(1 − 𝑥)
𝑔 𝑥 − 0 = 2𝑥𝑔(𝑥) +(1 + 𝑥 + 𝑥 + 𝑥 + ⋯)-1
𝐴 𝐵
(1 − 2𝑥)𝑔(𝑥) = (1 + 𝑥 + 𝑥 + 𝑥 + ⋯)-1 𝑔 𝑥 = + ⇒ 𝐴 = 1; 𝐵 = −1
(1 − 2𝑥) (1 − 𝑥)
Remember that (see Ex2) =1+𝑥+𝑥 +𝑥 +⋯
( )
191 192
2.5.2. Generating functions 2.5.2. Generating functions
Example 2: Tower of Hanoi Example 3: Solve the recursive relation an+2-5an+1+6an=2, n0, a0=3, a1=7
Solve the recurrence relation an = 2 an−1 + 1, n1, a0=0 Let 𝑔 𝑥 = 𝑎 𝑥 be the generating function for a0, a1,…, an
1 (−1)
𝑔 𝑥 = +
(1 − 2𝑥) (1 − 𝑥) 𝑎 𝑥 −5 𝑎 𝑥 +6 𝑎 𝑥 =2 𝑥
We find an by determining the coefficient of xn in each of the two summands
1. (1)/(1-2x) = (1) [1/(1-2x)] See Ex3.
= (1) [1 + 2x + (2x)2 + (2x)3+….] 𝑎 𝑥 − 5𝑥 𝑎 𝑥 + 6𝑥 𝑎 𝑥 = 2𝑥 𝑥
The coefficient of xn is (1)2n
2. (-1)/(1-x) = (-1) [1/(1-x)]
See Ex2. 1
= (-1) [1 + x + (x)2 + (x)3+….] 𝑔 𝑥 −𝑎 𝑥−𝑎 −5𝑥[𝑔 𝑥 − 𝑎 ] +6𝑥 [𝑔 𝑥 ] = 2𝑥
The coefficient of xn is (-1) 1−𝑥
Therefore, an = 2n -1, n ≥ 0
2𝑥 3 − 11𝑥 + 10𝑥
1 − 5𝑥 + 6𝑥 𝑔 𝑥 = 3 − 8𝑥 + =
1−𝑥 1−𝑥
193 194

2.5.2. Generating functions


Example 3: Solve the recursive relation an+2-5an+1+6an=2, n0, a0=3, a1=7
Let 𝑔 𝑥 = 𝑎 𝑥 be the generating function for a0, a1,…, an

2𝑥 3 − 11𝑥 + 10𝑥
1 − 5𝑥 + 6𝑥 𝑔 𝑥 = 3 − 8𝑥 + =
1−𝑥 1−𝑥
3 − 11𝑥 + 10𝑥 (3 − 5𝑥)(1 − 2𝑥) (3 − 5𝑥)
𝑔 𝑥 = = =
(1 − 𝑥) 1 − 5𝑥 + 6𝑥 (1 − 𝑥)(1 − 3𝑥)(1 − 2𝑥) (1 − 𝑥)(1 − 3𝑥)

(3 − 5𝑥) 𝐴 𝐵
𝑔 𝑥 = = + ⇒ 𝐴 = 1; 𝐵 = 2
(1 − 𝑥)(1 − 3𝑥) (1 − 𝑥) (1 − 3𝑥)

1 2
𝑔 𝑥 = + =2 (3𝑥) + (𝑥)
(1 − 𝑥) (1 − 3𝑥)

Therefore, an =2(3n)+1, n ≥ 0 195

You might also like