2

I am stuck on a recurrence question.

T(n)=T(n/2)+ log N

What I have right now is that:

T(N) = T(N/2) + log N

T(N/2) = T(N/4) + log(N/2)

...

T(N) = T(N/ 2^k) + sum[i=0 and k {log (N/2^i)}]

I am stuck on what to do next. Please give me some suggestion.

Thanks!

kevin
  • 21
  • 1
  • 2

3 Answers3

3

Another approach is to use the Master Theorem (or on Wikipedia). For most recurrences it is applicable and provides the answer very fast.

It basically gives you three categories and then the answer falls out. Given a recurrence of the form T (n) = aT (n/b) + f (n) we look for a,b, and f(n). In your case we have a=1, b=2, f(n)=log n.

Therefore (you have to look at the referenced links) we fall into Case 2, where f(n) is in Theta(n^(log_b(a-eps)) log^k(n)) = Theta(n^0 log(n)), then the Master Theorem states that T(n) is in Theta(n^(log_b(a-eps)) log^(k+1)(n)) = Theta(log^2(n))

gue
  • 1,868
  • 1
  • 16
  • 21
1
 T(1) = c                         (= c + 0)
 T(2) = T(1) +  log(2)             = c + 1
 T(4) = T(2) +  log(4) = c + 1 + 2 = c + 3
 T(8) = T(4) +  log(8) = c + 3 + 3 = c + 6
T(16) = T(8) + log(16) = c + 6 + 4 = c + 10
...

n | T(n)  | T(n) - T(n-1)
--+---------------------
 1| c +  0| -
 2| c +  1| 1
 4| c +  3| 2
 8| c +  6| 3
16| c + 10| 4

T(n) = c + (log n)(1 + log n) / 2 = O(log^2 n)

Another way to see the same thing:

n = 2^m
S(m) = T(2^m) = T(2^m / 2) + log(2^m) = S(m - 1) + m
m | S(m)
--+-----
0 | c
1 | c + 1
2 | c + 1 + 2 = c + 3
3 | c + 3 + 3 = c + 6
4 | c + 6 + 4 = c + 10
...
S(m) = c + m(m + 1) / 2
T(2^m) = c + m(m + 1) / 2
T(n) = c + (log n)(1 + log n) / 2 = O(log^2 n)
Patrick87
  • 27,682
  • 3
  • 38
  • 73
0

termination condition is not given in the mathematical equation so it is better if you solve this question with the help of modified version of master's theorem. I am providing here a link for these kind of problems, please have a look on this question probably you will get what you are looking for. have a look on the second answer please.

here

Community
  • 1
  • 1