You are on page 1of 5

RECURSIVE ALGORITHM COMPLEXITY

Part 1 : Homogeneous Linear Recurrence

Review : Time Complexity

T(n) ≈ copC(n)
Where :
T(n) : running time
n : input size
cop : execution time for basic operation
C(n) : number of times basic operation is executed
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
1 1
the solution to this system is c1 = 5 , c2 = 5

5. substitute the constant into the general solution to obtain the particular
solution
tn = c14n + c2(-1)n
1 1
tn = 5 4n - 5 (-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