I have been asked to analyze the asymptotic time complexity of the following recursion function:
for-all k ≥ 1:
T(n) = n + T(n/2) + T(n/4) + T(n/8) + .... + T(n/2^k)
I was able to prove that:
T(n) = O(n⋅log n) and T(n) = Ω(n),
but I am looking for a tighter bound (Big Theta).
First of all:
I understand "for-all k >= 1" this way: for
k = 1tok = mwhere2m-1 ≤ n ≤ 2m.So basicly
m = log₂(n)holds.Have a look at my calculation:
T(n) = n + Σk=1,...,m T(n/2k) = n + T(n/2) + Σk=2,...,m T(n/2k) = n + n/2 + 2⋅Σk=2,...,m T(n/2k) = ... = n + Σk=1,...,m k⋅n/2k = n + n⋅Σk=1,...,m k/2k = n + n⋅(2 - 2-mm - 21-m) ≤ n + 2⋅n = 3nSo
T(n)is inΘ(n).Notice:
You can also approximate
Σk=1,...,m k/2kby the integrals(m) = ∫1m k/2k dk.And here
limm → ∞s(m) = 2also holds.