Discrete Structures Chapter 6 Recurrence Relations Nurul Amelina Nasharuddin Multimedia Department.

36
Discrete Structures Chapter 6 Recurrence Relations Nurul Amelina Nasharuddin Multimedia Department
  • date post

    20-Dec-2015
  • Category

    Documents

  • view

    220
  • download

    1

Transcript of Discrete Structures Chapter 6 Recurrence Relations Nurul Amelina Nasharuddin Multimedia Department.

Discrete StructuresChapter 6

Recurrence RelationsNurul Amelina Nasharuddin

Multimedia Department

2

Objectives

On completion of this topic, student should be able to:

a. Solve first-order linear homogeneous recurrence relation

b. Solve second-order linear with constant coefficients

Outline

• First-order linear homogeneous recurrence relation

• Second-order linear with constant coefficients• Divide and conquer algorithm example

3

4

• 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

Sequence

5

Ways to Define Sequence

1. Write the first few terms: 3,5,7,…

2. Use explicit formula for its nth term an = 2n for n ≥ 1

3. Use recursion. How to define a sequence using a recursion?

6

• Recursion 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, …

Recursively Defined Sequences

7

• 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

Example

8

• Eg: Show that the sequence 1, -1!, 2!, -3!, 4!,…, (-1)n n!, … for n ≥ 0, satisfies the recurrence relation

sk = (-k)sk-1 for all integers k ≥ 1The general term of the sequence: sn=(-1)n n!

• 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

Explicit Formula and Recurrence Relation

9

Examples of Recursively Sequence

• Famous recurrences 1. Arithmetic sequences: ak = ak-1 + d

e.g. 1,4,7,10,13,…2. Geometric sequences: ak = ark-1

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

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

10

11

12

13

14

Application of RecurrenceFactorial Notation

• 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 1else return f(n-1)*n

• No. of operations (multiplication) determines the efficiency of algorithm

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

15

Solving Linear Recurrence Relations 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 to find explicit formula is iteration− start from the initial condition− calculate successive terms until a pattern can be

seen− guess an explicit formula

16

Example of Arithmetic Sequence (pg 476)

• Let a0, a1, a2,… be the sequence defined recursively as follows:

(1) ak = ak-1+2 for all integers k ≥ 1(2) a0 = 1

• Use iteration to guess an explicit formula for the sequencea0 =1a1 =a0+2=1+2 a2 =a1+2=(1+2)+2 = 1+2+2 = 1+2.2a3 =a2+2=(1+2+2)+2 = 1+2+2+2 = 1+3.2a4 =a3+2=(1+2+2+2)+2 = 1+2+2+2+2 = 1+4.2….

• Guess: an = 1+ n.2 = 1 + 2n

• The above sequence is an arithmetic sequence

17

Arithmetic Sequence

• A sequence a0, a1, a2, … is called arithmetic sequence iff there is a constant d such that

ak = ak-1 + d for all integers k 1

or equivalently

an = a0 + dn for all integers n 0

18

Example of Geometric Sequence• Let r be a fixed nonzero constant, and suppose a sequence

a0,a1,a2,… is defined as follows:(1) ak = rak-1 for all integers k ≥ 1(2) a0 = a

• Use iteration to guess an explicit formula for the sequencea0=aa1=ra0 =raa2=ra1 =r(ra) =r2aa3=ra2 =r(r2a) =r3a…

• Guess: an= rna = arn for all integers n≥0

• The above sequence is geometric sequence and r is a common ratio

19

Geometric Sequence

• A sequence a0, a1, a2, … is called geometric sequence iff there is a constant r such that

ak = rak-1 for all integers k 1

or equivalently

an = a0rn for all integers n 0

20

21

Second-Order Linear Homogeneous with Constant

Coefficients• A second-order linear homogeneous recurrence relation with constant coefficients is a recurrence 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

22

Terminology

ak = Aak-1 + Bak-2

• Second order: ak contains the two previous terms (ak-1 and ak-2)

• 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

23

Example

• Second-Order Linear Homogeneous with constant coefficients

ak = 3ak-1 + 2ak-2 (Yes)bk = bk-1 + bk-2 + bk-3 (No, not second order)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)

24

Characteristic equation• ak = Aak-1 + Bak-2 for k 2 ….. (1)

Suppose that sequence 1, t, t2, t3,…, tn,.. 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

25

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=2Relation 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, …

26

Linear Combination of Sequences

• Lemma

If r0, r1, r2,…, rn,.. and s0, s1, s2,…, sn,… are sequences that satisfy the same second-order linear homogeneous recurrence relation with constant coefficients, and if C and D are any numbers, then the sequence a0, a1, a2,…defined by the formulaan = C.rn + D.sn for all integer n 0 also satisfies the same recurrence relation and D can be calculated using initial conditions

27

Two Possible Solutions

• For the characteristic equation t2 – At – B = 0there are two possible solutions:

1. Distinct-roots case2. Single-root case

28

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 2and initial conditions

a0=1 and a1=8

• Solution:A=1 and B=2Characteristic equation : t2 – At – B =0Substitute A and B, t2 – t – 2 = 0Sequences: 1,2,22,23,… and 1,-1,1,-1, …,(-1)n,

29

30

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.

31

32

33

34

Single-Root Case

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

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

an = C.rn + D.nrn

35

Example (1)

• A sequence b0, b1, b2,… satisfies the reccurence 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 = -4Characteristic equation: t2 – 4t +4 =0

(t-2)2=0; t=2Sequence: 1,2,22, …, 2n,.. 0,2,2.22,3.23,…,n.2n,…

36

Example (1)

• Explicit formula: bn = C.rn + D.nrn

= C.2n + D.n2n

• bn = C.2n + D.n2n

n=0, b0 = 1 = C.20 + D.0.20 = Cn=1, b1 = 3 = C.2 + D.2

3 = 1.2 + 2DD = ½

• Therefore bn = 2n + (½).n.2n

= 2n (1+ n/2) for integer n 0• Sequence: 1,3,8,20,…