Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Master theorem: issue when f(n) contains negative power of log

So I was calculating average case complexity of the following function using Master's theorem:

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

According to http://people.csail.mit.edu/thies/6.046-web/master.pdf Question 7,

It says

Does not apply (non-polynomial difference between f(n) and n log b a )

This answer also supports pdf, by saying NO.

However, in this video instructor has solved same question at 12:26, he came out with answer

Θ(nloglogn) 

Can anyone explan which one is wrong and why?

like image 543
Varun Garg Avatar asked Oct 11 '16 17:10

Varun Garg


2 Answers

They are both right. The Master Theorem in the PDF does not apply, but the instructor in the video is using an extended form of the master theorem that covers your case.

I wasn't able to find any really good references to the version in the video, and it's not the version I learned, but there is a proof of it online here: http://homepages.math.uic.edu/~leon/cs-mcs401-s08/handouts/extended_master_theorem.pdf

like image 143
Matt Timmermans Avatar answered Oct 15 '22 11:10

Matt Timmermans


As Matt Timmermans correctly notes, the statement doesn't follow from the master theorem, but it does follow from an extended version of it.

It's quite simple to solve this problem directly using the tree method.

Starting with T(n) = 2T (n/2)+ n / log n:

  • Level 0 has 1 node with value n / log(n).

  • Level 1 has 2 nodes, each with value (n / 2) / log(n / 2).

  • ...

  • Level i has 2i nodes, each with value (n / 2i) / log(n / 2i)

Simplifying, level i contributes n / (log(n) - i).

Note that, altogether, there are ~log(n) - 1 levels to reach a constant.

Consequently, the sum of all levels is i = 0~log(n) - 1[n / (log(n) - i)] ~ n ∑i = 0k[1 / k],

for k = log(n).

Note that the sigma is the kth harmonic series, which is Θ(log(k)). Setting k = log(n) gives altogether n Θ(log(log(n))) = Θ(n log(log(n))).

like image 43
Ami Tavory Avatar answered Oct 15 '22 12:10

Ami Tavory