Agenda Lecture Content: Recurrence Relations Solving Recurrence Relations Iteration Linear...

39
Agenda Lecture Content: Recurrence Relations Solving Recurrence Relations Iteration Linear homogenous recurrence relation of order k with constant coefficients Exercise

Transcript of Agenda Lecture Content: Recurrence Relations Solving Recurrence Relations Iteration Linear...

Page 1: Agenda Lecture Content:  Recurrence Relations  Solving Recurrence Relations  Iteration  Linear homogenous recurrence relation of order k with constant.

Agenda

• Lecture Content: Recurrence Relations Solving Recurrence Relations

Iteration Linear homogenous recurrence relation of order k with

constant coefficients

• Exercise

Page 2: Agenda Lecture Content:  Recurrence Relations  Solving Recurrence Relations  Iteration  Linear homogenous recurrence relation of order k with constant.

Recurrence Relations

Page 3: Agenda Lecture Content:  Recurrence Relations  Solving Recurrence Relations  Iteration  Linear homogenous recurrence relation of order k with constant.

Recurrence Relations

Relates the n-th element of a sequence to its predecessors.

Example: an = 9 * an-1

Closely related to recursive algorithms.Suited for analysis of algorithm

Page 4: Agenda Lecture Content:  Recurrence Relations  Solving Recurrence Relations  Iteration  Linear homogenous recurrence relation of order k with constant.

Recurrence Relations

Generate a sequence :1. Start with 52. Given any term, add 3 to get the next term 5, 8, 11, 14, …

Sequence {an} = a0, a1, …, an-1, an 1. a0= 5 initial condition2. an = an-1 + 3 , n ≥ 1 recurrence relation

Page 5: Agenda Lecture Content:  Recurrence Relations  Solving Recurrence Relations  Iteration  Linear homogenous recurrence relation of order k with constant.

Recurrence Relations for the sequence {an}

is an equation that expresses an in terms of one or more of the previous terms of the sequence, namely, a0, a1, …, an-1 for all integers n with n ≥ n0, where n0 is a nonnegative integer.

A sequence {an} is called a solution of a recurrence relation if its terms an satisfy the recurrence relation.

Page 6: Agenda Lecture Content:  Recurrence Relations  Solving Recurrence Relations  Iteration  Linear homogenous recurrence relation of order k with constant.

Motivation

One of the main reason for using recurrence relation is that sometimes it is easier to determine the n-th term of a sequence in terms of its predecessors than it is to find an explicit formula for the n-th term in terms of n.

Page 7: Agenda Lecture Content:  Recurrence Relations  Solving Recurrence Relations  Iteration  Linear homogenous recurrence relation of order k with constant.

Example

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

a2 = a1 – a0 = 5 – 3 = 2 a3 = a2 – a1 = 2 – 5 = -3 Also a4, a5, …

Page 8: Agenda Lecture Content:  Recurrence Relations  Solving Recurrence Relations  Iteration  Linear homogenous recurrence relation of order k with constant.

Exercises

Find the first six terms of the sequence defined by the following recurrence relations:

an = an-1 + an-3

a0 = 1, a1 = 2, a2 = 0

an = n. an-1 + (an-2)2

a0 = -1, a1 = 0

Page 9: Agenda Lecture Content:  Recurrence Relations  Solving Recurrence Relations  Iteration  Linear homogenous recurrence relation of order k with constant.

Example

Find the recurrence relation of:- {an} = (0, 1, 2, 3, …)- {an} = (5, 10, 15, 20, …)

Find the first three terms of the sequence defined by the following recurrence relations:- an = 3 * an-1 – an-2 a0 = 3 and a1 = 5- an = an-1 – an-2 + an-3

a0 = 3, a1 = 5 and a2 = 5

Page 10: Agenda Lecture Content:  Recurrence Relations  Solving Recurrence Relations  Iteration  Linear homogenous recurrence relation of order k with constant.

Modelling with Recurrence Relations (1)

The number of bacteria in a colony doubles every hour. If a colony begins with five bacteria, how many will be present in n hours?- a0 = 5- a1 = 10- a2 = 20- …

The number of bacteria at the end of n hours: an = 2 * an-1

Page 11: Agenda Lecture Content:  Recurrence Relations  Solving Recurrence Relations  Iteration  Linear homogenous recurrence relation of order k with constant.

Modelling with Recurrence Relations (2)

Suppose that a person deposits $ 10,000 in a saving account at a bank yielding 11% per year with interest compounded annually. How much will be in the account after 30 years?

• Pn : the amount in the account after n years• Pn = Pn-1 + 0.11 Pn-1 = 1.11 Pn-1• P0 = 10,000• P1 = 1.11 P0• P2 = 1.11 P1 = 1.11 * 1.11 P0 = (1.11)2 P0• Pn = (1.11)n P0 Pn = (1.11)n P0

Deriving explicit formula from the recurrence relation and its initial condition (Section 7.2)

Page 12: Agenda Lecture Content:  Recurrence Relations  Solving Recurrence Relations  Iteration  Linear homogenous recurrence relation of order k with constant.

Converting to a Recursive Algorithm

A recursive function is a function that invokes itself. A recursive algorithm is an algorithm that contains a

recursive function

Input: n, the number of yearsOutput: the amount of money at the end of n years

1. compound_interest (n){2. if (n == 0)3. return 10,0004. return 1.11 * compound_interest (n-1)5. }

Page 13: Agenda Lecture Content:  Recurrence Relations  Solving Recurrence Relations  Iteration  Linear homogenous recurrence relation of order k with constant.

Modeling with Recurrence Relation (3)

A young pair of rabbits is placed on an island. A pair of rabbit does not breed until they are 2 months old. After they are 2 months old, each pair of rabbits produces another pair each month. Find a recurrence relation for the number of pairs of rabbit on the island after n months, assuming that no rabbits ever die.

fn : the number of pairs of rabbits after n months

Page 14: Agenda Lecture Content:  Recurrence Relations  Solving Recurrence Relations  Iteration  Linear homogenous recurrence relation of order k with constant.

Modeling with Recurrence Relation (3)

Month reproducing pairs young pairs total pairs1 0 1 12 0 1 13 1 1 24 1 2 35 2 3 56 3 5 8

Page 15: Agenda Lecture Content:  Recurrence Relations  Solving Recurrence Relations  Iteration  Linear homogenous recurrence relation of order k with constant.

Modeling with Recurrence Relation (3)

fn : the number of pairs of rabbits after n months

f1 = 1 f2 = 1 f3 = 2 fn = the number on the island for the previous

month + the number of newborn pairs fn = fn-1 + fn-2

Fibonacci Numbers

Page 16: Agenda Lecture Content:  Recurrence Relations  Solving Recurrence Relations  Iteration  Linear homogenous recurrence relation of order k with constant.

Modelling with Recurrence Relation (4)

Find a recurrence relation and give initial conditions for the number of bit strings of length n that do not have two consecutives 0s.

an : the number of bit strings of length n that do not have two consecutive 0s.

Page 17: Agenda Lecture Content:  Recurrence Relations  Solving Recurrence Relations  Iteration  Linear homogenous recurrence relation of order k with constant.

The Tree Diagrams

How many bit strings of length four do not have two consecutive 0s?

bit ke-1 bit ke-2 bit ke-3 bit ke-4

11

1111

00

1100

1100 11 00

11

00 1111 11

0000

11

There are eight bit strings

Page 18: Agenda Lecture Content:  Recurrence Relations  Solving Recurrence Relations  Iteration  Linear homogenous recurrence relation of order k with constant.

Modelling with Recurrence Relation (4)

an = an-1 + an-2 for n ≥ 3

a1 = 2 0, 1a2 = 3 (01, 10, 11)a3 = 5 (011, 010, 101, 110, 111)a4 = 8

Page 19: Agenda Lecture Content:  Recurrence Relations  Solving Recurrence Relations  Iteration  Linear homogenous recurrence relation of order k with constant.

Solving Recurrence Relations

Page 20: Agenda Lecture Content:  Recurrence Relations  Solving Recurrence Relations  Iteration  Linear homogenous recurrence relation of order k with constant.

Solving Recurrence Relations

- Given recurrence relations with sequence: a0 , a1 , …

- Find an explicit formula for the general term:

an

- Two methods:- Iteration- Recurrence relations with constant coefficients

Page 21: Agenda Lecture Content:  Recurrence Relations  Solving Recurrence Relations  Iteration  Linear homogenous recurrence relation of order k with constant.

Iteration

Steps:- Use the recurrence relation to write the n-th

term an in terms of certain of its predecessors an-1 , …, a0

- Use the recurrence relation to replace each of an-1 , … by certain of their predecessors.

- Continue until an explicit formula is obtained.

Page 22: Agenda Lecture Content:  Recurrence Relations  Solving Recurrence Relations  Iteration  Linear homogenous recurrence relation of order k with constant.

Iteration: Example 1

an = an-1 + 3 n ≥ 1

a0= 5

Solution:

- an-1 = an-2 + 3

- an = an-1 + 3 = (an-2 + 3) + 3 = an-2 + 2.3

= (an-3 + 3) +2.3 = an-3 + 3.3

= an-k + k.3

… k = n

= a0 + n . 3

= 5 + n . 3

Page 23: Agenda Lecture Content:  Recurrence Relations  Solving Recurrence Relations  Iteration  Linear homogenous recurrence relation of order k with constant.

Iteration: Example 2(1)

The number of bacteria in a colony doubles every hour. If a colony begins with five bacteria, how many will be present in n hours?

a0 = 5 a1 = 10 a2 = 20 … The number of bacteria at the end of n

hours: an = 2 * an-1

Page 24: Agenda Lecture Content:  Recurrence Relations  Solving Recurrence Relations  Iteration  Linear homogenous recurrence relation of order k with constant.

Iteration: Example 2(2)

an = 2 * an-1

= 2 * (2 * an-2 ) = 2 * 2 ( an-2 )

= 2 * 2 * (2 * an-3 ) = 23 ( an-3 )

= 2n * a0

= 2n * 5

Page 25: Agenda Lecture Content:  Recurrence Relations  Solving Recurrence Relations  Iteration  Linear homogenous recurrence relation of order k with constant.

Iteration: Example 3

The deer population is 1000 at time n = 0 The increase from time n-1 to time n is 10 percent. Find the recurrence relation, initial condition and solve

the recurrence relation at time n

a0 = 1000 an = 1.1 * an-1

an = 1.1 * (1.1 * an-2) = 1.12 * an-2

an = 1.1n * a0 an = 1.1n * 1000

Page 26: Agenda Lecture Content:  Recurrence Relations  Solving Recurrence Relations  Iteration  Linear homogenous recurrence relation of order k with constant.

Recurrence Relations with Constant Coefficients

Page 27: Agenda Lecture Content:  Recurrence Relations  Solving Recurrence Relations  Iteration  Linear homogenous recurrence relation of order k with constant.

Definition

A linear homogeneous recurrence relation of order k with constant coefficients is a recurrence relation of the form:

an = c1an–1+ c2an–2+ … + ckan–k , ck ≠ 0

Example:

• Sn = 2Sn–1

• fn = fn–1 + fn–2

Page 28: Agenda Lecture Content:  Recurrence Relations  Solving Recurrence Relations  Iteration  Linear homogenous recurrence relation of order k with constant.

Not linear homogenous recurrence relations

Example:

• an = 3an–1an–2

• an – an–1 = 2n

• an = 3nan–1

Why?

Page 29: Agenda Lecture Content:  Recurrence Relations  Solving Recurrence Relations  Iteration  Linear homogenous recurrence relation of order k with constant.

Solving Recurrence Relations

Example:• Solve the linear homogeneous recurrence

relations with constant coefficients

an = 5an–1 – 6an–2

a0 = 7, a1= 16

Solution:• Often in mathematics, when trying to solve a

more difficult instance of some problem, we begin with an expression that solved a simpler version.

Page 30: Agenda Lecture Content:  Recurrence Relations  Solving Recurrence Relations  Iteration  Linear homogenous recurrence relation of order k with constant.

Solving Recurrence Relations

For the first-order recurrence relation, the solution was of the form Vn= tn ; thus for our first attempt at finding a solution of the second-order recurrence relation, we will search for a solution of the form Vn= tn.

If Vn = tn is to solve the recurrence relation, we must have Vn= 5Vn–1–6Vn–2 or tn = 5tn–1 – 6tn–2 or tn – 5tn–1+ 6tn–2 = 0. Dividing by tn–2, we obtain the equivalent equation t2 – 5t1 + 6 = 0. Solving this, we find the solutions t= 2, t= 3. Characteristic

polynomialCharacteristic roots

Page 31: Agenda Lecture Content:  Recurrence Relations  Solving Recurrence Relations  Iteration  Linear homogenous recurrence relation of order k with constant.

Solving Recurrence Relations

We thus have two solutions, Sn = 2n and Tn = 3n.

• We can verify that if S and T are solutions of the preceding recurrence relation, then bS + dT, where b and d are any numbers, is also a solution of that relation. In our case, if we define the sequence U by the equation

Un = bSn+ dTn = b2n + d3n,

U is a solution of the given relation.

Page 32: Agenda Lecture Content:  Recurrence Relations  Solving Recurrence Relations  Iteration  Linear homogenous recurrence relation of order k with constant.

Solving Recurrence Relations

To satisfy the initial conditions, we must have:

7 = U0 = b20 + d30= b + d,

16 = U1= b21+ d31= 2b + 3d.

Solving these equations for b and d, we obtain b = 5, d = 2.

Therefore, the sequence U defined by Un= 5∙2n + 2∙3n satisfies the recurrence relation and the initial conditions.

We conclude that an= Un= 5∙2n+ 2∙3n, for n = 0, 1, ….

Page 33: Agenda Lecture Content:  Recurrence Relations  Solving Recurrence Relations  Iteration  Linear homogenous recurrence relation of order k with constant.

Theorem

Let an = c1an–1+ c2an–2 be a second-order, linear homogeneous recurrence relation with constant coefficients. • If S and T are solutions of the recurrence relation,

then U = bS+ dT is also a solution of the relation.

• If r is a root of t2–c1t–c2= 0, then the sequence rn, n = 0, 1, …, is a solution of the recurrence relation.

• If a is the sequence defined by the recurrence relation, a0 = C0, a1= C1, and r1 and r2 are roots of the preceding equation with r1 ≠ r2, then there exist constants b and d such that an= br1

n + dr2n, n = 0, 1, ….

Page 34: Agenda Lecture Content:  Recurrence Relations  Solving Recurrence Relations  Iteration  Linear homogenous recurrence relation of order k with constant.

Example (1)

More Population Growth• Assume that the deer population of Rustic

County is 200 at time n = 0 and 220 at time n = 1 and that the increase from time n–1 to time n is twice the increase from time n–2 to time n–1.

• Write a recurrence relation and an initial condition that define the deer population at time n and then solve the recurrence relation.

Page 35: Agenda Lecture Content:  Recurrence Relations  Solving Recurrence Relations  Iteration  Linear homogenous recurrence relation of order k with constant.

Example (1)

Solution:• Let dn denote the deer population at time n.

d0 = 200, d1 = 220

dn – dn-1 = 2(dn-1 – dn-2)

dn = 3dn-1 – 2dn-2

• Solving t2 – 3t + 2 = 0, we have roots 1 and 2. Then the sequence d is of the form dn = b∙1n + c∙2n = b + c2n.

• To meet the initial conditions, we must have 200 = d0= b + c, 220 = d1= b + 2c. Solving for b and c, we find b= 180, and c= 20.

• Thus, dn is given by dn = 180 + 20∙2n.

Page 36: Agenda Lecture Content:  Recurrence Relations  Solving Recurrence Relations  Iteration  Linear homogenous recurrence relation of order k with constant.

Example (2)

Find an explicit formula for the Fibonacci sequence:

fn – fn–1 – fn–2= 0, n≥ 3

f1 = 1, f2 = 1

Solution:•We begin by using the quadratic formula to solve t2 –t – 1 = 0. The solutions are t = (1 ±√5)/2. Thus the solution is of the form fn= b((1+√5)/2)n + c((1–√5)/2)n.

–To satisfy the initial conditions, we must have b((1+√5)/2) + c((1–√5)/2)= 1, b((1+√5)/2)2+ c((1–√5)/2)2= 1. Solving these equations for b and d, we obtain b = 1/√5, d = -1/√5.

• •Therefore, fn= 1/√5∙((1+√5)/2)n – 1/√5((1–√5)/2)n.

Page 37: Agenda Lecture Content:  Recurrence Relations  Solving Recurrence Relations  Iteration  Linear homogenous recurrence relation of order k with constant.

Theorem

Let an = c1an–1 + c2an–2 be a second-order, linear homogeneous recurrence relation with constant coefficients. • Let a be the sequence satisfying the relation

and a0 = C0, a1= C1.

• If both roots of t2 – c1t – c2 = 0 are equal to r, then there exist constants b and d such that an = brn + dnrn, n = 0, 1, ….

Page 38: Agenda Lecture Content:  Recurrence Relations  Solving Recurrence Relations  Iteration  Linear homogenous recurrence relation of order k with constant.

Example

Solve the recurrence relation dn= 4(dn-1 – dn-2) subject to the initial conditions d0= 1 = d1.

– According to the theorem, Sn= rn is a solution, where r is a solution of t2 – 4t + 4 = 0. Thus we obtain the solution Sn = 2n.

– Since 2 is the only solution of the equation, Tn= n2n is also a solution of the recurrence relation.

– Thus the general solution is of the form U = aS+ bT. – We must have U0 = 1 = U1. The last equations become

aS0 + bT0= a+ 0b= 1, aS1+ bT1= 2a+ 2b = 1.

– Solving for a and b, we obtain a = 1, b = -1/2. – Therefore,

the solution is dn= 2n – 1/2n2n = 2n – n2n-1 .

Page 39: Agenda Lecture Content:  Recurrence Relations  Solving Recurrence Relations  Iteration  Linear homogenous recurrence relation of order k with constant.

Note

For the general linear homogeneous recurrence relation of order k with constant coefficients c1, c2, …, ck,

• if r is a root of

tk – c1tk-1 – c2tk-2 – … – ck = 0

of multiplicity m, it can be shown that

rn, nrn, … , nm-1rn are solutions of the equation.