discrete mathematics and its applications -...

124
Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques: Recurrence Relation MING GAO DaSE@ ECNU (for course related communications) [email protected] Nov. 23, 2017

Upload: phamhuong

Post on 09-Sep-2018

228 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Discrete Mathematics and Its ApplicationsLecture 4: Advanced Counting Techniques: Recurrence Relation

MING GAO

DaSE@ ECNU(for course related communications)

[email protected]

Nov. 23, 2017

Page 2: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Outline

1 Applications of Recurrence Relations

2 Algorithms and Recurrence Relations

3 Solving Linear Recurrence RelationsSolving LHR2 with Constant CoefficientsSolving LNR2 with Constant Coefficients

4 Take-aways

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 2 / 53

Page 3: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Applications of Recurrence Relations

The Fibonacci sequence

Source:

https://en.wikipedia.org/wiki/

File:Fibonacci.jpg

In 1202, Leonardo Bonacci (known as Fibonacci)asked the following question.

“Assuming that: a newly born pair of rabbits, onemale, one female, are put in an island; rabbits are ableto mate at the age of one month so that at the endof its second month a female can produce another pairof rabbits; rabbits never die and a mating pair alwaysproduces one new pair (one male, one female) everymonth from the second month on.”

“The puzzle that Fibonacci posed was: how many pairs

will there be in one year?”

From https://en.wikipedia.org/wiki/Fibonacci number

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 3 / 53

Page 4: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Applications of Recurrence Relations

Let’s try to solve Fibonacci’s question.

Let ♠ denote a newly born rabit pair, and ♥ denote a mature rabit pair.Month Rabits

1 ♠ 12 ♥ 13 ♥ ♠ 24 ♥ ♥ ♠ 35 ♥ ♥ ♥ ♠ ♠ 56 ♥ ♥ ♥ ♥ ♥ ♠ ♠ ♠ 87 ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♠ ♠ ♠ ♠ ♠ 13

How many rabit pairs do we have at the beginning of the 8th month?

Surely all 13 rabit pairs we have in the 7th month remain there and are allmature. So, the question is how many newly born rabbit pairs that we have.

The number of newly born rabbit pairs equals the number of mature rabbitpairs we have. This is also equal to the number of rabit pairs that we havein the 6th month: 8.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 4 / 53

Page 5: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Applications of Recurrence Relations

Let’s try to solve Fibonacci’s question.Let ♠ denote a newly born rabit pair, and ♥ denote a mature rabit pair.

Month Rabits

1 ♠ 1

2 ♥ 13 ♥ ♠ 24 ♥ ♥ ♠ 35 ♥ ♥ ♥ ♠ ♠ 56 ♥ ♥ ♥ ♥ ♥ ♠ ♠ ♠ 87 ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♠ ♠ ♠ ♠ ♠ 13

How many rabit pairs do we have at the beginning of the 8th month?

Surely all 13 rabit pairs we have in the 7th month remain there and are allmature. So, the question is how many newly born rabbit pairs that we have.

The number of newly born rabbit pairs equals the number of mature rabbitpairs we have. This is also equal to the number of rabit pairs that we havein the 6th month: 8.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 4 / 53

Page 6: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Applications of Recurrence Relations

Let’s try to solve Fibonacci’s question.Let ♠ denote a newly born rabit pair, and ♥ denote a mature rabit pair.

Month Rabits

1 ♠ 12 ♥ 1

3 ♥ ♠ 24 ♥ ♥ ♠ 35 ♥ ♥ ♥ ♠ ♠ 56 ♥ ♥ ♥ ♥ ♥ ♠ ♠ ♠ 87 ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♠ ♠ ♠ ♠ ♠ 13

How many rabit pairs do we have at the beginning of the 8th month?

Surely all 13 rabit pairs we have in the 7th month remain there and are allmature. So, the question is how many newly born rabbit pairs that we have.

The number of newly born rabbit pairs equals the number of mature rabbitpairs we have. This is also equal to the number of rabit pairs that we havein the 6th month: 8.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 4 / 53

Page 7: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Applications of Recurrence Relations

Let’s try to solve Fibonacci’s question.Let ♠ denote a newly born rabit pair, and ♥ denote a mature rabit pair.

Month Rabits

1 ♠ 12 ♥ 13 ♥

♠ 24 ♥ ♥ ♠ 35 ♥ ♥ ♥ ♠ ♠ 56 ♥ ♥ ♥ ♥ ♥ ♠ ♠ ♠ 87 ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♠ ♠ ♠ ♠ ♠ 13

How many rabit pairs do we have at the beginning of the 8th month?

Surely all 13 rabit pairs we have in the 7th month remain there and are allmature. So, the question is how many newly born rabbit pairs that we have.

The number of newly born rabbit pairs equals the number of mature rabbitpairs we have. This is also equal to the number of rabit pairs that we havein the 6th month: 8.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 4 / 53

Page 8: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Applications of Recurrence Relations

Let’s try to solve Fibonacci’s question.Let ♠ denote a newly born rabit pair, and ♥ denote a mature rabit pair.

Month Rabits

1 ♠ 12 ♥ 13 ♥ ♠ 2

4 ♥ ♥ ♠ 35 ♥ ♥ ♥ ♠ ♠ 56 ♥ ♥ ♥ ♥ ♥ ♠ ♠ ♠ 87 ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♠ ♠ ♠ ♠ ♠ 13

How many rabit pairs do we have at the beginning of the 8th month?

Surely all 13 rabit pairs we have in the 7th month remain there and are allmature. So, the question is how many newly born rabbit pairs that we have.

The number of newly born rabbit pairs equals the number of mature rabbitpairs we have. This is also equal to the number of rabit pairs that we havein the 6th month: 8.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 4 / 53

Page 9: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Applications of Recurrence Relations

Let’s try to solve Fibonacci’s question.Let ♠ denote a newly born rabit pair, and ♥ denote a mature rabit pair.

Month Rabits

1 ♠ 12 ♥ 13 ♥ ♠ 24 ♥ ♥

♠ 35 ♥ ♥ ♥ ♠ ♠ 56 ♥ ♥ ♥ ♥ ♥ ♠ ♠ ♠ 87 ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♠ ♠ ♠ ♠ ♠ 13

How many rabit pairs do we have at the beginning of the 8th month?

Surely all 13 rabit pairs we have in the 7th month remain there and are allmature. So, the question is how many newly born rabbit pairs that we have.

The number of newly born rabbit pairs equals the number of mature rabbitpairs we have. This is also equal to the number of rabit pairs that we havein the 6th month: 8.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 4 / 53

Page 10: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Applications of Recurrence Relations

Let’s try to solve Fibonacci’s question.Let ♠ denote a newly born rabit pair, and ♥ denote a mature rabit pair.

Month Rabits

1 ♠ 12 ♥ 13 ♥ ♠ 24 ♥ ♥ ♠ 3

5 ♥ ♥ ♥ ♠ ♠ 56 ♥ ♥ ♥ ♥ ♥ ♠ ♠ ♠ 87 ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♠ ♠ ♠ ♠ ♠ 13

How many rabit pairs do we have at the beginning of the 8th month?

Surely all 13 rabit pairs we have in the 7th month remain there and are allmature. So, the question is how many newly born rabbit pairs that we have.

The number of newly born rabbit pairs equals the number of mature rabbitpairs we have. This is also equal to the number of rabit pairs that we havein the 6th month: 8.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 4 / 53

Page 11: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Applications of Recurrence Relations

Let’s try to solve Fibonacci’s question.Let ♠ denote a newly born rabit pair, and ♥ denote a mature rabit pair.

Month Rabits

1 ♠ 12 ♥ 13 ♥ ♠ 24 ♥ ♥ ♠ 35 ♥ ♥ ♥

♠ ♠ 56 ♥ ♥ ♥ ♥ ♥ ♠ ♠ ♠ 87 ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♠ ♠ ♠ ♠ ♠ 13

How many rabit pairs do we have at the beginning of the 8th month?

Surely all 13 rabit pairs we have in the 7th month remain there and are allmature. So, the question is how many newly born rabbit pairs that we have.

The number of newly born rabbit pairs equals the number of mature rabbitpairs we have. This is also equal to the number of rabit pairs that we havein the 6th month: 8.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 4 / 53

Page 12: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Applications of Recurrence Relations

Let’s try to solve Fibonacci’s question.Let ♠ denote a newly born rabit pair, and ♥ denote a mature rabit pair.

Month Rabits

1 ♠ 12 ♥ 13 ♥ ♠ 24 ♥ ♥ ♠ 35 ♥ ♥ ♥ ♠ ♠ 5

6 ♥ ♥ ♥ ♥ ♥ ♠ ♠ ♠ 87 ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♠ ♠ ♠ ♠ ♠ 13

How many rabit pairs do we have at the beginning of the 8th month?

Surely all 13 rabit pairs we have in the 7th month remain there and are allmature. So, the question is how many newly born rabbit pairs that we have.

The number of newly born rabbit pairs equals the number of mature rabbitpairs we have. This is also equal to the number of rabit pairs that we havein the 6th month: 8.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 4 / 53

Page 13: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Applications of Recurrence Relations

Let’s try to solve Fibonacci’s question.Let ♠ denote a newly born rabit pair, and ♥ denote a mature rabit pair.

Month Rabits

1 ♠ 12 ♥ 13 ♥ ♠ 24 ♥ ♥ ♠ 35 ♥ ♥ ♥ ♠ ♠ 56 ♥ ♥ ♥ ♥ ♥

♠ ♠ ♠ 87 ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♠ ♠ ♠ ♠ ♠ 13

How many rabit pairs do we have at the beginning of the 8th month?

Surely all 13 rabit pairs we have in the 7th month remain there and are allmature. So, the question is how many newly born rabbit pairs that we have.

The number of newly born rabbit pairs equals the number of mature rabbitpairs we have. This is also equal to the number of rabit pairs that we havein the 6th month: 8.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 4 / 53

Page 14: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Applications of Recurrence Relations

Let’s try to solve Fibonacci’s question.Let ♠ denote a newly born rabit pair, and ♥ denote a mature rabit pair.

Month Rabits

1 ♠ 12 ♥ 13 ♥ ♠ 24 ♥ ♥ ♠ 35 ♥ ♥ ♥ ♠ ♠ 56 ♥ ♥ ♥ ♥ ♥ ♠ ♠ ♠ 8

7 ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♠ ♠ ♠ ♠ ♠ 13

How many rabit pairs do we have at the beginning of the 8th month?

Surely all 13 rabit pairs we have in the 7th month remain there and are allmature. So, the question is how many newly born rabbit pairs that we have.

The number of newly born rabbit pairs equals the number of mature rabbitpairs we have. This is also equal to the number of rabit pairs that we havein the 6th month: 8.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 4 / 53

Page 15: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Applications of Recurrence Relations

Let’s try to solve Fibonacci’s question.Let ♠ denote a newly born rabit pair, and ♥ denote a mature rabit pair.

Month Rabits

1 ♠ 12 ♥ 13 ♥ ♠ 24 ♥ ♥ ♠ 35 ♥ ♥ ♥ ♠ ♠ 56 ♥ ♥ ♥ ♥ ♥ ♠ ♠ ♠ 87 ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♥

♠ ♠ ♠ ♠ ♠ 13

How many rabit pairs do we have at the beginning of the 8th month?

Surely all 13 rabit pairs we have in the 7th month remain there and are allmature. So, the question is how many newly born rabbit pairs that we have.

The number of newly born rabbit pairs equals the number of mature rabbitpairs we have. This is also equal to the number of rabit pairs that we havein the 6th month: 8.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 4 / 53

Page 16: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Applications of Recurrence Relations

Let’s try to solve Fibonacci’s question.Let ♠ denote a newly born rabit pair, and ♥ denote a mature rabit pair.

Month Rabits

1 ♠ 12 ♥ 13 ♥ ♠ 24 ♥ ♥ ♠ 35 ♥ ♥ ♥ ♠ ♠ 56 ♥ ♥ ♥ ♥ ♥ ♠ ♠ ♠ 87 ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♠ ♠ ♠ ♠ ♠ 13

How many rabit pairs do we have at the beginning of the 8th month?

Surely all 13 rabit pairs we have in the 7th month remain there and are allmature. So, the question is how many newly born rabbit pairs that we have.

The number of newly born rabbit pairs equals the number of mature rabbitpairs we have. This is also equal to the number of rabit pairs that we havein the 6th month: 8.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 4 / 53

Page 17: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Applications of Recurrence Relations

Let’s try to solve Fibonacci’s question.Let ♠ denote a newly born rabit pair, and ♥ denote a mature rabit pair.

Month Rabits

1 ♠ 12 ♥ 13 ♥ ♠ 24 ♥ ♥ ♠ 35 ♥ ♥ ♥ ♠ ♠ 56 ♥ ♥ ♥ ♥ ♥ ♠ ♠ ♠ 87 ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♠ ♠ ♠ ♠ ♠ 13

How many rabit pairs do we have at the beginning of the 8th month?

Surely all 13 rabit pairs we have in the 7th month remain there and are allmature. So, the question is how many newly born rabbit pairs that we have.

The number of newly born rabbit pairs equals the number of mature rabbitpairs we have. This is also equal to the number of rabit pairs that we havein the 6th month: 8.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 4 / 53

Page 18: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Applications of Recurrence Relations

Let’s try to solve Fibonacci’s question.Let ♠ denote a newly born rabit pair, and ♥ denote a mature rabit pair.

Month Rabits

1 ♠ 12 ♥ 13 ♥ ♠ 24 ♥ ♥ ♠ 35 ♥ ♥ ♥ ♠ ♠ 56 ♥ ♥ ♥ ♥ ♥ ♠ ♠ ♠ 87 ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♠ ♠ ♠ ♠ ♠ 13

How many rabit pairs do we have at the beginning of the 8th month?

Surely all 13 rabit pairs we have in the 7th month remain there and are allmature. So, the question is how many newly born rabbit pairs that we have.

The number of newly born rabbit pairs equals the number of mature rabbitpairs we have. This is also equal to the number of rabit pairs that we havein the 6th month: 8.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 4 / 53

Page 19: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Applications of Recurrence Relations

Let’s try to solve Fibonacci’s question.Let ♠ denote a newly born rabit pair, and ♥ denote a mature rabit pair.

Month Rabits

1 ♠ 12 ♥ 13 ♥ ♠ 24 ♥ ♥ ♠ 35 ♥ ♥ ♥ ♠ ♠ 56 ♥ ♥ ♥ ♥ ♥ ♠ ♠ ♠ 87 ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♠ ♠ ♠ ♠ ♠ 13

How many rabit pairs do we have at the beginning of the 8th month?

Surely all 13 rabit pairs we have in the 7th month remain there and are allmature. So, the question is how many newly born rabbit pairs that we have.

The number of newly born rabbit pairs equals the number of mature rabbitpairs we have.

This is also equal to the number of rabit pairs that we havein the 6th month: 8.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 4 / 53

Page 20: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Applications of Recurrence Relations

Let’s try to solve Fibonacci’s question.Let ♠ denote a newly born rabit pair, and ♥ denote a mature rabit pair.

Month Rabits

1 ♠ 12 ♥ 13 ♥ ♠ 24 ♥ ♥ ♠ 35 ♥ ♥ ♥ ♠ ♠ 56 ♥ ♥ ♥ ♥ ♥ ♠ ♠ ♠ 87 ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♠ ♠ ♠ ♠ ♠ 13

How many rabit pairs do we have at the beginning of the 8th month?

Surely all 13 rabit pairs we have in the 7th month remain there and are allmature. So, the question is how many newly born rabbit pairs that we have.

The number of newly born rabbit pairs equals the number of mature rabbitpairs we have. This is also equal to the number of rabit pairs that we havein the 6th month: 8.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 4 / 53

Page 21: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Applications of Recurrence Relations

Thus, we will have 13+8 rabit pairs at the beginning of the 8th month.

If we write down the sequence, we get the Fibonacci sequence:

1, 1, 2, 3, 5, 8, 13, 21, . . .

Again, what’s the next number in this sequence? How can you compute it?21+13 = 34 is the answer. You take the last two numbers and add themup to get the next number. Why?

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 5 / 53

Page 22: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Applications of Recurrence Relations

Thus, we will have 13+8 rabit pairs at the beginning of the 8th month.If we write down the sequence, we get the Fibonacci sequence:

1, 1, 2, 3, 5, 8, 13, 21, . . .

Again, what’s the next number in this sequence? How can you compute it?21+13 = 34 is the answer. You take the last two numbers and add themup to get the next number. Why?

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 5 / 53

Page 23: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Applications of Recurrence Relations

Thus, we will have 13+8 rabit pairs at the beginning of the 8th month.If we write down the sequence, we get the Fibonacci sequence:

1, 1, 2, 3, 5, 8, 13, 21, . . .

Again, what’s the next number in this sequence? How can you compute it?

21+13 = 34 is the answer. You take the last two numbers and add themup to get the next number. Why?

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 5 / 53

Page 24: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Applications of Recurrence Relations

Thus, we will have 13+8 rabit pairs at the beginning of the 8th month.If we write down the sequence, we get the Fibonacci sequence:

1, 1, 2, 3, 5, 8, 13, 21, . . .

Again, what’s the next number in this sequence? How can you compute it?21+13 = 34 is the answer.

You take the last two numbers and add themup to get the next number. Why?

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 5 / 53

Page 25: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Applications of Recurrence Relations

Thus, we will have 13+8 rabit pairs at the beginning of the 8th month.If we write down the sequence, we get the Fibonacci sequence:

1, 1, 2, 3, 5, 8, 13, 21, . . .

Again, what’s the next number in this sequence? How can you compute it?21+13 = 34 is the answer. You take the last two numbers and add themup to get the next number. Why?

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 5 / 53

Page 26: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Applications of Recurrence Relations

To be precise, let Fn be the n-th number in the Fibonacci sequence. (Thatis, F1 = 1,F2 = 1,F3 = 2,F4 = 3 and so on.) We can define the(n + 1)-th number as

Fn+1 = Fn + Fn−1,

for n = 2, 3, . . ..

Is this enough to completely specify the sequence?No, because we do not know how to start. To get the Fibonacci sequence,we need to specify two starting values: F1 = 1 and F2 = 1 as well.Now, you can see that the equation and these special values uniquelydetermine the sequence. It is also convenient to define F0 = 0 so that theequation works for n = 1.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 6 / 53

Page 27: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Applications of Recurrence Relations

To be precise, let Fn be the n-th number in the Fibonacci sequence. (Thatis, F1 = 1,F2 = 1,F3 = 2,F4 = 3 and so on.) We can define the(n + 1)-th number as

Fn+1 = Fn + Fn−1,

for n = 2, 3, . . .. Is this enough to completely specify the sequence?

No, because we do not know how to start. To get the Fibonacci sequence,we need to specify two starting values: F1 = 1 and F2 = 1 as well.Now, you can see that the equation and these special values uniquelydetermine the sequence. It is also convenient to define F0 = 0 so that theequation works for n = 1.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 6 / 53

Page 28: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Applications of Recurrence Relations

To be precise, let Fn be the n-th number in the Fibonacci sequence. (Thatis, F1 = 1,F2 = 1,F3 = 2,F4 = 3 and so on.) We can define the(n + 1)-th number as

Fn+1 = Fn + Fn−1,

for n = 2, 3, . . .. Is this enough to completely specify the sequence?No, because we do not know how to start. To get the Fibonacci sequence,we need to specify two starting values: F1 = 1 and F2 = 1 as well.Now, you can see that the equation and these special values uniquelydetermine the sequence. It is also convenient to define F0 = 0 so that theequation works for n = 1.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 6 / 53

Page 29: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Applications of Recurrence Relations

A recurrence

The equationFn+1 = Fn + Fn−1

and the initial values F0 = 0 and F1 = 1 specify all values of the Fibonaccisequence. With these two initial values, you can use the equation to findthe value of any number in the sequence.This definition is called a recurrence. Instead of defining the value ofeach number in the sequence explicitly, we do so by using the values ofother numbers in the sequence.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 7 / 53

Page 30: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Applications of Recurrence Relations

Tilings with 1x1 and 2x1 tiles

You have a walk way of length n units. The width of the walk way is 1unit. You have unlimited supplies of 1x1 tiles and 2x1 tiles. Every tile ofthe same size is indistinguishable. In how many ways can you tile the walkway?Let’s consider small cases.

When n = 1, there are 1 way.

When n = 2, there are 2 ways.

When n = 3, there are 3 ways.

When n = 4, there are 5 ways.

Let’s define Jn to be the number of ways you can tile a walk way of lengthn. From the example above, we know that J1 = 1 and J2 = 2.Can you find a formula for general Jn?

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 8 / 53

Page 31: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Applications of Recurrence Relations

Figuring out the recurrence for Jn

To figure out the general formula for Jn, we can think about the firstchoice we can make when tiling a walk way of length n. There are twochoices:

(1) We can start placing a 1x1 tile at the beginning, or

(2) We can start placing a 2x1 tile at the beginning.

In each of the cases, let’s think about how many ways we can tile the restof the walk way, provided that the first step is made.

Note that if we start by placing a 1x1 tile, we are left with a walk way oflength n − 1. From the definition of Jn, we know that there are Jn−1 waysto tile the rest of the walk way of length n− 1. Using similar reasoning, weknow that if we start with a 2x1 tile, there are Jn−2 ways to tile the rest ofthe walk way.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 9 / 53

Page 32: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Applications of Recurrence Relations

The recurrence for Jn

From the discussion, we have that

Jn = Jn−1 + Jn−2,

where J1 = 1 and J2 = 2.

Note that this is exactly the same recurrence as the Fibonacci sequence,but with different initial values. In fact, we have that

Jn = Fn+1.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 10 / 53

Page 33: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Applications of Recurrence Relations

The number of bit strings

Question: Find a recurrence relation and give initial conditions forthe number of bit strings of length n that do not have two consecutive0s. How many such bit strings are there of length five?

Solution: Let an denote the number of bit strings of length n thatdo not have two consecutive 0s.Note that a1 = 2, a2 = 3. Assume that n ≥ 3, we have

Way # bit strings1: ending with 1 an−1

2: ending with 10 an−2

We conclude thatan = an−1 + an−2

for n ≥ 3.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 11 / 53

Page 34: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Applications of Recurrence Relations

The number of bit strings

Question: Find a recurrence relation and give initial conditions forthe number of bit strings of length n that do not have two consecutive0s. How many such bit strings are there of length five?Solution: Let an denote the number of bit strings of length n thatdo not have two consecutive 0s.

Note that a1 = 2, a2 = 3. Assume that n ≥ 3, we haveWay # bit strings1: ending with 1 an−1

2: ending with 10 an−2

We conclude thatan = an−1 + an−2

for n ≥ 3.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 11 / 53

Page 35: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Applications of Recurrence Relations

The number of bit strings

Question: Find a recurrence relation and give initial conditions forthe number of bit strings of length n that do not have two consecutive0s. How many such bit strings are there of length five?Solution: Let an denote the number of bit strings of length n thatdo not have two consecutive 0s.Note that a1 = 2, a2 = 3. Assume that n ≥ 3, we have

Way # bit strings1: ending with 1 an−1

2: ending with 10 an−2

We conclude thatan = an−1 + an−2

for n ≥ 3.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 11 / 53

Page 36: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Applications of Recurrence Relations

The number of bit strings

Question: Find a recurrence relation and give initial conditions forthe number of bit strings of length n that do not have two consecutive0s. How many such bit strings are there of length five?Solution: Let an denote the number of bit strings of length n thatdo not have two consecutive 0s.Note that a1 = 2, a2 = 3. Assume that n ≥ 3, we have

Way # bit strings1: ending with 1 an−1

2: ending with 10 an−2

We conclude thatan = an−1 + an−2

for n ≥ 3.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 11 / 53

Page 37: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Applications of Recurrence Relations

Identities on Fibonacci numbers

There are a lot of identities related to Fibonacci numbers. Let’s see thefirst few values in the sequence:

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, . . .

Now, let’s add the first few numbers:

0 + 1 = 1

0 + 1 + 1 = 2

0 + 1 + 1 + 2 = 4

0 + 1 + 1 + 2 + 3 = 7

0 + 1 + 1 + 2 + 3 + 5 = 12

0 + 1 + 1 + 2 + 3 + 5 + 8 = 20

0 + 1 + 1 + 2 + 3 + 5 + 8 + 13 = 33

From this we can formulate the following conjecture:

F0 + F1 + · · ·+ Fn = Fn+2 − 1.MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 12 / 53

Page 38: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Applications of Recurrence Relations

Theorem: For n ≥ 0, we have that

F0 + F1 + · · ·+ Fn = Fn+2 − 1.

Proof: We shall prove by induction on n. The base case has already beendemonstrated when we consider small values of n.

Inductive Step: Let’s assume that the statement is true for n = k , fork ≥ 0, i.e., assume that

F0 + F1 + · · ·+ Fk = Fk+2 − 1.

We shall prove that the statement is true when n = k + 1. This is nothard to show. We write

(F0 + F1 + · · ·+ Fk) + Fk+1 = (Fk+2 − 1) + Fk+1

= Fk+3 − 1,

as required. Note that the first step follows from the induction hypothesis.�

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 13 / 53

Page 39: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Applications of Recurrence Relations

Another harder identity

The following identity is harder to prove:

F 2n + F 2

n−1 = F2n−1.

Let’s try a few values as a sanity check.

F 21 + F 2

2 = 12 + 12 = 2 = F3

F 22 + F 2

3 = 12 + 22 = 5 = F5

F 23 + F 2

4 = 22 + 32 = 13 = F7

To see how hard it is to prove the identity, let’s try to prove it byinduction. (Let’s jump to the inductive step.)

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 14 / 53

Page 40: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Applications of Recurrence Relations

We use strong induction. Assume that the statement is true forn = k , k − 1, k − 2, . . . , 0. We prove the statement for n = k + 1.

Let’s work on the left hand side.

F 2k+1 + F 2

k = (Fk + Fk−1)2 + (Fk−1 + Fk−2)2

= F 2k + 2FkFk−1 + F 2

k−1 + F 2k−1 + 2Fk−1Fk−2 + F 2

k−2

= (F 2k + F 2

k−1) + 2FkFk−1 + (F 2k−1 + F 2

k−2) + 2Fk−1Fk−2

= F2k−1 + F2k−3 + 2FkFk−1 + 2Fk−1Fk−2,

where the last step follows from the induction hypothesis.

Note that we end up with the terms like: FkFk−1 + Fk−1Fk−2. We cankeep expanding the terms, but we will end up with the same cross termslike this.

So, let’s take a look at a few values of this expression. Maybe we canguess its values.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 15 / 53

Page 41: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Applications of Recurrence Relations

Let’s plug in a few values:

F3F2 + F2F1 = 2 · 1 + 1 · 1 = 3 = F4

F4F3 + F3F2 = 3 · 2 + 2 · 1 = 8 = F6

F5F4 + F4F3 = 5 · 3 + 3 · 2 = 21 = F8

F6F5 + F5F4 = 8 · 5 + 5 · 3 = 55 = F10

From this, we can make another conjecture:

Conjecture 2:Fn+1Fn + FnFn−1 = F2n.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 16 / 53

Page 42: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Applications of Recurrence Relations

Let’s assume that Conjecture 2 is true and see if we can prove the identitythat we want.Recall that we have

F 2k+1 + F 2

k = F2k−1 + F2k−3 + 2FkFk−1 + 2Fk−1Fk−2

= F2k−1 + F2k−3 + 2(FkFk−1 + Fk−1Fk−2)

= F2k−1 + F2k−3 + 2F2k−2 (from Conj 2)

= (F2k−1 + F2k−2) + (F2k−2 + F2k−3)

= F2k + F2k−1

= F2k+1,

as required. We use Conjecture 2 to show the second step.

This means that assuming the Conjecture 2, we can show the identityF 2n + F 2

n−1 = F2n−1.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 17 / 53

Page 43: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Applications of Recurrence Relations

Let’s prove Conjecture 2

Conjecture 2: Fn+1Fn + FnFn−1 = F2n.Proof: Let’s do so by induction. Since we have plugged in many smallvalues, we can only consider the inductive step now. Assume that thestatement is true for n = k , k − 1, k − 2, . . . , 0. We prove the statementfor n = k + 1. We write

Fk+2Fk+1 + Fk+1Fk = (Fk+1 + Fk)Fk+1 + (Fk + Fk−1)Fk

= F 2k+1 + FkFk+1 + F 2

k + Fk−1Fk

= (FkFk+1 + Fk−1Fk) + F 2k+1 + F 2

k = F2k + F 2k+1 + F 2

k .

(Note that the 4th step uses the induction hypothesis.) Do you see anyfamiliar terms?

Yes, the terms F 2k+1 + F 2

k is the left hand side of the identity we have justproven. Actually, we cannot use it directly here, because we useConjecture 2 to prove it and now we are trying to prove the conjectureitself. Using it results in a circular reasoning.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 18 / 53

Page 44: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Applications of Recurrence Relations

We can actually prove the conjecture using that identity, but we first haveto break our circular reasoning by proving both statements together.Formally, let’s define predicates P and Q:

P(n) : F 2n + F 2

n−1 = F2n−1

Q(n) : Fn+1Fn + FnFn−1 = F2n

We will prove that for all integer n ≥ 0, P(n) ∧ Q(n).Base Case: We have shown that P(1) and Q(1) are true.Inductive Step: Assume that the statements are true forn = k, k − 1, . . . , 1 for k ≥ 1. We will prove P(k + 1) ∧ Q(k + 1).

P(k + 1) can be proved as in the proof of the identity previously.

To prove Q(k + 1), we can use the induction hypotheses and alsoP(k + 1).

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 19 / 53

Page 45: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Applications of Recurrence Relations

Simultaneous induction

Let’s prove Q(k + 1). We can continue from our “broken” proof. We havethat

Fk+2Fk+1 + Fk+1Fk = F2k + (F 2k+1 + F 2

k )

= F2k + F2k+1 = F2k+2,

as required. Note that the second step uses P(k + 1). �

The technique we use to prove P and Q together is called simultaneousinduction.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 20 / 53

Page 46: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Applications of Recurrence Relations

The Tower of Hanoi problem

Source: https://en.wikipedia.org/wiki/

File:Fibonacci.jpg

In 1883, French mathematician E douardLucas asked the following question (calledthe Tower of Hanoi).

The puzzle consists of three pegs mounted on

a board together with disks of different sizes.

Initially these disks are placed on the first peg

in order of size, with the largest on the bottom

(as shown in Figure). The rules of the puzzle

allow disks to be moved one at a time from

one peg to another as long as a disk is never

placed on top of a smaller disk. The goal

of the puzzle is to have all the disks on the

second peg in order of size, with the largest

on the bottom.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 21 / 53

Page 47: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Applications of Recurrence Relations

Let Hn denote the number of moves needed to solve the Tower of Hanoiproblem with n disks. Set up a recurrence relation for sequence {Hn}.

Tower of Hanoi

Step # moves1: top n − 1 disk to peg 2 Hn−1

2: largest disk to peg 3 13: n − 1 disks from peg 2 to 3 Hn−1

Moreover, it is easy to see that the puzzle cannot be solved using fewersteps. This shows that H1 = 1, and when n ≥ 2

Hn = 2Hn−1 + 1 = 2(2Hn−2 + 1) + 1 = 22Hn−2 + 2 + 1

= 22(2Hn−3 + 1) + 2 + 1 = 23Hn−3 + 22 + 2 + 1

= · · · = 2n−1H1 + 2n−2 + · · ·+ 2 + 1

= 2n − 1

Particularly, 264 − 1 = 18, 446, 744, 073, 709, 551, 615.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 22 / 53

Page 48: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Applications of Recurrence Relations

Let Hn denote the number of moves needed to solve the Tower of Hanoiproblem with n disks. Set up a recurrence relation for sequence {Hn}.

Tower of Hanoi

Step # moves1: top n − 1 disk to peg 2 Hn−1

2: largest disk to peg 3 13: n − 1 disks from peg 2 to 3 Hn−1

Moreover, it is easy to see that the puzzle cannot be solved using fewersteps. This shows that H1 = 1, and when n ≥ 2

Hn = 2Hn−1 + 1 = 2(2Hn−2 + 1) + 1 = 22Hn−2 + 2 + 1

= 22(2Hn−3 + 1) + 2 + 1 = 23Hn−3 + 22 + 2 + 1

= · · · = 2n−1H1 + 2n−2 + · · ·+ 2 + 1

= 2n − 1

Particularly, 264 − 1 = 18, 446, 744, 073, 709, 551, 615.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 22 / 53

Page 49: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Applications of Recurrence Relations

Let Hn denote the number of moves needed to solve the Tower of Hanoiproblem with n disks. Set up a recurrence relation for sequence {Hn}.

Tower of Hanoi

Step # moves1: top n − 1 disk to peg 2 Hn−1

2: largest disk to peg 3 13: n − 1 disks from peg 2 to 3 Hn−1

Moreover, it is easy to see that the puzzle cannot be solved using fewersteps. This shows that H1 = 1, and when n ≥ 2

Hn = 2Hn−1 + 1 = 2(2Hn−2 + 1) + 1 = 22Hn−2 + 2 + 1

= 22(2Hn−3 + 1) + 2 + 1 = 23Hn−3 + 22 + 2 + 1

= · · · = 2n−1H1 + 2n−2 + · · ·+ 2 + 1

= 2n − 1

Particularly, 264 − 1 = 18, 446, 744, 073, 709, 551, 615.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 22 / 53

Page 50: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Applications of Recurrence Relations

Codeword Enumeration

Question: A computer system considers a string of decimal digits avalid codeword if it contains an even number of 0 digits. For instance,1230407869 is valid, whereas 120987045608 is not valid. How manyvalid n-digit codewords?

Solution: Let an be the number of valid n-digit codewords. Find arecurrence relation for an.Note that a1 = 9 since only 0 is invalid. Assume that n ≥ 2, we have

Way # digitsWay 1: ending with non-zero 9an−1

Task 11: choose the ending digit 9Task 12: choose the remaining digits an−1

Way 2: ending with zero 10n−1 − an−1

We conclude thatan = 8an−1 + 10n−1

for n ≥ 2.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 23 / 53

Page 51: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Applications of Recurrence Relations

Codeword Enumeration

Question: A computer system considers a string of decimal digits avalid codeword if it contains an even number of 0 digits. For instance,1230407869 is valid, whereas 120987045608 is not valid. How manyvalid n-digit codewords?Solution: Let an be the number of valid n-digit codewords. Find arecurrence relation for an.

Note that a1 = 9 since only 0 is invalid. Assume that n ≥ 2, we haveWay # digitsWay 1: ending with non-zero 9an−1

Task 11: choose the ending digit 9Task 12: choose the remaining digits an−1

Way 2: ending with zero 10n−1 − an−1

We conclude thatan = 8an−1 + 10n−1

for n ≥ 2.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 23 / 53

Page 52: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Applications of Recurrence Relations

Codeword Enumeration

Question: A computer system considers a string of decimal digits avalid codeword if it contains an even number of 0 digits. For instance,1230407869 is valid, whereas 120987045608 is not valid. How manyvalid n-digit codewords?Solution: Let an be the number of valid n-digit codewords. Find arecurrence relation for an.Note that a1 = 9 since only 0 is invalid. Assume that n ≥ 2, we have

Way # digitsWay 1: ending with non-zero 9an−1

Task 11: choose the ending digit 9Task 12: choose the remaining digits an−1

Way 2: ending with zero 10n−1 − an−1

We conclude thatan = 8an−1 + 10n−1

for n ≥ 2.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 23 / 53

Page 53: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Applications of Recurrence Relations

Codeword Enumeration

Question: A computer system considers a string of decimal digits avalid codeword if it contains an even number of 0 digits. For instance,1230407869 is valid, whereas 120987045608 is not valid. How manyvalid n-digit codewords?Solution: Let an be the number of valid n-digit codewords. Find arecurrence relation for an.Note that a1 = 9 since only 0 is invalid. Assume that n ≥ 2, we have

Way # digitsWay 1: ending with non-zero 9an−1

Task 11: choose the ending digit 9Task 12: choose the remaining digits an−1

Way 2: ending with zero 10n−1 − an−1

We conclude thatan = 8an−1 + 10n−1

for n ≥ 2.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 23 / 53

Page 54: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Applications of Recurrence Relations

Specifying the order of multiplication

Question: Find the number of ways to parenthesize the product ofn +1 numbers, x0 ·x1 ·x2 · · · xn, to specify the order of multiplication.

Let Cn denote the number of ways to parenthesize the product ofn + 1 numbers.Solution: Note that C0 = C1 = 1. Assume that n ≥ 2, we have

Location of last operation · # orders of multip.Way 1: between x0 and x1 C0Cn−1

Way 2: between x1 and x2 C1Cn−2

· · · · · · · · ·Way k: between xk−1 and xk Ck−1Cn−k· · · · · · · · ·Way n: between xn−1 and xn Cn−1C0

We conclude for n ≥ 2 that

Cn = C0Cn−1 + C1Cn−2 + · · ·+ Cn−1C0 =n−1∑k=0

CkCn−k−1.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 24 / 53

Page 55: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Applications of Recurrence Relations

Specifying the order of multiplication

Question: Find the number of ways to parenthesize the product ofn +1 numbers, x0 ·x1 ·x2 · · · xn, to specify the order of multiplication.Let Cn denote the number of ways to parenthesize the product ofn + 1 numbers.Solution:

Note that C0 = C1 = 1. Assume that n ≥ 2, we haveLocation of last operation · # orders of multip.

Way 1: between x0 and x1 C0Cn−1

Way 2: between x1 and x2 C1Cn−2

· · · · · · · · ·Way k: between xk−1 and xk Ck−1Cn−k· · · · · · · · ·Way n: between xn−1 and xn Cn−1C0

We conclude for n ≥ 2 that

Cn = C0Cn−1 + C1Cn−2 + · · ·+ Cn−1C0 =n−1∑k=0

CkCn−k−1.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 24 / 53

Page 56: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Applications of Recurrence Relations

Specifying the order of multiplication

Question: Find the number of ways to parenthesize the product ofn +1 numbers, x0 ·x1 ·x2 · · · xn, to specify the order of multiplication.Let Cn denote the number of ways to parenthesize the product ofn + 1 numbers.Solution: Note that C0 = C1 = 1. Assume that n ≥ 2, we have

Location of last operation · # orders of multip.Way 1: between x0 and x1 C0Cn−1

Way 2: between x1 and x2 C1Cn−2

· · · · · · · · ·Way k: between xk−1 and xk Ck−1Cn−k· · · · · · · · ·Way n: between xn−1 and xn Cn−1C0

We conclude for n ≥ 2 that

Cn = C0Cn−1 + C1Cn−2 + · · ·+ Cn−1C0 =n−1∑k=0

CkCn−k−1.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 24 / 53

Page 57: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Applications of Recurrence Relations

Specifying the order of multiplication

Question: Find the number of ways to parenthesize the product ofn +1 numbers, x0 ·x1 ·x2 · · · xn, to specify the order of multiplication.Let Cn denote the number of ways to parenthesize the product ofn + 1 numbers.Solution: Note that C0 = C1 = 1. Assume that n ≥ 2, we have

Location of last operation · # orders of multip.Way 1: between x0 and x1 C0Cn−1

Way 2: between x1 and x2 C1Cn−2

· · · · · · · · ·Way k: between xk−1 and xk Ck−1Cn−k· · · · · · · · ·Way n: between xn−1 and xn Cn−1C0

We conclude for n ≥ 2 that

Cn = C0Cn−1 + C1Cn−2 + · · ·+ Cn−1C0 =n−1∑k=0

CkCn−k−1.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 24 / 53

Page 58: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Algorithms and Recurrence Relations

What is dynamic programming?

Wikipedia Definition: “method for solving complex problems bybreaking them down into simpler subproblems”

Steps:

1 Define subproblems;

2 Write down the recurrence that relates subproblems;

3 Recognize and solve the base cases.

Example (1-dimensional DP)

Given n, find the number of different ways to write n as the sum of1, 3, 4. For example: when n = 5, the answer is 6.

5 = 1 + 1 + 1 + 1 + 1 = 1 + 1 + 3 = 1 + 3 + 1

= 3 + 1 + 1 = 1 + 4 = 4 + 1

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 25 / 53

Page 59: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Algorithms and Recurrence Relations

What is dynamic programming?

Wikipedia Definition: “method for solving complex problems bybreaking them down into simpler subproblems”Steps:

1 Define subproblems;

2 Write down the recurrence that relates subproblems;

3 Recognize and solve the base cases.

Example (1-dimensional DP)

Given n, find the number of different ways to write n as the sum of1, 3, 4. For example: when n = 5, the answer is 6.

5 = 1 + 1 + 1 + 1 + 1 = 1 + 1 + 3 = 1 + 3 + 1

= 3 + 1 + 1 = 1 + 4 = 4 + 1

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 25 / 53

Page 60: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Algorithms and Recurrence Relations

What is dynamic programming?

Wikipedia Definition: “method for solving complex problems bybreaking them down into simpler subproblems”Steps:

1 Define subproblems;

2 Write down the recurrence that relates subproblems;

3 Recognize and solve the base cases.

Example (1-dimensional DP)

Given n, find the number of different ways to write n as the sum of1, 3, 4. For example: when n = 5, the answer is 6.

5 = 1 + 1 + 1 + 1 + 1 = 1 + 1 + 3 = 1 + 3 + 1

= 3 + 1 + 1 = 1 + 4 = 4 + 1

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 25 / 53

Page 61: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Algorithms and Recurrence Relations

How to solve the 1-dimensional DP?

Solution

Step 1: Define subproblems Let Dn be the number of ways towrite n as the sum of 1, 3, 4.Step 2: Find the recurrence

Consider one possible solution n = x1 + x2 + · · ·+ xm;

If xm = 1, the rest of the terms must sum to n − 1. Thus, thenumber of sums that end with xm = 1 is equal to Dn−1;

Similarly, recurrence is then Dn = Dn−1 + Dn−3 + Dn−4.

Step 3: Solve the base cases We can set D0 = D1 = D2 = 1,and D3 = 2.

Implement:

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 26 / 53

Page 62: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Algorithms and Recurrence Relations

How to solve the 1-dimensional DP?

Solution

Step 1: Define subproblems Let Dn be the number of ways towrite n as the sum of 1, 3, 4.Step 2: Find the recurrence

Consider one possible solution n = x1 + x2 + · · ·+ xm;

If xm = 1, the rest of the terms must sum to n − 1. Thus, thenumber of sums that end with xm = 1 is equal to Dn−1;

Similarly, recurrence is then Dn = Dn−1 + Dn−3 + Dn−4.

Step 3: Solve the base cases We can set D0 = D1 = D2 = 1,and D3 = 2.

Implement:

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 26 / 53

Page 63: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Algorithms and Recurrence Relations

2-dimensional DP Example

Question: Given two strings x and y , find the longest commonsubsequence (LCS). For example, x : ABCBDAB and y : BDCABC ,then BCAB is the longest subsequence found in both sequences.

Solution

Step 1: Define subproblems Let Dij be the length of the LCS ofx1···i and y1···j ;Step 2: Find the recurrence

If xi = yj , they both contribute to the LCS, thenDij = Di−1,j−1 + 1;

Otherwise, either xi or yj does not contribute to the LCS, soone can be dropped Dij = max{Di−1,j ,Di ,j−1}.

Step 3: Solve the base cases We can set Di0 = D0j = 0.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 27 / 53

Page 64: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Algorithms and Recurrence Relations

2-dimensional DP Example

Question: Given two strings x and y , find the longest commonsubsequence (LCS). For example, x : ABCBDAB and y : BDCABC ,then BCAB is the longest subsequence found in both sequences.

Solution

Step 1: Define subproblems Let Dij be the length of the LCS ofx1···i and y1···j ;Step 2: Find the recurrence

If xi = yj , they both contribute to the LCS, thenDij = Di−1,j−1 + 1;

Otherwise, either xi or yj does not contribute to the LCS, soone can be dropped Dij = max{Di−1,j ,Di ,j−1}.

Step 3: Solve the base cases We can set Di0 = D0j = 0.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 27 / 53

Page 65: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Algorithms and Recurrence Relations

Implementation

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 28 / 53

Page 66: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Algorithms and Recurrence Relations

Talk scheduling

We need to schedule as many talks as possi-

ble in a single lecture hall. These talks have

preset start and end times; once a talk start-

s, it continues until it ends; no two talks can

proceed at the same time; and a talk can be-

gin at the same time another one ends. Our

goal is to have the largest possible combined

attendance of the scheduled talks.

We formalize this problem by supposing that we have n talks, where talk jbegins at time sj , ends at time ej , and will be attended by wj students.We define

p(j) =

{max{i}, if i < j ∧ ei ≤ sj ;0, otherwise.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 29 / 53

Page 67: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Algorithms and Recurrence Relations

DP for talk scheduling

Solution

Step 1: Define subproblems T (j) is the maximal number of totalattendees for an optimal schedule for the first j talks.

Step 2: Find the recurrence

When talk j belongs to the optimal schedule,T (j) = wj + T (p(j));

When talk j does not belong to the optimal schedule,T (j) = T (j − 1);

Thus, T (j) = max{wj + T (p(j)),T (j − 1)};Step 3: Solve the base cases We can set T (0) = 0.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 30 / 53

Page 68: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Algorithms and Recurrence Relations

DP for talk scheduling

Solution

Step 1: Define subproblems T (j) is the maximal number of totalattendees for an optimal schedule for the first j talks.Step 2: Find the recurrence

When talk j belongs to the optimal schedule,T (j) = wj + T (p(j));

When talk j does not belong to the optimal schedule,T (j) = T (j − 1);

Thus, T (j) = max{wj + T (p(j)),T (j − 1)};

Step 3: Solve the base cases We can set T (0) = 0.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 30 / 53

Page 69: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Algorithms and Recurrence Relations

DP for talk scheduling

Solution

Step 1: Define subproblems T (j) is the maximal number of totalattendees for an optimal schedule for the first j talks.Step 2: Find the recurrence

When talk j belongs to the optimal schedule,T (j) = wj + T (p(j));

When talk j does not belong to the optimal schedule,T (j) = T (j − 1);

Thus, T (j) = max{wj + T (p(j)),T (j − 1)};Step 3: Solve the base cases We can set T (0) = 0.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 30 / 53

Page 70: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Algorithms and Recurrence Relations

Implementation

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 31 / 53

Page 71: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Solving Linear Recurrence Relations

An explicit form of the Fibonacci sequence

While the recurrence for Fn completely specifies the sequence, it is hard tofind the value of, say, F20 quickly. We really have to enumerate thesequence from F0,F1, . . . , to get to F20. Also, with the definition based onthe recurrence, other properties of the sequence is unclear (e.g., how fastthe sequence grows).Therefore, it might be useful to find the explicit definition of the Fibonaccisequence.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 32 / 53

Page 72: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Solving Linear Recurrence Relations

Ratios

To get started, we might want to look for a common form of the function.We can start by looking at the numbers in the sequence.

n Fn ratio Fn/Fn−1

1 12 1 1.00000000003 2 2.00000000004 3 1.50000000005 5 1.66666666676 8 1.60000000007 13 1.62500000008 21 1.61538461549 34 1.6190476190

10 55 1.617647058811 89 1.618181818212 144 1.6179775281

n Fn ratio Fn/Fn−1

13 233 1.618055555614 377 1.618025751115 610 1.618037135316 987 1.618032786917 1597 1.618034447818 2584 1.618033813419 4181 1.618034055720 6765 1.618033963221 10946 1.618033998522 17711 1.618033985023 28657 1.618033990224 46368 1.6180339882

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 33 / 53

Page 73: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Solving Linear Recurrence Relations

The 1st guess: an

We can see that the ratio between two consecutive Fibonacci numbers isclose to 1.61803. We may guess that the explicit form for Fn is anexponential function an. (While we know that this is not true, it may giveus hints on the correct function.)

Let’s try to figure out the exact value for a. The value a must satisfy therecurrence F (n + 1) = F (n) + F (n − 1), i.e.,

an+1 = an + an−1.

We can try to solve for a. Dividing the equation by an−1, we get

a2 = a + 1,

i.e., a2 − a− 1 = 0.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 34 / 53

Page 74: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Solving Linear Recurrence Relations

Solutions (1)

We can use a standard formula to get the values of a, i.e., a can be1+√

12+4·1·12·1 , 1−

√12+4·1·12·1 , or

1+√

52 , 1−

√5

2 .

These look nice because 1+√

52 ≈ 1.61803.

These solutions give us two candidates for Fn:

g(n) =

(1 +√

5

2

)n

, and h(n) =

(1−√

5

2

)n

,

But we can see that while both g(n) and h(n) satisfyg(n + 1) = g(n) + g(n − 1) and h(n + 1) = h(n) + h(n − 1), they are notthe correct function for Fn. (We can just plug in various values of n tocheck.)

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 35 / 53

Page 75: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Solving Linear Recurrence Relations

Linear recurrence relations

Definition

A linear homogeneous recurrence relation (shorted in LHR2) of degreek with constant coefficients is a recurrence relation of the form

an = c1an−1 + c2an−2 + · · ·+ ckan−k ,

where c1, c2, · · · , ck are real numbers, and ck 6= 0.

Examples

Pn = (1.11)Pn−1, fn = fn−1 + fn−2 and an = 5an−5 are linearhomogeneous recurrence relations associated with of degreesone, two and five;

an = an−1 + a2n−2 is not linear; Hn = 2Hn−1 + 1 is not

homogeneous; Bn = nBn−1 does not have constant coefficients.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 36 / 53

Page 76: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Solving Linear Recurrence Relations

Linear recurrence relations

Definition

A linear homogeneous recurrence relation (shorted in LHR2) of degreek with constant coefficients is a recurrence relation of the form

an = c1an−1 + c2an−2 + · · ·+ ckan−k ,

where c1, c2, · · · , ck are real numbers, and ck 6= 0.

Examples

Pn = (1.11)Pn−1, fn = fn−1 + fn−2 and an = 5an−5 are linearhomogeneous recurrence relations associated with of degreesone, two and five;

an = an−1 + a2n−2 is not linear; Hn = 2Hn−1 + 1 is not

homogeneous; Bn = nBn−1 does not have constant coefficients.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 36 / 53

Page 77: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Solving Linear Recurrence Relations

Linear recurrence relations

Definition

A linear homogeneous recurrence relation (shorted in LHR2) of degreek with constant coefficients is a recurrence relation of the form

an = c1an−1 + c2an−2 + · · ·+ ckan−k ,

where c1, c2, · · · , ck are real numbers, and ck 6= 0.

Examples

Pn = (1.11)Pn−1, fn = fn−1 + fn−2 and an = 5an−5 are linearhomogeneous recurrence relations associated with of degreesone, two and five;

an = an−1 + a2n−2 is not linear; Hn = 2Hn−1 + 1 is not

homogeneous; Bn = nBn−1 does not have constant coefficients.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 36 / 53

Page 78: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Solving Linear Recurrence Relations Solving LHR2 with Constant Coefficients

Solving LHR2 with constant coefficients

Guess: The basic approach for solving LHR2 is to look for solutionsof the form an = rn, where r is a constant.If an = rn is a solution of the recurrence relation an = c1an−1 +c2an−2 + · · ·+ ckan−k if and only if

rn = c1rn−1 + c2rn−2 + · · ·+ ck rn−k .

That isrk − c1rk−1 − c2rk−2 − · · · − ck = 0.

Consequently, the sequence {an} with an = rn is a solution if andonly if r is a solution of this last equation.We call this the characteristic equation of the recurrence relation.The solutions of this equation are called the characteristic roots ofthe recurrence relation.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 37 / 53

Page 79: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Solving Linear Recurrence Relations Solving LHR2 with Constant Coefficients

Solving LHR2 with constant coefficients

Guess: The basic approach for solving LHR2 is to look for solutionsof the form an = rn, where r is a constant.If an = rn is a solution of the recurrence relation an = c1an−1 +c2an−2 + · · ·+ ckan−k if and only if

rn = c1rn−1 + c2rn−2 + · · ·+ ck rn−k .

That isrk − c1rk−1 − c2rk−2 − · · · − ck = 0.

Consequently, the sequence {an} with an = rn is a solution if andonly if r is a solution of this last equation.We call this the characteristic equation of the recurrence relation.The solutions of this equation are called the characteristic roots ofthe recurrence relation.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 37 / 53

Page 80: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Solving Linear Recurrence Relations Solving LHR2 with Constant Coefficients

Solving LHR2 with constant coefficients

Guess: The basic approach for solving LHR2 is to look for solutionsof the form an = rn, where r is a constant.If an = rn is a solution of the recurrence relation an = c1an−1 +c2an−2 + · · ·+ ckan−k if and only if

rn = c1rn−1 + c2rn−2 + · · ·+ ck rn−k .

That isrk − c1rk−1 − c2rk−2 − · · · − ck = 0.

Consequently, the sequence {an} with an = rn is a solution if andonly if r is a solution of this last equation.

We call this the characteristic equation of the recurrence relation.The solutions of this equation are called the characteristic roots ofthe recurrence relation.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 37 / 53

Page 81: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Solving Linear Recurrence Relations Solving LHR2 with Constant Coefficients

Solving LHR2 with constant coefficients

Guess: The basic approach for solving LHR2 is to look for solutionsof the form an = rn, where r is a constant.If an = rn is a solution of the recurrence relation an = c1an−1 +c2an−2 + · · ·+ ckan−k if and only if

rn = c1rn−1 + c2rn−2 + · · ·+ ck rn−k .

That isrk − c1rk−1 − c2rk−2 − · · · − ck = 0.

Consequently, the sequence {an} with an = rn is a solution if andonly if r is a solution of this last equation.We call this the characteristic equation of the recurrence relation.The solutions of this equation are called the characteristic roots ofthe recurrence relation.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 37 / 53

Page 82: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Solving Linear Recurrence Relations Solving LHR2 with Constant Coefficients

LHR2 with degree two I

Theorem

Let c1 and c2 be real numbers c2 6= 0. Suppose that r 2−c1r−c2 = 0has two distinct roots r1 and r2. Then sequence {an} is a solutionof the recurrence relation an = c1an−1 + c2an−2 if and only if an =α1rn1 + α2rn2 for n = 0, 1, 2, · · · , where α1 and α2 are constants.

Proof

Note that r1 and r2 are roots of r 2 − c1r − c2 = 0. Thus, we haver 2i = c1ri + c2 for i = 1, 2.

If an = α1rn1 + α2rn2 , we have

c1an−1 + c2an−2 = c1(α1rn−11 + α2rn−1

2 ) + c2(α1rn−21 + α2rn−2

2 )

= α1rn−21 (c1r1 + c2) + α2rn−2

2 (c1r2 + c2)

= α1rn1 + α2rn2 = an

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 38 / 53

Page 83: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Solving Linear Recurrence Relations Solving LHR2 with Constant Coefficients

LHR2 with degree two I

Theorem

Let c1 and c2 be real numbers c2 6= 0. Suppose that r 2−c1r−c2 = 0has two distinct roots r1 and r2. Then sequence {an} is a solutionof the recurrence relation an = c1an−1 + c2an−2 if and only if an =α1rn1 + α2rn2 for n = 0, 1, 2, · · · , where α1 and α2 are constants.

Proof

Note that r1 and r2 are roots of r 2 − c1r − c2 = 0. Thus, we haver 2i = c1ri + c2 for i = 1, 2.

If an = α1rn1 + α2rn2 , we have

c1an−1 + c2an−2 = c1(α1rn−11 + α2rn−1

2 ) + c2(α1rn−21 + α2rn−2

2 )

= α1rn−21 (c1r1 + c2) + α2rn−2

2 (c1r2 + c2)

= α1rn1 + α2rn2 = an

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 38 / 53

Page 84: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Solving Linear Recurrence Relations Solving LHR2 with Constant Coefficients

LHR2 with degree two I

Theorem

Let c1 and c2 be real numbers c2 6= 0. Suppose that r 2−c1r−c2 = 0has two distinct roots r1 and r2. Then sequence {an} is a solutionof the recurrence relation an = c1an−1 + c2an−2 if and only if an =α1rn1 + α2rn2 for n = 0, 1, 2, · · · , where α1 and α2 are constants.

Proof

Note that r1 and r2 are roots of r 2 − c1r − c2 = 0. Thus, we haver 2i = c1ri + c2 for i = 1, 2.

If an = α1rn1 + α2rn2 , we have

c1an−1 + c2an−2 = c1(α1rn−11 + α2rn−1

2 ) + c2(α1rn−21 + α2rn−2

2 )

= α1rn−21 (c1r1 + c2) + α2rn−2

2 (c1r2 + c2)

= α1rn1 + α2rn2 = an

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 38 / 53

Page 85: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Solving Linear Recurrence Relations Solving LHR2 with Constant Coefficients

Determining α1 and α2

Let initial conditions a0 = C0 and a1 = C1 hold. We have

C0 = α1 + α2,C1 = α1r1 + α2r2

If an = α1rn1 + α2rn2 , we have

α1 =C1 − r2C0

r1 − r2

α2 = C0 − α1 =r1C0 − C1

r1 − r2

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 39 / 53

Page 86: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Solving Linear Recurrence Relations Solving LHR2 with Constant Coefficients

Determining α1 and α2

Let initial conditions a0 = C0 and a1 = C1 hold. We have

C0 = α1 + α2,C1 = α1r1 + α2r2

If an = α1rn1 + α2rn2 , we have

α1 =C1 − r2C0

r1 − r2

α2 = C0 − α1 =r1C0 − C1

r1 − r2

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 39 / 53

Page 87: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Solving Linear Recurrence Relations Solving LHR2 with Constant Coefficients

Determining α1 and α2

Let initial conditions a0 = C0 and a1 = C1 hold. We have

C0 = α1 + α2,C1 = α1r1 + α2r2

If an = α1rn1 + α2rn2 , we have

α1 =C1 − r2C0

r1 − r2

α2 = C0 − α1 =r1C0 − C1

r1 − r2

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 39 / 53

Page 88: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Solving Linear Recurrence Relations Solving LHR2 with Constant Coefficients

Solutions for Fibonacci numbers

Since 1+√

52 , 1−

√5

2 are two roots of r 2 − r − 1 = 0.We define g(n) and h(n) as follows:

g(n) =

(1 +√

5

2

)n

, and h(n) =

(1−√

5

2

)n

,

Furthermore, we have `(n) = αg(n) + βh(n).

To get the actual function, we observe that if both g(n) and h(n) aresolutions to our recurrence, then for any α and β, we have

α(

1+√

52

)0+ β

(1−√

52

)0= α + β = 0,

and

α(

1+√

52

)1+ β

(1−√

52

)1= α

(1+√

52

)+ β

(1−√

52

)= 1.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 40 / 53

Page 89: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Solving Linear Recurrence Relations Solving LHR2 with Constant Coefficients

Solutions for Fibonacci numbers

Since 1+√

52 , 1−

√5

2 are two roots of r 2 − r − 1 = 0.We define g(n) and h(n) as follows:

g(n) =

(1 +√

5

2

)n

, and h(n) =

(1−√

5

2

)n

,

Furthermore, we have `(n) = αg(n) + βh(n).To get the actual function, we observe that if both g(n) and h(n) aresolutions to our recurrence, then for any α and β, we have

α(

1+√

52

)0+ β

(1−√

52

)0= α + β = 0,

and

α(

1+√

52

)1+ β

(1−√

52

)1= α

(1+√

52

)+ β

(1−√

52

)= 1.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 40 / 53

Page 90: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Solving Linear Recurrence Relations Solving LHR2 with Constant Coefficients

Solutions for Fibonacci numbers

Since 1+√

52 , 1−

√5

2 are two roots of r 2 − r − 1 = 0.We define g(n) and h(n) as follows:

g(n) =

(1 +√

5

2

)n

, and h(n) =

(1−√

5

2

)n

,

Furthermore, we have `(n) = αg(n) + βh(n).To get the actual function, we observe that if both g(n) and h(n) aresolutions to our recurrence, then for any α and β, we have

α(

1+√

52

)0+ β

(1−√

52

)0= α + β = 0,

and

α(

1+√

52

)1+ β

(1−√

52

)1= α

(1+√

52

)+ β

(1−√

52

)= 1.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 40 / 53

Page 91: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Solving Linear Recurrence Relations Solving LHR2 with Constant Coefficients

Final solution

The first equation gives β = −α. Put that in the second equation to get

α(

1+√

52

)− α

(1−√

52

)= 2α

√5

2 = α√

5 = 1,

implying that α = 1/√

5 and β = −1/√

5.

Using the obtained α and β, our solution to Fn becomes

1√5

(1 +√

5

2

)n

− 1√5

(1−√

5

2

)n

.

Note that 1+√

52 ≈ 1.61803 is the golden ratio. Also observe that

|1−√

52 | ≈ | − 0.61803| < 1; therefore, the term

(1−√

52

)ngoes to zero as n

goes to infinity. This explains why we only observe only the ratio 1+√

52 in

Fn as n gets large.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 41 / 53

Page 92: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Solving Linear Recurrence Relations Solving LHR2 with Constant Coefficients

Final solution

The first equation gives β = −α. Put that in the second equation to get

α(

1+√

52

)− α

(1−√

52

)= 2α

√5

2 = α√

5 = 1,

implying that α = 1/√

5 and β = −1/√

5.Using the obtained α and β, our solution to Fn becomes

1√5

(1 +√

5

2

)n

− 1√5

(1−√

5

2

)n

.

Note that 1+√

52 ≈ 1.61803 is the golden ratio. Also observe that

|1−√

52 | ≈ | − 0.61803| < 1; therefore, the term

(1−√

52

)ngoes to zero as n

goes to infinity. This explains why we only observe only the ratio 1+√

52 in

Fn as n gets large.MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 41 / 53

Page 93: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Solving Linear Recurrence Relations Solving LHR2 with Constant Coefficients

LHR2 with degree two II

Theorem

Let c1 and c2 be real numbers c2 6= 0. Suppose that r 2−c1r−c2 = 0has only one root r0. A sequence {an} is a solution of the recurrencerelation an = c1an−1 + c2an−2 if and only if an = α1rn0 + α2nrn0 forn = 0, 1, 2, · · · , where α1 and α2 are constants. [The proof is left asan exercise]

Example

What is the solution of the recurrence relation an = 6an−1 − 9an−2

with initial conditions a0 = 1 and a1 = 6?Solution: The only root of r 2 − 6r + 9 = 0 is r = 3. Hence, thesolution to this recurrence relation is an = α13n + α2n3n.Using the initial conditions, it follows that a0 = 1 = α1, a1 = 6 =3α1 + 3α2. That is an = 3n + n3n.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 42 / 53

Page 94: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Solving Linear Recurrence Relations Solving LHR2 with Constant Coefficients

LHR2 with degree two II

Theorem

Let c1 and c2 be real numbers c2 6= 0. Suppose that r 2−c1r−c2 = 0has only one root r0. A sequence {an} is a solution of the recurrencerelation an = c1an−1 + c2an−2 if and only if an = α1rn0 + α2nrn0 forn = 0, 1, 2, · · · , where α1 and α2 are constants. [The proof is left asan exercise]

Example

What is the solution of the recurrence relation an = 6an−1 − 9an−2

with initial conditions a0 = 1 and a1 = 6?Solution:

The only root of r 2 − 6r + 9 = 0 is r = 3. Hence, thesolution to this recurrence relation is an = α13n + α2n3n.Using the initial conditions, it follows that a0 = 1 = α1, a1 = 6 =3α1 + 3α2. That is an = 3n + n3n.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 42 / 53

Page 95: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Solving Linear Recurrence Relations Solving LHR2 with Constant Coefficients

LHR2 with degree two II

Theorem

Let c1 and c2 be real numbers c2 6= 0. Suppose that r 2−c1r−c2 = 0has only one root r0. A sequence {an} is a solution of the recurrencerelation an = c1an−1 + c2an−2 if and only if an = α1rn0 + α2nrn0 forn = 0, 1, 2, · · · , where α1 and α2 are constants. [The proof is left asan exercise]

Example

What is the solution of the recurrence relation an = 6an−1 − 9an−2

with initial conditions a0 = 1 and a1 = 6?Solution: The only root of r 2 − 6r + 9 = 0 is r = 3. Hence, thesolution to this recurrence relation is an = α13n + α2n3n.

Using the initial conditions, it follows that a0 = 1 = α1, a1 = 6 =3α1 + 3α2. That is an = 3n + n3n.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 42 / 53

Page 96: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Solving Linear Recurrence Relations Solving LHR2 with Constant Coefficients

LHR2 with degree two II

Theorem

Let c1 and c2 be real numbers c2 6= 0. Suppose that r 2−c1r−c2 = 0has only one root r0. A sequence {an} is a solution of the recurrencerelation an = c1an−1 + c2an−2 if and only if an = α1rn0 + α2nrn0 forn = 0, 1, 2, · · · , where α1 and α2 are constants. [The proof is left asan exercise]

Example

What is the solution of the recurrence relation an = 6an−1 − 9an−2

with initial conditions a0 = 1 and a1 = 6?Solution: The only root of r 2 − 6r + 9 = 0 is r = 3. Hence, thesolution to this recurrence relation is an = α13n + α2n3n.Using the initial conditions, it follows that a0 = 1 = α1, a1 = 6 =3α1 + 3α2. That is an = 3n + n3n.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 42 / 53

Page 97: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Solving Linear Recurrence Relations Solving LHR2 with Constant Coefficients

LHR2 with degree k I

Theorem

Let c1, c2, · · · , ck be real numbers ck 6= 0. Suppose that the charac-teristic equation

rk − c1rk−1 − · · · − ck = 0

has k distinct roots ri for i = 1, 2, · · · , k . Then sequence {an} is asolution of the recurrence relation

an = c1an−1 + c2an−2 + · · ·+ ckan−k

if and only ifan = α1rn1 + α2rn2 + αk rnk

for n = 0, 1, 2, · · · , where α1, α2, · · · , αk are constants.[The proof is left as an exercise]

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 43 / 53

Page 98: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Solving Linear Recurrence Relations Solving LHR2 with Constant Coefficients

Example

Find the solution to the recurrence relation an = 6an−1 − 11an−2 +6an−3 with the initial conditions a0 = 2, a1 = 5, and a2 = 15.Solution:

The characteristic equation of this recurrence relation is

r 3 − 6r 2 + 11r − 6 = 0.

The characteristic roots are r = 1, r = 2, and r = 3. Hence, thesolutions to this recurrence relation are of form

an = α1 · 1n + α2 · 2n + α3 · 3n.

Using the initial conditions, it gives

a0 = 2 = α1 + α2 + α3, a1 = 5 = α1 + 2α2 + 3α3,

a2 = 15 = α1 + 4α2 + 9α3.

Hence, we have an = 1− 2n + 2 · 3n. (α1 = 1, α2 = −1, and α3 = 2)

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 44 / 53

Page 99: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Solving Linear Recurrence Relations Solving LHR2 with Constant Coefficients

Example

Find the solution to the recurrence relation an = 6an−1 − 11an−2 +6an−3 with the initial conditions a0 = 2, a1 = 5, and a2 = 15.Solution: The characteristic equation of this recurrence relation is

r 3 − 6r 2 + 11r − 6 = 0.

The characteristic roots are r = 1, r = 2, and r = 3. Hence, thesolutions to this recurrence relation are of form

an = α1 · 1n + α2 · 2n + α3 · 3n.

Using the initial conditions, it gives

a0 = 2 = α1 + α2 + α3, a1 = 5 = α1 + 2α2 + 3α3,

a2 = 15 = α1 + 4α2 + 9α3.

Hence, we have an = 1− 2n + 2 · 3n. (α1 = 1, α2 = −1, and α3 = 2)

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 44 / 53

Page 100: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Solving Linear Recurrence Relations Solving LHR2 with Constant Coefficients

Example

Find the solution to the recurrence relation an = 6an−1 − 11an−2 +6an−3 with the initial conditions a0 = 2, a1 = 5, and a2 = 15.Solution: The characteristic equation of this recurrence relation is

r 3 − 6r 2 + 11r − 6 = 0.

The characteristic roots are r = 1, r = 2, and r = 3. Hence, thesolutions to this recurrence relation are of form

an = α1 · 1n + α2 · 2n + α3 · 3n.

Using the initial conditions, it gives

a0 = 2 = α1 + α2 + α3, a1 = 5 = α1 + 2α2 + 3α3,

a2 = 15 = α1 + 4α2 + 9α3.

Hence, we have an = 1− 2n + 2 · 3n. (α1 = 1, α2 = −1, and α3 = 2)

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 44 / 53

Page 101: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Solving Linear Recurrence Relations Solving LHR2 with Constant Coefficients

Example

Find the solution to the recurrence relation an = 6an−1 − 11an−2 +6an−3 with the initial conditions a0 = 2, a1 = 5, and a2 = 15.Solution: The characteristic equation of this recurrence relation is

r 3 − 6r 2 + 11r − 6 = 0.

The characteristic roots are r = 1, r = 2, and r = 3. Hence, thesolutions to this recurrence relation are of form

an = α1 · 1n + α2 · 2n + α3 · 3n.

Using the initial conditions, it gives

a0 = 2 = α1 + α2 + α3, a1 = 5 = α1 + 2α2 + 3α3,

a2 = 15 = α1 + 4α2 + 9α3.

Hence, we have an = 1− 2n + 2 · 3n. (α1 = 1, α2 = −1, and α3 = 2)

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 44 / 53

Page 102: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Solving Linear Recurrence Relations Solving LHR2 with Constant Coefficients

Example

Find the solution to the recurrence relation an = 6an−1 − 11an−2 +6an−3 with the initial conditions a0 = 2, a1 = 5, and a2 = 15.Solution: The characteristic equation of this recurrence relation is

r 3 − 6r 2 + 11r − 6 = 0.

The characteristic roots are r = 1, r = 2, and r = 3. Hence, thesolutions to this recurrence relation are of form

an = α1 · 1n + α2 · 2n + α3 · 3n.

Using the initial conditions, it gives

a0 = 2 = α1 + α2 + α3, a1 = 5 = α1 + 2α2 + 3α3,

a2 = 15 = α1 + 4α2 + 9α3.

Hence, we have an = 1− 2n + 2 · 3n. (α1 = 1, α2 = −1, and α3 = 2)MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 44 / 53

Page 103: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Solving Linear Recurrence Relations Solving LHR2 with Constant Coefficients

LHR2 with degree k II

Theorem

Let c1, c2, · · · , ck be real numbers ck 6= 0. Suppose that character-istic equation

rk − c1rk−1 − · · · − ck = 0

has t distinct roots ri with multiplicities mi (for i = 1, 2, · · · , t),respectively (that is

∑ti=1 mi = k). Then sequence {an} is a solution

of recurrence relation an = c1an−1 + c2an−2 + · · · + ckan−k if andonly if

an = (α1,0 + α1,1n + · · ·+ α1,m1−1nm1−1)rn1

+ (α2,0 + α2,1n + · · ·+ α2,m2−1nm2−1)rn2

+ · · ·+ (αt,0 + αt,1n + · · ·+ αt,mt−1nmt−1)rnt

for n = 0, 1, 2, · · · , where αi ,j are constants for 1 ≤ i ≤ t and0 ≤ j ≤ mi − 1. [The proof is left as an exercise]

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 45 / 53

Page 104: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Solving Linear Recurrence Relations Solving LHR2 with Constant Coefficients

Example

Find the solution to the recurrence relation an = −3an−1 − 3an−2 −an−3 with the initial conditions a0 = 1, a1 = −2, and a2 = −1.Solution:

The characteristic equation of this recurrence relation is

r 3 + 3r 2 + 3r + 1 = 0.

The characteristic root is r = −1 of multiplicity three of the equation.Hence, the solutions to this recurrence relation are of form

an = α0 · (−1)n + α1 · n · (−1)n + α2 · n2 · (−1)n.

Using the initial conditions, it gives

a0 = 1 = α0, a1 = −2 = −α0 − α1 − α2,

a2 = −1 = α0 + 2α1 + 4α2.

Hence, an = (1 + 3n +−2n2)(−1)n. (α0 = 1, α1 = 3, and α2 = −2)

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 46 / 53

Page 105: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Solving Linear Recurrence Relations Solving LHR2 with Constant Coefficients

Example

Find the solution to the recurrence relation an = −3an−1 − 3an−2 −an−3 with the initial conditions a0 = 1, a1 = −2, and a2 = −1.Solution: The characteristic equation of this recurrence relation is

r 3 + 3r 2 + 3r + 1 = 0.

The characteristic root is r = −1 of multiplicity three of the equation.Hence, the solutions to this recurrence relation are of form

an = α0 · (−1)n + α1 · n · (−1)n + α2 · n2 · (−1)n.

Using the initial conditions, it gives

a0 = 1 = α0, a1 = −2 = −α0 − α1 − α2,

a2 = −1 = α0 + 2α1 + 4α2.

Hence, an = (1 + 3n +−2n2)(−1)n. (α0 = 1, α1 = 3, and α2 = −2)

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 46 / 53

Page 106: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Solving Linear Recurrence Relations Solving LHR2 with Constant Coefficients

Example

Find the solution to the recurrence relation an = −3an−1 − 3an−2 −an−3 with the initial conditions a0 = 1, a1 = −2, and a2 = −1.Solution: The characteristic equation of this recurrence relation is

r 3 + 3r 2 + 3r + 1 = 0.

The characteristic root is r = −1 of multiplicity three of the equation.Hence, the solutions to this recurrence relation are of form

an = α0 · (−1)n + α1 · n · (−1)n + α2 · n2 · (−1)n.

Using the initial conditions, it gives

a0 = 1 = α0, a1 = −2 = −α0 − α1 − α2,

a2 = −1 = α0 + 2α1 + 4α2.

Hence, an = (1 + 3n +−2n2)(−1)n. (α0 = 1, α1 = 3, and α2 = −2)

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 46 / 53

Page 107: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Solving Linear Recurrence Relations Solving LHR2 with Constant Coefficients

Example

Find the solution to the recurrence relation an = −3an−1 − 3an−2 −an−3 with the initial conditions a0 = 1, a1 = −2, and a2 = −1.Solution: The characteristic equation of this recurrence relation is

r 3 + 3r 2 + 3r + 1 = 0.

The characteristic root is r = −1 of multiplicity three of the equation.Hence, the solutions to this recurrence relation are of form

an = α0 · (−1)n + α1 · n · (−1)n + α2 · n2 · (−1)n.

Using the initial conditions, it gives

a0 = 1 = α0, a1 = −2 = −α0 − α1 − α2,

a2 = −1 = α0 + 2α1 + 4α2.

Hence, an = (1 + 3n +−2n2)(−1)n. (α0 = 1, α1 = 3, and α2 = −2)MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 46 / 53

Page 108: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Solving Linear Recurrence Relations Solving LNR2 with Constant Coefficients

LNR2 with constant coefficients

Definition

A linear nonhomogeneous recurrence relation (shorted in LNR2)with constant coefficients of degree k is a recurrence relation of theform

an = c1an−1 + c2an−2 + · · ·+ ckan−k + F (n),

where c1, c2, · · · , ck are real numbers (ck 6= 0), and F (n) is a functionnot identically zero depending only on n. The recurrence relation

an = c1an−1 + c2an−2 + · · ·+ ckan−k

is called the associated homogeneous recurrence relation.

Example

Recurrence relations an = 3an−1 + 2n, an = an−2 + n2 + 1, an = 3an1 + n3n, and

an = an−1 + an−2 + n! are examples of LNR2 with constant coefficients

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 47 / 53

Page 109: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Solving Linear Recurrence Relations Solving LNR2 with Constant Coefficients

LNR2 with constant coefficients

Definition

A linear nonhomogeneous recurrence relation (shorted in LNR2)with constant coefficients of degree k is a recurrence relation of theform

an = c1an−1 + c2an−2 + · · ·+ ckan−k + F (n),

where c1, c2, · · · , ck are real numbers (ck 6= 0), and F (n) is a functionnot identically zero depending only on n. The recurrence relation

an = c1an−1 + c2an−2 + · · ·+ ckan−k

is called the associated homogeneous recurrence relation.

Example

Recurrence relations an = 3an−1 + 2n, an = an−2 + n2 + 1, an = 3an1 + n3n, and

an = an−1 + an−2 + n! are examples of LNR2 with constant coefficients

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 47 / 53

Page 110: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Solving Linear Recurrence Relations Solving LNR2 with Constant Coefficients

Solution for LNR2

Theorem

If {a(p)n } is a particular solution of LNR2 with constant coefficients

an = c1an−1 + c2an−2 + · · ·+ ckan−k + F (n),

then every solution is of the form {a(p)n + a

(h)n }, where {a(h)

n } is asolution of LHR2

an = c1an−1 + c2an−2 + · · ·+ ckan−k .

Proof

Because {a(p)n } is a particular solution of the LNR2, we therefore

havea

(p)n = c1a

(p)n−1 + c2a

(p)n−2 + · · ·+ cka

(p)n−k + F (n).

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 48 / 53

Page 111: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Solving Linear Recurrence Relations Solving LNR2 with Constant Coefficients

Solution for LNR2

Theorem

If {a(p)n } is a particular solution of LNR2 with constant coefficients

an = c1an−1 + c2an−2 + · · ·+ ckan−k + F (n),

then every solution is of the form {a(p)n + a

(h)n }, where {a(h)

n } is asolution of LHR2

an = c1an−1 + c2an−2 + · · ·+ ckan−k .

Proof

Because {a(p)n } is a particular solution of the LNR2, we therefore

havea

(p)n = c1a

(p)n−1 + c2a

(p)n−2 + · · ·+ cka

(p)n−k + F (n).

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 48 / 53

Page 112: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Solving Linear Recurrence Relations Solving LNR2 with Constant Coefficients

Proof Cont’d

Proof

Since {a(p)n } is a particular solution of the LNR2, we therefore have

a(p)n = c1a

(p)n−1 + c2a

(p)n−2 + · · ·+ cka

(p)n−k + F (n).

Now suppose that {bn} is a second solution of the LNR2, so that

bn = c1bn−1 + c2bn−2 + · · ·+ ckbn−k + F (n).

Thus, we have

bn − a(p)n = c1(bn−1 − a

(p)n−1) + c2(bn−2 − a

(p)n−2) + · · ·+ ck(bn−k − a

(p)n−k).

It follows that {bn−a(p)n } is a solution of the associated homogeneous

linear recurrence, say, {a(h)n }.

Consequently, we have bn = {a(p)n + a

(h)n } for all n.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 49 / 53

Page 113: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Solving Linear Recurrence Relations Solving LNR2 with Constant Coefficients

Example I

Find the solution to recurrence relation an = 3an−1 + 2n with initialconditions a1 = 3.Solution:

Step 1: find the solution for LHR2. The associated linear homo-

geneous equation is an = 3an−1. Its solution is a(h)n = α3n, where α

is a constant.Step 2: find a particular solution. Let pn = cn + d be a particularsolution of the recurrence relation, where c and d are constants.Then, we have cn + d = 3(c(n − 1) + d) + 2n, that is (2 + 2c)n +(2d − 3c) = 0. It follows that cn + d is a solution if and only if2 + 2c = 0 and 2d − 3c = 0, i.e., c = −1 and d = −3/2.

Consequently, an = {a(p)n + a

(h)n } = −n− 3

2 +α · 3n. Using the initialconditions, it gives α = 11

6 . Thus,

an = (11

6)3n + n − 3

2.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 50 / 53

Page 114: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Solving Linear Recurrence Relations Solving LNR2 with Constant Coefficients

Example I

Find the solution to recurrence relation an = 3an−1 + 2n with initialconditions a1 = 3.Solution:Step 1: find the solution for LHR2. The associated linear homo-

geneous equation is an = 3an−1. Its solution is a(h)n = α3n, where α

is a constant.

Step 2: find a particular solution. Let pn = cn + d be a particularsolution of the recurrence relation, where c and d are constants.Then, we have cn + d = 3(c(n − 1) + d) + 2n, that is (2 + 2c)n +(2d − 3c) = 0. It follows that cn + d is a solution if and only if2 + 2c = 0 and 2d − 3c = 0, i.e., c = −1 and d = −3/2.

Consequently, an = {a(p)n + a

(h)n } = −n− 3

2 +α · 3n. Using the initialconditions, it gives α = 11

6 . Thus,

an = (11

6)3n + n − 3

2.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 50 / 53

Page 115: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Solving Linear Recurrence Relations Solving LNR2 with Constant Coefficients

Example I

Find the solution to recurrence relation an = 3an−1 + 2n with initialconditions a1 = 3.Solution:Step 1: find the solution for LHR2. The associated linear homo-

geneous equation is an = 3an−1. Its solution is a(h)n = α3n, where α

is a constant.Step 2: find a particular solution. Let pn = cn + d be a particularsolution of the recurrence relation, where c and d are constants.Then, we have cn + d = 3(c(n − 1) + d) + 2n, that is (2 + 2c)n +(2d − 3c) = 0. It follows that cn + d is a solution if and only if2 + 2c = 0 and 2d − 3c = 0, i.e., c = −1 and d = −3/2.

Consequently, an = {a(p)n + a

(h)n } = −n− 3

2 +α · 3n. Using the initialconditions, it gives α = 11

6 . Thus,

an = (11

6)3n + n − 3

2.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 50 / 53

Page 116: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Solving Linear Recurrence Relations Solving LNR2 with Constant Coefficients

Example I

Find the solution to recurrence relation an = 3an−1 + 2n with initialconditions a1 = 3.Solution:Step 1: find the solution for LHR2. The associated linear homo-

geneous equation is an = 3an−1. Its solution is a(h)n = α3n, where α

is a constant.Step 2: find a particular solution. Let pn = cn + d be a particularsolution of the recurrence relation, where c and d are constants.Then, we have cn + d = 3(c(n − 1) + d) + 2n, that is (2 + 2c)n +(2d − 3c) = 0. It follows that cn + d is a solution if and only if2 + 2c = 0 and 2d − 3c = 0, i.e., c = −1 and d = −3/2.

Consequently, an = {a(p)n + a

(h)n } = −n− 3

2 +α · 3n. Using the initialconditions, it gives α = 11

6 . Thus,

an = (11

6)3n + n − 3

2.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 50 / 53

Page 117: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Solving Linear Recurrence Relations Solving LNR2 with Constant Coefficients

Forms of the particular solutions

Theorem: Suppose that {an} satisfies LNR2

an = c1an−1 + c2an−2 + · · ·+ ckan−k + F (n),

where c1, c2, · · · , ck are real numbers, and

F (n) = (btnt + bt−1n

t−1 + · · ·+ b1n + b0)sn,

where b0, b1, · · · , bt and s are real numbers.

If s is not a root of the characteristic equation of theassociated LHR2, there is a particular solution of form

(ptnt + pt−1nt−1 + · · ·+ p1n + p0)sn;

Else, s is a root of multiplicity m, the particular solution is ofform

nm(ptnt + pt−1nt−1 + · · ·+ p1n + p0)sn.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 51 / 53

Page 118: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Solving Linear Recurrence Relations Solving LNR2 with Constant Coefficients

Forms of the particular solutions

Theorem: Suppose that {an} satisfies LNR2

an = c1an−1 + c2an−2 + · · ·+ ckan−k + F (n),

where c1, c2, · · · , ck are real numbers, and

F (n) = (btnt + bt−1n

t−1 + · · ·+ b1n + b0)sn,

where b0, b1, · · · , bt and s are real numbers.

If s is not a root of the characteristic equation of theassociated LHR2, there is a particular solution of form

(ptnt + pt−1nt−1 + · · ·+ p1n + p0)sn;

Else, s is a root of multiplicity m, the particular solution is ofform

nm(ptnt + pt−1nt−1 + · · ·+ p1n + p0)sn.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 51 / 53

Page 119: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Solving Linear Recurrence Relations Solving LNR2 with Constant Coefficients

Forms of the particular solutions

Theorem: Suppose that {an} satisfies LNR2

an = c1an−1 + c2an−2 + · · ·+ ckan−k + F (n),

where c1, c2, · · · , ck are real numbers, and

F (n) = (btnt + bt−1n

t−1 + · · ·+ b1n + b0)sn,

where b0, b1, · · · , bt and s are real numbers.

If s is not a root of the characteristic equation of theassociated LHR2, there is a particular solution of form

(ptnt + pt−1nt−1 + · · ·+ p1n + p0)sn;

Else, s is a root of multiplicity m, the particular solution is ofform

nm(ptnt + pt−1nt−1 + · · ·+ p1n + p0)sn.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 51 / 53

Page 120: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Solving Linear Recurrence Relations Solving LNR2 with Constant Coefficients

Example II

Let an be the sum of the first n positive integers, i.e., an =∑n

k=1 ak .Solution: Note that an satisfies LNR2 an = an−1 + n.

Step 1: find the solution for LHR2. The associated linear homo-

geneous equation is an = an−1. Its solution is a(h)n = α1n = α, where

α is a constant.Step 2: find a particular solution. Since F (n) = n = n · (1)n, ands = 1 is a root of the characteristic equation of the associated LHR2.Thus, there is a particular solution n(cn + d) = cn2 + dn.Then, we have cn2 + dn = c(n − 1)2 + d(n − 1) + n, that is (2c −1)n + (c − d) = 0. It follows that cn + d is a solution if and only if2c − 1 = 0 and c − d = 0, i.e., c = d = 1

2 .

Consequently, an = {a(p)n + a

(h)n } = n(n+1)

2 + α. Using the initialconditions, it gives α = 0. Thus,

an =n(n + 1)

2.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 52 / 53

Page 121: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Solving Linear Recurrence Relations Solving LNR2 with Constant Coefficients

Example II

Let an be the sum of the first n positive integers, i.e., an =∑n

k=1 ak .Solution: Note that an satisfies LNR2 an = an−1 + n.Step 1: find the solution for LHR2. The associated linear homo-

geneous equation is an = an−1. Its solution is a(h)n = α1n = α, where

α is a constant.

Step 2: find a particular solution. Since F (n) = n = n · (1)n, ands = 1 is a root of the characteristic equation of the associated LHR2.Thus, there is a particular solution n(cn + d) = cn2 + dn.Then, we have cn2 + dn = c(n − 1)2 + d(n − 1) + n, that is (2c −1)n + (c − d) = 0. It follows that cn + d is a solution if and only if2c − 1 = 0 and c − d = 0, i.e., c = d = 1

2 .

Consequently, an = {a(p)n + a

(h)n } = n(n+1)

2 + α. Using the initialconditions, it gives α = 0. Thus,

an =n(n + 1)

2.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 52 / 53

Page 122: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Solving Linear Recurrence Relations Solving LNR2 with Constant Coefficients

Example II

Let an be the sum of the first n positive integers, i.e., an =∑n

k=1 ak .Solution: Note that an satisfies LNR2 an = an−1 + n.Step 1: find the solution for LHR2. The associated linear homo-

geneous equation is an = an−1. Its solution is a(h)n = α1n = α, where

α is a constant.Step 2: find a particular solution. Since F (n) = n = n · (1)n, ands = 1 is a root of the characteristic equation of the associated LHR2.Thus, there is a particular solution n(cn + d) = cn2 + dn.Then, we have cn2 + dn = c(n − 1)2 + d(n − 1) + n, that is (2c −1)n + (c − d) = 0. It follows that cn + d is a solution if and only if2c − 1 = 0 and c − d = 0, i.e., c = d = 1

2 .

Consequently, an = {a(p)n + a

(h)n } = n(n+1)

2 + α. Using the initialconditions, it gives α = 0. Thus,

an =n(n + 1)

2.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 52 / 53

Page 123: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Solving Linear Recurrence Relations Solving LNR2 with Constant Coefficients

Example II

Let an be the sum of the first n positive integers, i.e., an =∑n

k=1 ak .Solution: Note that an satisfies LNR2 an = an−1 + n.Step 1: find the solution for LHR2. The associated linear homo-

geneous equation is an = an−1. Its solution is a(h)n = α1n = α, where

α is a constant.Step 2: find a particular solution. Since F (n) = n = n · (1)n, ands = 1 is a root of the characteristic equation of the associated LHR2.Thus, there is a particular solution n(cn + d) = cn2 + dn.Then, we have cn2 + dn = c(n − 1)2 + d(n − 1) + n, that is (2c −1)n + (c − d) = 0. It follows that cn + d is a solution if and only if2c − 1 = 0 and c − d = 0, i.e., c = d = 1

2 .

Consequently, an = {a(p)n + a

(h)n } = n(n+1)

2 + α. Using the initialconditions, it gives α = 0. Thus,

an =n(n + 1)

2.

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 52 / 53

Page 124: Discrete Mathematics and Its Applications - …dase.ecnu.edu.cn/mgao/teaching/DM_2017_Fall/slides/... · Discrete Mathematics and Its Applications Lecture 4: Advanced Counting Techniques:

Take-aways

Take-aways

Conclusions

Applications of recurrence relations

Algorithms and recurrence relations

Solving linear recurrence relations

Solving LHR2

Solving LNR2

MING GAO (DaSE@ECNU) Discrete Mathematics and Its Applications Nov. 23, 2017 53 / 53