r. johnsonbaugh discrete mathematics 5 th edition, 2001 chapter 5 recurrence relations

24
R. Johnsonbaugh Discrete Mathematics 5 th edition, 2001 Chapter 5 Recurrence Relations

Upload: daniella-shelton

Post on 14-Dec-2015

295 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: R. Johnsonbaugh Discrete Mathematics 5 th edition, 2001 Chapter 5 Recurrence Relations

R. Johnsonbaugh

Discrete Mathematics5th edition, 2001

Chapter 5

Recurrence Relations

Page 2: R. Johnsonbaugh Discrete Mathematics 5 th edition, 2001 Chapter 5 Recurrence Relations

5.1 Introduction

A recurrence relation is an infinite sequence a1, a2, a3,…, an,…

in which the formula for the nth term an depends on one or more preceding terms,

with a finite set of start-up values or initial conditions

Page 3: R. Johnsonbaugh Discrete Mathematics 5 th edition, 2001 Chapter 5 Recurrence Relations

Examples of recurrence relations

Example 1: Initial condition a0 = 1

Recursive formula: a n = 1 + 2a n-1 for n > 2

First few terms are: 1, 3, 7, 15, 31, 63, …

Example 2: Initial conditions a0 = 1, a1 = 2

Recursive formula: a n = 3(a n-1 + a n-2) for n > 2

First few terms are: 1, 2, 9, 33, 126, 477, 1809, 6858, 26001,…

Page 4: R. Johnsonbaugh Discrete Mathematics 5 th edition, 2001 Chapter 5 Recurrence Relations

Fibonacci sequence

Initial conditions: f1 = 1, f2 = 2

Recursive formula: f n+1 = f n-1 + f n for n > 3

First few terms:

n 1 2 3 4 5 6 7 8 9 10 11

fn 1 2 3 5 8 13 21 34 55 89 144

Page 5: R. Johnsonbaugh Discrete Mathematics 5 th edition, 2001 Chapter 5 Recurrence Relations

Compound interest Given

P = initial amount (principal) n = number of years r = annual interest rate A = amount of money at the end of n years

At the end of: 1 year: A = P + rP = P(1+r) 2 years: A = P + rP(1+r) = P(1+r)2

3 years: A = P + rP(1+r)2 = P(1+r)3

Obtain the formula A = P (1 + r) n

Page 6: R. Johnsonbaugh Discrete Mathematics 5 th edition, 2001 Chapter 5 Recurrence Relations

Eugene Catalan Belgian mathematician, 1814-1894

Catalan numbers are generated by the formula:

Cn = C(2n,n) / (n+1) for n > 0 The first few Catalan numbers are:            

n 0 1 2 3 4 5 6 7 8 9 10 11

Cn 1 1 2 5 14 42 132 429 1430 4862 16796 58786

Page 7: R. Johnsonbaugh Discrete Mathematics 5 th edition, 2001 Chapter 5 Recurrence Relations

Catalan Numbers: applications The number of ways in which a polygon with n+2 sides

can be cut into n triangles The number of ways in which parentheses can be

placed in a sequence of numbers, to be multiplied two at a time

The number of rooted trivalent trees with n+1 nodes The number of paths of length 2n through an n by n

grid that do not rise above the main diagonal The number of nonisomorphic binary trees with n

vertices

Page 8: R. Johnsonbaugh Discrete Mathematics 5 th edition, 2001 Chapter 5 Recurrence Relations

Towers of Hanoi

Start with three pegs numbered 1, 2 and 3 mounted on a board, n disks of different sizes with holes in their centers, placed in order of increasing size from top to bottom.

Object of the game: find the minimum number of moves needed to have all n disks stacked in the same order in peg number 3.

Page 9: R. Johnsonbaugh Discrete Mathematics 5 th edition, 2001 Chapter 5 Recurrence Relations

Rules of the game: Hanoi towers

Start with all disks stacked in peg 1 with the smallest at the top and the largest at the bottom Use peg number 2 for intermediate steps Only a disk of smaller diameter can be placed

on top of another disk

Page 10: R. Johnsonbaugh Discrete Mathematics 5 th edition, 2001 Chapter 5 Recurrence Relations

End of game: Hanoi towers Game ends when all disks are stacked in peg

number 3 in the same order they were stored at the start in peg number 1.

Verify that the minimum number of moves needed is the Catalan number C3 = 5.

Start End

Page 11: R. Johnsonbaugh Discrete Mathematics 5 th edition, 2001 Chapter 5 Recurrence Relations

A problem in Economics Demand equation: p = a - bq Supply equation: p = kq There is a time lag as supply reacts to changes

in demand Use discrete time intervals as n = 0, 1, 2, 3,… Given the time delayed equations

pn = a – bqn (demand)

pn+1 = kqn+1 (supply)

The recurrence relation obtained is pn+1 = a – bpn /k

Page 12: R. Johnsonbaugh Discrete Mathematics 5 th edition, 2001 Chapter 5 Recurrence Relations

Economic cobweb with a stabilizing price

Page 13: R. Johnsonbaugh Discrete Mathematics 5 th edition, 2001 Chapter 5 Recurrence Relations

Ackermann’s function

Initial conditions:

A(0,n) = n + 1, for n = 0, 1, 2, 3,…

Recurrence relations:

A(m,0) = A(m – 1, 1), for m = 1, 2, 3,…

A(m,n) = A(m -1, A(m, n -1))

for m = 1, 2, 3,… and n = 1, 2, 3,…

Page 14: R. Johnsonbaugh Discrete Mathematics 5 th edition, 2001 Chapter 5 Recurrence Relations

5.2 Solving recurrence relations

Two main methods: Iteration Method for linear homogeneous recurrence

relations with constant coefficients

Page 15: R. Johnsonbaugh Discrete Mathematics 5 th edition, 2001 Chapter 5 Recurrence Relations

Method 1: Iteration

Problem: Given a recursive expression with initial conditions a0, a1

try to express an without dependence on previous terms.Example: an = 2an-1 for n > 1, with initial condition a0 = 1 Solution: an = 2n

Page 16: R. Johnsonbaugh Discrete Mathematics 5 th edition, 2001 Chapter 5 Recurrence Relations

More on the iteration method

Example: Deer Population growth Deer population dn at time n

Initial condition: d0 = 1000 Increase from time n-1 to time n is 10%.

Therefore the recursive function is

dn – dn-1 = 0.1dn-1

dn = 1.1dn-1

Solution: dn = 1000(1.1)n

Page 17: R. Johnsonbaugh Discrete Mathematics 5 th edition, 2001 Chapter 5 Recurrence Relations

Method 2: Linear homogeneous recurrence relations

Theorem 5.2.11: Given the second order linear homogeneous recurrence relation with constant coefficients

an = c1an-1 + c2an-2

and initial conditions a0 = C0, a1 = C1

1. If S and T are solutions then U = bS + dT is also a solution for any real numbers b, d

2. If r is a root of t2 – c1t – c2 = 0, then the sequence {rn}, n = 0, 1, 2,… is also a solution

Page 18: R. Johnsonbaugh Discrete Mathematics 5 th edition, 2001 Chapter 5 Recurrence Relations

Case 1: Two different roots

3. If r1 and r2 (r1 r2) are solutions of the quadratic equation t2 – c1t – c2 = 0, then there exist constants b and d such that

an = br1n + dr2

n

for n = 0, 1, 2, 3,…

Page 19: R. Johnsonbaugh Discrete Mathematics 5 th edition, 2001 Chapter 5 Recurrence Relations

More on linear homogeneous recurrence relations

Theorem 5.2.14: Let an = c1an-1 + c2an-2 be a second order linear homogeneous recurrence relation with constant coefficients.

Let a0 = C0, a1 = C1 be the first two terms of the sequence satisfying the recurrence relation.

Page 20: R. Johnsonbaugh Discrete Mathematics 5 th edition, 2001 Chapter 5 Recurrence Relations

Case 2: One root of multiplicity 2

If r is a root of multiplicity 2 satisfying the

equation

t2 – c1t – c2 = 0,

then: there exist constants b and d such that

an = brn + dnrn

for n = 0, 1, 2, 3,…

Page 21: R. Johnsonbaugh Discrete Mathematics 5 th edition, 2001 Chapter 5 Recurrence Relations

5.3 Applications to the analysis of algorithms

1. Selection sorting

a) Given a sequence of n terms ak, k = 1, 2,…, n to be arranged in increasing order

b) Count the number of comparisons bn with initial condition b1 = 0

c) Obtain recursion relation bn = n – 1 + bn-1 for n = 1, 2, 3,…

d) bn = n(n-1)/2 = (n2)

Page 22: R. Johnsonbaugh Discrete Mathematics 5 th edition, 2001 Chapter 5 Recurrence Relations

Binary search

2. Problem: Search for a value in an increasing sequence. Return the index of the value, or 0 if not found.

Initial condition a1 = 2

Recurrence relation an = 1 + an/2

Result: an = (lg n)

Page 23: R. Johnsonbaugh Discrete Mathematics 5 th edition, 2001 Chapter 5 Recurrence Relations

Merging two sequences

3. Problem: Combine two increasing sequences into a single increasing sequence (merge two sequences).

Theorem 5.3.7: To merge two sequences the sum of whose lengths is n, the number of comparisons required is n-1.

Page 24: R. Johnsonbaugh Discrete Mathematics 5 th edition, 2001 Chapter 5 Recurrence Relations

Merge sort4. A recursive algorithm is used to sort

a sequence into increasing order using the algorithm for merging two increasing sequences into one increasing sequence (merge sort).

Theorem 5.3.10: The merge sort algorithm is (n lg n) in the worst case.