-2

If we assume T(n) is constant for small n, how can we find the solution of this function?

T(n) = T(n−2) + 2logn

So far, I am unable to find a way to represent the whole function. Can you please help me? I really want to understand.

coder
  • 12,832
  • 5
  • 39
  • 53
Bucciarati
  • 17
  • 5

1 Answers1

1

Assuming n is even, and that T(1) = T(0) = 0.

T(n)/2 = log(n) + log(n-2) + ... + log(2)
       = log((n/2)! * 2^n)
       = n log(2) + log((n/2)!)
       = n log(2) + n log(n) - n + O(log(n)) (Stirling's approximation)

So for n even, T(n) = Theta(n log(n)).

For n odd, you can note that T(n-1) < T(n) < T(n+1), and get the same asymptotic bound.

Paul Hankin
  • 54,811
  • 11
  • 92
  • 118