5

I'm taking Data Structures and Algorithm course and I'm stuck at this recursive equation:

T(n) = logn*T(logn) + n

obviously this can't be handled with the use of the Master Theorem, so I was wondering if anybody has any ideas for solving this recursive equation. I'm pretty sure that it should be solved with a change in the parameters, like considering n to be 2^m , but I couldn't manage to find any good fix.

Hooked
  • 84,485
  • 43
  • 192
  • 261
Ashkan Kazemi
  • 1,077
  • 8
  • 26
  • This is not a recursive equation, for two reasons. First, T(n) depends on T(log n) ,and even if n is an integer log n is in general not. Second, there is no start condition, such as T(0) = 0. – Johan Råde Oct 03 '13 at 09:33
  • 5
    I dont think these reasons are enough to say that this is not a recursive equation , because after all T(n) depends on another value of T , so this makes it recursive . and according to our instructor the start condition should be guessed by yourself , and sometimes the start condition is not even needed , like when using the master theorem . – Ashkan Kazemi Oct 03 '13 at 09:41
  • 1
    To be precise, functions can be defined **recursively**, equations can have **recurrence**. Did you try enumerating some values for this function? Intelligent guesswork should be the first attempt, it's easy to check if a guess is correct by induction. – DanielKO Oct 03 '13 at 09:51
  • 1
    thanks for the correction Daniel , but no guess comes to mind on this one , do you have any in mind ? – Ashkan Kazemi Oct 03 '13 at 09:54
  • It seems (if I am not wrong), you can atleast calculate the expression for some of the powers of 2. T(1) = 1, T(2) = T(1) + 2, T(4) = 2*T(2) + 4, T(16) = 56, T(256) = 704 – Abhishek Bansal Oct 03 '13 at 10:34
  • yes , but where would that take us !? :| – Ashkan Kazemi Oct 03 '13 at 10:48
  • 3
    this question was solved at this topic , http://cs.stackexchange.com/questions/14775/recursive-equation-for-complexity-tn-logn-tlogn-n – Ashkan Kazemi Oct 03 '13 at 11:20
  • 1
    This question appears to be off-topic because it is not about programming. – Johan Råde Oct 03 '13 at 14:09

2 Answers2

1

This is by no means an official proof but I think it goes like this.

The key is the + n part. Because of this, T is bounded below by o(n). (or should that be big omega? I'm rusty.) So let's assume that T(n) = O(n) and have a go at that.

Substitute into the original relation

T(n) = (log n)O(log n) + n
     = O(log^2(n)) + O(n)
     = O(n)

So it still holds.

Worakarn Isaratham
  • 1,034
  • 1
  • 9
  • 16
  • this is completely and utterly wrong my friend , I'd vote you down but I cannot . – Ashkan Kazemi Oct 03 '13 at 11:04
  • 1
    hah okay I admit I'm not sure with this solution. Care to elaborate? – Worakarn Isaratham Oct 03 '13 at 11:05
  • well I think your mistake is that for T(logn) you cannot just write O(logn) , because we do not know what will happen with logn within the function T(logn) . – Ashkan Kazemi Oct 03 '13 at 11:07
  • 1
    @AshkanKzme: Why is this answer that T(n) is O(n) "completely and utterly wrong" when the solution to the Accepted Answer to your cross-post at cs.SE also says T(n) is O(n)? There's some abuse of notation in the Answer above, but not much more than what is entailed by the Question itself. – hardmath Oct 03 '13 at 12:56
  • 1
    This is correct. You could make it a little more rigorous by saying "assume that `T(n) – Teepeemm Oct 03 '13 at 13:54
  • Be careful with these kind of proofs (induction proofs) and big-O notation. A simple *assume this-or-that* approach can produce wrong results! – phimuemue Oct 03 '13 at 16:52
1

The answer is Theta(n). To prove something is Theta(n), you have to show it is Omega(n) and O(n). Omega(n) in this case is obvious because T(n)>=n. To show that T(n)=O(n), first

  1. Pick a large finite value N such that log(n)^2 < n/100 for all n>N. This is possible because log(n)^2=o(n).
  2. Pick a constant C>100 such that T(n)<Cn for all n<=N. This is possible due to the fact that N is finite.

We will show inductively that T(n)<Cn for all n>N. Since log(n)<n, by the induction hypothesis, we have:

T(n) < n + log(n) C log(n) 
     = n + C log(n)^2
     < n + (C/100) n 
     = C * (1/100 + 1/C) * n
     < C/50 * n
     < C*n

In fact, for this function it is even possible to show that T(n) = n + o(n) using a similar argument.

mrip
  • 14,913
  • 4
  • 40
  • 58
  • dude your final answer is correct , but your proof is faulty ! it is not logn^2 , its logn*T(logn) ! I think you forgot that ! – Ashkan Kazemi Oct 04 '13 at 07:23
  • T(log n) < C log(n) follows from the induction hypothesis. Are you familiar with proof by induction? http://en.wikipedia.org/wiki/Mathematical_induction – mrip Oct 04 '13 at 07:41
  • yes , As I examined my textbook your method was right and I was wrong . I made that mistake because your way of using induction was slightly different than the method I learnt ( like choosing the constants c and n ) . anyway , thanks – Ashkan Kazemi Oct 04 '13 at 09:07