Reputation: 9146
Suppose I have a recursive function T
, and I want to calculate the upper bound timer complexity of this function.
T(1) = 3
T(n) = 3T(n/3) + 3.
How can I find the upper bound of the time complexity of T(n)?
Upvotes: 2
Views: 2215
Reputation: 2418
Use the master theorem case where a=3, b=3, c=0.
I highly recommend the MIT lectures on Algorithms. You can learn more about the Master theorem in lecture 2
Upvotes: 3
Reputation: 521
assume that, n = 3^k
F(0) = 3
F(k) = 3 * F(k-1) + 3
= 3^2 * F(k-2) + 3^2 + 3
= ...
= 3^k * F(0) + 3^k + 3^(k-1) + ... + 3
= 3^(k+1) + 3^k + ... + 3^2 + 3
= [3^(k+2) - 3] / 2
T(n = 3^k) = F(k) = (9 * n - 3) / 2 = O(n)
Upvotes: 0