1 recurrence 1. sequence 2. recursively defined sequence 3. finding an explicit formula for...

37
1 RECURRENCE 1. Sequence 2. Recursively defined sequence 3. Finding an explicit formula for recurrence relation

Upload: veronica-warner

Post on 01-Jan-2016

255 views

Category:

Documents


0 download

TRANSCRIPT

1

RECURRENCE

1. Sequence2. Recursively defined sequence3. Finding an explicit formula for

recurrence relation

2

Learning Outcomes

You should be able to solve first-order and second-order linear

homogeneous recurrence relation with constant coefficients

3

Preamble

What is recurrence and how does it relate to a sequence?

4

Sequences A sequence is an ordered list of objects (or events).

Like a set, it contains members (also called terms) Sequences can be finite or infinite.

2,4,6,8,… for i ≥ 1 ai = 2i (explicit formula)infinite sequence with infinite distinct values

-1,1,-1,1,… for i ≥ 1 bi = (-1)i infinite sequence with finite distinct values

For 1<=i<=6 ci = i+5 finite sequence (with finite distinct values)6,7,8,9,10,11

5

Ways to define sequence

Write the first few terms: 3,5,7,… Use explicit formula for its nth term an = 2n for n ≥ 1 Use recursion How to define a sequence using a

recursion?

6

Recursively defined sequencesRecursion can be used to defined a sequence.This requires:A recurrence relation: a formula that relates each term ak

to some previous terms ak-1, ak-2, … ak = ak-1 + 2ak-2

The initial conditions: the values of the first few terms a0, a1, …

Example: For all integers k ≥ 2, find the terms b2, b3 and b4: bk = bk-1 + bk-2 (recurrence relation) b0 = 1 and b1 = 3 (initial conditions)Solution:b2 = b1 + b0 = 3 + 1 = 4b3 = b2 + b1 = 4 + 3 = 7b4 = b3 + b2 = 7 + 4 = 11

7

Explicit formula and recurrence relation Show that the sequence 1,-1!,2!,-3!,4!,…,(-1)nn!,

… for n≥0, satisfies the recurrence relation sk = (-k)sk-1 for all integers k≥1. The general term of the sequence: sn=(-1)nn! substitute k and k-1 for n to get sk=(-1)kk! sk-1=(-1)k-1(k-1)! Substitute sk-1 into recurrence relation: (-k)sk-1 = (-k)(-1)k-1(k-1)! = (-1)k(-1)k-1(k-1)! = (-1)(-1)k-1 k(k-1)! = (-1)k k! = sk

8

Examples of recursively sequence Famous recurrences Arithmetic sequences: ak = ak-1 + de.g. 1,4,7,10,13,…geometric sequences: ak = ark-1

e.g. 1,3,9,27,… Factorial: f(n) = n . f(n-1) Fibonacci numbers: fk = fk-1+fk-2

1,1,2,3,5,8,…Tower of Hanoi problem

9

Tower of Hanoi

10

11

12

13

Application of recurrence Analysis of algorithm containing recursive function such

as factorial function.

Algorithm f(n) /input: A nonnegative integer /output: The value of n! If n = 0 return 1 else return f(n-1)*n

No. of operations (multiplication) determines the efficiency of algo.

Recurrence relation is used to express the no. of operation in the algorithm.

14

Solving Recurrence relation by Iteration It is helpful to know an explicit formula

for a sequence. An explicit formula is called a solution

to the recurrence relation Most basic method is iteration - start from the initial condition - calculate successive terms until a

pattern can be seen - guess an explicit formula

15

Some examplesLet a0,a1,a2,… be the sequence defined recursively as

follows: For all integers k≥1,(1) ak = ak-1+2(2) a0 = 1Use iteration to guess an explicit formula for the sequence.a0=1a1=a0+2a2=a1+2=(1+2)+2 = 1+2.2a3=a2+2=(1+2.2)+2 = 1+3.2a4=a3+2=(1+3.2)+2 = 1+4.3….Guess: an=1+n.2=1+2nThe above sequence is an arithmetic sequence.

16

Geometric SequenceLet r be a fixed nonzero constant, and suppose a sequence

a0,a1,a2,… is defined as follows: ak = rak-1 for all integers k ≥ 1 a0 = aUse iteration to guess an explicit formula for the sequence a0=a a1=ra0=ra a2=ra1=r(ra)=r2a a3=ra2=r(r2a)=r3a Guess: an=rna = arn for all integers n≥0The above sequence is geometric sequence and r is a

common ratio.

17

18

Explicit formula for tower of Hanoi

mn = 2n – 1. (exponential order) To move 1 disk takes 1 second m64 = 264 –1 = 1.844674 * 1019

seconds = 5.84542 * 1011

years = 584.5 billion years.

19

Second-Order Linear Homogeneous with constant coefficients

A second-order linear homogeneous recur. relation with c.c. is a recur. relation of the form

ak = Aak-1 + Bak-2 for all integers k ≥ some fixed integer,

where A and B are fixed real numbers with B ≠ 0.

20

Terminology ak = Aak-1 + Bak-2

Second order: ak contains the two previous terms

Linear: ak-1 and ak-2 appear in separate terms and to the first power

Homogeneous: total degree of each term is the same (no constant term)

Constant coefficients: A and B are fixed real numbers

21

Examples Second-Order Linear Homogeneous with

constant coefficients ak = 3ak-1 + 2ak-2 - yes. bk = bk-1 + bk-2 + bk-3 - no dk = (dk-1)2 + dk-1dk-2 - no; not linear ek = 2ek-2 - yes; A = 0, B = 2. fk = 2fk-1 + 1 - no; not homogeneous

22

Characteristic equationak = Aak-1 + Bak-2 for k>=2 ….. (1)Suppose that sequence 1, t, t2, t3,… satisfies relation (1) where t is a nonzero real number. General term for the sequence an=tn.Hence, ak-1=tk-1 and ak-2= tk-2

Substitute ak-1 and ak-2 into relation (1)tk = Atk-1 + Btk-2

Divide the equation by tk-2:t2 = At + B or t2 – At – B = 0 This equation is called the characteristic equation of therelation. Recurrence relation (1) is satisfied by the sequence 1,t,t2,t3,… iff t satisfies the characteristic equation.

23

Using the characteristic equation to find sequences Example: Consider the following recurrence relationak = ak-1+2ak-2 for all k >= 2.Find sequences that satisfy the relation.Solution: For the given relation, A=1 and B=2.Relation is satisfied by the sequence 1,t,t2,t3,… iff t

satisfies the characteristic equation t2 – At – B = 0 ort2 – t – 2 = 0(t – 2)(t + 1) = 0.t = 2 or t = -1. Sequences: 1,2,22,23,… and 1,-1,(-1)2,(-1)3, … or 1,-1,1,-1, …,(-1)n, …

24

Linear combination of sequences LemmaIf r0,r1,r2,…,rn,.. and s0,s1,s2,…,sn,… are sequences

that satisfy the same second-order linear homogeneous recurrence relation with c.c., and if C and D are any numbers, then the sequence a0,a1,a2,…

defined by the formula an = C.rn + D.sn for all integer n>=0 also satisfies the same recurrence relation. C and D can be calculated using initial

conditions.

25

Two possible solutions

For the characteristic equation t2 – At – B = 0 there are two possible solutions: - Distinct-roots case - Single-root case

26

Explicit formula for second-order relation – Distinct-roots case

Find a sequence (explicit formula) that satisfies the recurrence relation

ak=ak-1 + 2ak-2 for k>=2 and initial conditions a0=1 and a1=8Solution: A=1 and B=2. Characteristic equation : t2 – At – B =0 Substitute A and B, t2 – t – 2 = 0 Sequences: 1,2,22,23,… and 1,-1,1,-1, …,(-1)n, …

27

28

Steps for finding explicit formula

1. Form the characteristic equation.2. Solve the equation – let r and s be

the roots. ( r ≠ s)3. Set up an explicit formula: ak = C.rk + D.sk

4. Find C and D using initial conditions.

29

30

31

32

Single-Root Case

Two sequences that satisfy the relation ak = A.ak-1+B.ak-2

S1: 1,r,r2,r3,…,rn,…

S2: 0,r,2r2,3r3,…,nrn,…

where r is the root of t2 - A.t - B = 0. Explicit formula for the new sequence ak

= C.rk + D.nrn

33

Example A sequence b0, b1, b2,… satisfies the rec. relation

bk = 4bk-1 – 4bk-2 for k>=2 with initial conditions b0=1 and b1=3.

Find explicit formula for the sequence.Solution: A=4 and B=-4Charac eq: t2 – 4t +4 =0 (t-2)2=0. t=2.Seq: 1,2,22, …, 2n,.. 0,2,2.22,3.23,…,n.2n,… Explicit formula: bn

= C.rn + D.nrn = C.2n + D.n2n

34

Example bn = C.2n + D.n2n

b0 = 1 = C + D.0 = C b1 = 3 = C.2 + D.2 Hence D = ½. Therefore bn = 2n + (1/2).n.2n

= 2n (1+ n/2) for integer n>=0.

35

Question

?????

36

Summary

How to express the sequence Find explicit formula for first-order

relation Find explicit formula for second-

order relation (distinct and single root)

37

THANK YOU