Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Recurrences

Four methods to solve a recurrence relation:


1. Substitution method
2. Iteration method
3. Recursion tree method
4. Master theorem method
Iteration Method
It means to expand the recurrence and express it as a summation of
terms ‘n’ and initial condition.
Example:
Solve the following recurrence relation in terms of ‘n’ by using the
iteration method:
T(n) = 4T(n/4) +4 k
1−r i
T(1) = 1 ∑ ar i=a ( 1−r
)
i=1

n=1 Geometric Series

then T(1) = 1

K T(n)
1 T(n) = 4T(n/4) + 4
n/4
T(n) = 4 T( 4 ) +4
T(n/4) = 4T(n/42) + 4
2 T(n) = 4(4T(n/42)+4)+4
T(n) = 42 T(n/42) + 42 + 4
2 n/4 2
T(n/4 ) = 4 T( 4 ) +4
= 4 T(n/43) + 4
3 T(n) = 42 (4T(n/43)+4)+42 +4
T(n) = 43 T(n/43) + 43 + 42 + 4
.
.
.
K T(n) = 4k T(n/4k) + 4k + 4k-1 + … + 4
k
k k
=4 T(n/4 ) + ∑ 4i
i=1

k k 1−4 k
= 4 T(n/4 ) + 1−4
1−4 k
= 4k T(n/4k) + −3
4 k −1
= 4k T(n/4k) + 3
n/4k = 1
n = 4k
taking log on both sides
log4n = k (4log4n = n)

4 log 4n−1

T(n) = 4log4n T(n/4log4n) + 3


= n.T(n/n) + n-1/3
= nT(1) + n-1/3
= n 1 + n-1/3
= n+ n-1/3
=1/3(4n-1)
Runtime = O(n)

You might also like