Solve the following recurrence relation
T(1) = c1
T(n) = 2*T(n/2) + c2
T(1) = c1
T(n) = 2*T(n/2) + c2
Solution:
T(n) = 2*T(n/2) + c2 T(n/2) = 2*T(n/4) + c2
= 2*(2*T(n/4) + c2) + c2
= 4*T(n/4) + 3c2 T(n/4) = 2*T(n/8) + c2
= 4*(2*T(n/8) + c2) + 3c2
= 8*T(n/8) + 7c2 T(n/8) = 2*T(n/16) + c2
= 8*(2*T(n/16) + c2) + 7c2
= 16*T(n/16) + 15c2 T(n/16) = 2*T(n/32) + c2
= 16*(2*T(n/32) + c2 ) + 15c2
= 32*T(n/32) + 31c2
= .......
= 2k*T(n/2k) + (2k - 1)c2
T(1) = c1
T(n) = 2*T(n/2) + c2
T(n) = 2k*T(n/2k) + (2k - 1)c2
We need to get off T(n/2k) using T(1)
n/2k = 1
n = 2k
lg (n) = k
T(n) = 2lg (n) *T(n/2lg (n) ) + (2lg (n) - 1)c2
= nT(n/n) + (n - 1)c2
= nT(1) + (n - 1)c2
= nc1 + (n - 1)c2
Get Answers For Free
Most questions answered within 1 hours.