You are on page 1of 8

RECURSIVE ALGORITHM COMPLEXITY

Part 2 : Nonhomogeneous Linear Recurrence

In this document, you can find the nonhomogeneous linear recurrence.


There is an example case to solve. You can find step-by-step problem-
solving.
Pattern of nonhomogeneous linear recurrences

a0tn + a1tn-1 + … + aktn-k = f(n)


Where :
k and ai : constant
f(n) : function other than the zero function

Develop a method for solving the common case

a0tn + a1tn-1 + … + aktn-k = bnp(n)


Where :
b : constant
p(n) : a polynomial in n

Theorem
A nonhomogeneous linear recurrence form can be transformed into homogeneous
linear recurrence
a0tn + a1tn-1 + … + aktn-k = bnp(n)
where d is the degree of p(n)

Characteristic equation :

(a0rk + a1rk-1 + … + ak)(r-b)d+1 = 0

Example :
Solve the following recurrence
tn – 3tn-1 = 4n(2n + 1) for n > 1
t0 = 0
t1 = 12
Solution :
- Obtain the characteristic eq for the corresponding homogeneous eq :

tn – 3tn-1 = 0 → r1 – 3 = 0
- Obtain a term from the nonhomogeneous part of the recurrence
4n(2n1 + 1)

b d
the term is
(r + b)d+1 = (r – 4)1+1

- Apply theorem to obtain the characteristic eq


(r – 3)(r – 4)2

- Solve the characteristic equation


(r – 3)(r – 4)2
the root are r=3 and r=4, and the root r=4 has multiplicity 2

- Apply the theorem to get the general solution


tn = c13n + c24n + c3n4n
We must find another initial condition.
Because t2 – 3t1 = 42(2 x 2 + 1)
And t1 = 12 → t2 = 3 x 12 + 80 = 116

- Determine the value of the constants


- Subtitute the constants into the general solution to obtain
tn = 20(3n) – 20(4n) + 8n4n
Counting the number of times the algorithm’s basic operation is executed on input of
size n.

There are several things to consider about recursive algorithm :


1. Recursive algorithm doesn’t use sum
2. The number of basic operations is difficult to identify how many times it is
executed
3. Find the recurrence relations
4. Solve the recurrence relation to get algorithm efficiency.

Example of recurrence relation

tn – 3tn-1 – 4tn-2 = 0 for n > 1


t0 = 0
t1 = 1

tn – 5tn-1 + 6tn-2 = 0 for n > 1


t0 = 0
t1 = 1

tn = tn-1 + tn-2 tn - tn-1 + tn-2 = 0


t0 = 0 t0 = 0
t1 = 1 t1 = 1

Homogeneous Linear Recurrence


The following are homogeneous linear recurrence equations with constant
coefficients:

7tn – 3tn-1 = 0
6tn – 5tn-1 + 8tn-2 = 0
8tn – 4tn-3 = 0
a0tn + a1tn-1 + … + aktn-k = 0

 k and ai are constant


 It’s called “linear” because every term ti appears only to the first power
 It’s called “homogeneous” because the linear combination is equal to 0

The characteristic equation for the homogeneous linear recurrence equation with
constant coefficients
a0tn + a1tn-1 + … + aktn-k = 0
is defined as
a0rk + a1rk-1 + … + akr0 = 0

Example : The characteristic equation for the recurrence appears below it :


5tn + 7tn-1 + 6tn-2 = 0

5r2 + 7r + 6 = 0
We use an arrow to show that the order of the characteristic equation is k
(in this case is 2)’
Theorem
Let the homogeneous linear recurrence equation with constant coefficients
a0tn + a1tn-1 + … + aktn-k = 0
be given. If its characteristic equation
a0rk + a1rk-1 + … + akr0 = 0
has k distinct solutions r1, r2, . . . , rk, then the only solutions to the recurrence are
n n n
tn = c1r1 + c2r2 + … + ckrk

Example : tn- 3tn-1 – 4tn-2 = 0 for n > 1


t0 = 0
t1 = 1
1. obtain the characteristic equation
tn- 3tn-1 – 4tn-2 = 0 → r2 + 3r – 4 = 0
2. solve the characteristic equation
r2 + 3r – 4 = (r-4)(r+1) = 0
3. apply the theorem to get the general solution
tn = c14n + c2(-1)n
4. determine the values of the constants
t0 = 0 = c140 + c2(-1)n
t1 = 1 = c141 + c2(-1)1
the solution to this system is c1 = , c2 =

5. substitute the constant into the general solution to obtain the particular
solution
tn = c14n + c2(-1)n
tn = 4n - (-1)n
Theorem
Let r be a root of multiplicity m of the characteristic equation for a homogeneous
linear recurrence with constant coefficients. Then
tn = rn, tn = nrn. tn = n2rn, tn = n3rn, …, tn = nm-1rn
are all solution to the recurrence.

To be continued in part 2
References

Levitin’s book (Section 2.4)


Neapolitan’s book (Appendix B)

You might also like