Question

I understand that the Master Theorem and recursion tree can be used for "divide-and-conquer" recurrence relations (i.e. T(n)=T(n/2)+1).

However, how would I apply those concepts to T(n)=T(n-1)+logn?

To my understanding, you cannot apply the two concepts to (n-1) decrements. But the assignment and professor are requiring T(n)=T(n-1)+logn to be solved using recursion trees and master theorem.

Furthermore, is there any reason that the following is not the recursive expansion for the above function?

T(n)=T(n-3)+log(n-2)+log(n-1)+log(n)

According to my professor, it should not be log(n-2) and log(n-1) but rather

T(n)=T(n-3)+logn+logn+logn

which makes absolutely no sense to me.

Était-ce utile?

La solution 2

Two things,

  1. The recursive definition states that you must replace n with n-1 when calling T(n) again, so your logic is sound for T(n)=T(n-3)+log(n-2)+log(n-1)+log(n).

  2. Your can easily make the argument that log(1) + log(2) + log(3) + ... log(n) = log(n!) = Theta(nlogn), and log(n) + log(n) + log(n) ... + log(n) = nlog(n) = Theta(nlog(n))

http://en.wikipedia.org/wiki/Factorial#Rate_of_growth_and_approximations_for_large_n

http://en.wikipedia.org/wiki/Stirling%27s_approximation

To look at it as a tree, it's actually just a tree with worst case height, i.e.

enter image description here

This is because at each call, There is only one subproblem to solve.

Autres conseils

The following is a subtractive version of the master theorem:

If T(n) = aT(n-c) + g(n) where c>=1 and g(n)=Theta(n^k) for k>=0, then

  • T(n)=Theta(n^k) if a<1
  • T(n)=Theta(n^{k+1}) if a=1
  • T(n)=Theta(a^{n/c}) if a>1

It does not include the particular case you ask, but states a general result on decrements.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top