0% found this document useful (0 votes)
52 views26 pages

8.recurrence Relations

Uploaded by

rgn12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views26 pages

8.recurrence Relations

Uploaded by

rgn12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 26

Recurrence Relations

Learning Objectives
 Learn about recurrence relations
 Learn the relationship between sequences and
recurrence relations
 Explore how to solve recurrence relations by
iteration
 Learn about linear homogeneous recurrence
relations and how to solve them
 Become familiar with linear nonhomogeneous
recurrence relations

2
Useful Facts
 Arithmetic series
n(n  1)
1  2  3   n 
2
 More generally, if an= an-1 +c, where c is a
constant, then
n(an  a1 )
a1  a2  a3   an 
2

3
Useful Facts
 Geometric series

1  2  4    2 n 2 n 1  1
 More generally, if an= can-1 ,where c≠1 is a
constant, then
cn  1
a1  a2  a3    an a1
c 1
 If 0< c< 1, then the sum of the infinite geometric
series is

a1

i 1
ai 
1 c

4
Sequences and Recurrence Relations

5
Sequences and Recurrence Relations

6
Sequences and Recurrence Relations

7
Sequences and Recurrence Relations

8
Sequences and Recurrence Relations

9
10
Linear Homogenous Recurrence Relations

11
Linear Homogenous Recurrence Relations

12
Linear Homogenous Recurrence Relations

13
Linear Homogenous Recurrence Relations

14
Linear Homogenous Recurrence Relations
find the solution for T(n) = 2T(n/2) + 5n2 Assume T(1) = 7, n = 2k

15
Linear Homogenous Recurrence Relations
k1

Let  1
i 0
/ 2 i
2  1 / 2 k1

T(n) = 7n + 5n2(2 – 1/2k-1)

= 7n + 5n2(2 – 2/n)

= 7n + 10n2 – 10n

= 10n2 – 3n

16
Solving Recurrence Relations
Basically, when solving such recurrence relations, we try to
find solutions of the form an = rn, where r is a constant.
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 + … + ckrn-k.
Divide this equation by rn-k and subtract the right-hand side
from the left:
rk - c1rk-1 - c2rk-2 - … - ck-1r - ck = 0
This is called the characteristic equation of the
recurrence relation.
17
Solving Recurrence Relations
The solutions of this equation are called the characteristic roots of the
recurrence relation.
Let us consider linear homogeneous recurrence relations of
Theorem: Let c1 and c2 be real numbers. Suppose that

r2 – c1r – c2 = 0 has two distinct roots r1 and r2.


Then the sequence {an} is a solution of the recurrence relation an = c1an-1
+ c2an-2
if and only if
an = 1r1n + 2r2n for n = 0, 1, 2, …,

where 1 and 2 are constants.

. 18
Solving Recurrence Relations

Theorem: Let c1 and c2 be real numbers with c2


0. Suppose that r2 – c1r – c2 = 0 has only one root r0.

A sequence {an} is a solution of the recurrence relation


an = c1an-1 + c2an-2
if and only if

an = 1r0n + 2nr0n, for n = 0, 1, 2, …, where 1 and 2


are constants.
19
Solving Recurrence Relations
Example: What is the solution of the recurrence relation

an = 6an-1 – 9an-2 with a0 = 1 and a1 = 6?


Solution: The only root of r2 – 6r + 9 = 0 is r0 = 3.
Hence, the solution to the recurrence relation is
an = 13n + 2n3n for some constants 1 and 2.
To match the initial condition, we need

a0 = 1 = 1
a1 = 6 = 13 + 23
Solving these equations yields 1 = 1 and 2 = 1.
Consequently, the overall solution is given by
an = 3n + n3n. 20
Example solution
 an = an-1 + 2an-2, a0=2 and a1=7
 Characteristic equation
r2 – r – 2 = 0
 The quadratic formula for ax2+bx+c = 0,

 b  b2  4ac
x
2a
 gives roots r1=(1+(-3))/2=-1 and r2=(1-(-3))/2 = 2

21
Example solution
 Therefore,

a1  a0 r1 7  2 (  1) 9
b2    3
r2  r1 2  (  1) 3
a0 r2  a1 2 2  7  3
b1     1
r2  r1 2  (  1) 3

an b1r1n  b2 r2n  1 (  1) n  3 2n 3 2n  (  1) n

22
Example 5

Find a closed form solution for the following recurrence relations. For brevity, we
omit the inductive proofs.

a) Recurrence relation: a0 = 2
an = 3an-1

Solution:

an = 3an-1
an = 3 (3an-2) = 32 an-2
an = 32 (3an-3) = 33 an-3

an = 3i-1 (3an-i) = 3i an-I

Set i = n, yielding:
an = 3 n a 0
an = 2 * 3 n

23
b) Recurrence relation: a0 = 1
an = 2an-1 – 1

Solution:
an = 2(2an-2 – 1) – 1 = 22 an-2 – 2 – 1
an = 22 (2an-3 – 1) – 2 – 1 = 23 an-3 – 22 – 2 – 1

an = 2i (an-i) – 2i-1 – 2i-2 – … – 20

Set i = n, yielding:
an = 2n (a0) – 2n-1 – 2n-2 – … – 20 = 2n – 2n-1 – 2n-2 – … – 20
an = 2n – (2n – 1) (Note: 2n-1 – 2n-2 – … – 1 = 2n – 1)
an = 1

c) Recurrence relation: a0 = 5
an = nan-1

Solution:
an = n(n-1)an-2
an = n(n-1)(n-2)an-3

an = n(n-1)(n-2)…(n-i+1)an-I

Set i = n, yielding:
an = n(n-1)(n-2)…(1) a0 = a0 n!
an = 5n! 24
A recurrence relation expresses the running time of a recursive
algorithm. This includes how many recursive calls are generated at
each level of the recursion, how much of the problem is solved by each
recursive call, and how much work is done at each level.

25
Example 6
Consider the following function to compute factorials:
int factorial(int n)
{
1) if (n <= 1)
2) return(1);
else
3) return(n * factorial(n-));
}

Recurrence relation:

base case: T(1) = a


induction: T(n) = b + T(n-1), for n > 1

Closed form formula:

T(1) = a
T(2) = b + T(1) = b + a
T(3) = b + T(2) = b + (b + a) = a + 2b
T(4) = b + T(3) = b + (a + 2b) = a + 3b
T(n) = a + (n-1)b for all n >= 1

26

You might also like