Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Solving Recurrence relation: T(n) = 3T(n/5) + lgn * lgn

Consider the following recurrence
T(n) = 3T(n/5) + lgn * lgn

What is the value of T(n)?

(A) Theta(n ^ log_5{3})
(B) Theta(n ^ log_3{5})
(c) Theta(n Log n )
(D) Theta( Log n )

Answer is (A)

My Approach :

lgn * lgn = theta(n) since c2lgn < 2*lglgn < c1*lgn for some n>n0

Above inequality is shown in this picture for c2 = 0.1 and c1 = 1

log_5{3} < 1,

Hence by master theorem answer has to be theta(n) and none of the answers match. How to solve this problem??

like image 639
user3409814 Avatar asked Jun 12 '14 07:06

user3409814


2 Answers

Your claim that lg n * lg n = Θ(n) is false. Notice that the limit of (lg n)2 / n tends toward 0 as n goes to infinity. You can see this using l'Hopital's rule:

limn → ∞ (lg n)2 / n

= lim n → ∞ 2 lg n / n

= lim n → ∞ 2 / n

= 0

More generally, using similar reasoning, you can prove that lg n = o(nε) for any ε > 0.

Let's try to solve this recurrence using the master theorem. We see that there are three subproblems of size n / 5 each, so we should look at the value of log5 3. Since (lg n)2 = o(nlog5 3), we see that the recursion is bottom-heavy and can conclude that the recurrence solves to O(nlog5 3), which is answer (A) in your list up above.

Hope this helps!

like image 66
templatetypedef Avatar answered Sep 28 '22 15:09

templatetypedef


To apply Master Theorem we should check the relation between

nlog5(3) ~= n0.682 and (lg(n))2

Unfortunately lg(n)2 != 2*lg(n): it is lg(n2) that's equal to 2*lg(n)

Also, there is a big difference, in Master Theorem, if f(n) is O(nlogb(a)-ε), or instead Θ(nlogba): if the former holds we can apply case 1, if the latter holds case 2 of the theorem.

With just a glance, it looks highly unlikely (lg(n))2 = Ω(n0.682), so let's try to prove that (lg(n))2 = O(n0.682), i.e.:

∃ n0, c ∈ N+, such that for n>n0, (lg(n))2 < c * n0.682

Let's take the square root of both sides (assuming n > 1, the inequality holds)

lg(n) < c1 * n0.341 , (where c1 = sqrt(c))

now we can assume, that lg(n) = log2(n) (otherwise the multiplicative factor could be absorbed by our constant - as you know constant factors don't matter in asymptotic analysis) and exponentiate both sides:

2lg(n) < 2c2 * n0.341 <=> n < 2c2 * n0.341 <=> n < (n20.341)c2 <=> n < (n20.341)c2 <=> n < (n1.266)c2

which is immediately true choosing c2 = 1 and n0 = 1

Therefore, it does hold true that f(n) = O(nlogb(a)-ε), and we can apply case 1 of the Master Theorem, and conclude that:

T(n) = O(nlog53)

Same result, a bit more formally.

like image 45
mlr Avatar answered Sep 28 '22 16:09

mlr