Extended Master's Theorem

Distribute Education like Computer Geek

This theorem is the extended part of the master’s theorem. If running time in a recurrence equation has a part of log n, then, by this theorem, we can solve the problem.

 

T(n) = aT(n/b) + nk*logpn,

where a ≥ 1, b ≥ 1, k ≥ 0, p is any real number.

 

(1) If a > bk, then T(n) = θ(nlogba)

 

(2) If a = bk,

-> (a) If p > -1, then T(n) = θ(nklogp+1n).

-> (b) If p = -1, then T(n) = θ(nkloglogn).

-> (c) If p < -1, then T(n) = θ(nk).

 

(3) If a < bk,

-> (a) If p ≥ 0, then T(n) = θ(nklogpn).

-> (b) If p < 0, then T(n) = O(nk).

 

Questions for solving recurrence problem

Q9 – Find the time complexity of T(n) = T(n/2) + log n.

Ans-

Apply Extended master’s theorem.

In this equation, a = 1, b = 2, k = 0 and p = 1

Now, Case 2 applies because a = bk

-> a = 1, bk = 20 = 1

Value of p is 1, means it should be in the case of p > -1.

-> T(n) = θ(nklogp+1n).

-> T(n) = θ(n0log1+1n).

-> T(n) = θ(log2n).

You can check the answer by iterative method.

 

Q10 – Find the time complexity of T(n) = 2T(n/2) + n/log n.

Ans-

Apply Extended master’s theorem.

In this equation, a = 2, b = 2, k = 1 and p = -1

Now, Case 2 applies because a = bk

-> a = 2, bk = 21 = 2

Value of p is -1, means it should be in the case of p > -1.

-> T(n) = θ(nkloglogn).

-> T(n) = θ(n1loglogn).

-> T(n) = θ(n*log2n) = θ(n*logn*logn).

You can check the answer by iterative method.

I will give you some other examples so that you can understand easily.

 

Example 1 – Find the time complexity of T(n) = 2T(n/2) + n/log2 n.

Ans-

Apply Extended master’s theorem.

In this equation, a = 2, b = 2, k = 1 and p = -2

Now, Case 2 applies because a = bk

-> a = 2, bk = 21 = 2

Value of p is -2, means it should be in the case of p < -1.

-> T(n) = θ(nk).

-> T(n) = θ(n1).

 

Example 2 – Find the time complexity of T(n) = 2T(n/2) + n/log0.5n.

Ans-

Apply Extended master’s theorem.

In this equation, a = 2, b = 2, k = 1 and p = -0.5

Now, Case 2 applies because a = bk

-> a = 2, bk = 21 = 2

Value of p is -0.5, means it should be in the case of p > -1.

-> T(n) = θ(nklogp+1n).

-> T(n) = θ(n1log1-0.5n).

-> T(n) = θ(n*log0.5n).

 

Example 3 – Find the time complexity of T(n) = 8T(n/2) + n2log2n.

Ans-

Apply Extended master’s theorem.

In this equation, a = 8, b = 2, k = 2 and p = 2

Now, Case 2 applies because a > bk

-> a = 8, bk = 22 = 4

Only one case applies

-> T(n) = θ(n^logba).

-> T(n) = θ(n^log28).

-> T(n) = θ(n3).

 

Example 4 – Find the time complexity of T(n) = T(n/2) + n2log2n.

Ans-

Apply Extended master’s theorem.

In this equation, a = 1, b = 2, k = 2 and p = 2

Now, Case 3 applies because a < bk

-> a = 1, bk = 22 = 4

Value of p is 2, means it should be in the case of p ≥ 0.

-> T(n) = θ(nklogpn).

-> T(n) = θ(n2log2n).

I think you understand the extended master’s theorem very well. But the tricky part is that it can also solve the master’s theorem problem.

Question numbers 6 to 8 can also be solved by the extended master’s theorem.

 

Q6 – Find the time complexity of T(n) = T(n/2) + n.

Ans-

Apply Extended master’s theorem.

In this equation, a = 1, b = 2, k = 1 and p = 0

Now, Case 3 applies because a < bk

-> a = 1, bk = 21 = 2

Value of p is 0, means it should be in the case of p ≥ 0.

-> T(n) = θ(nklogpn).

-> T(n) = θ(n1).

 

Q7 – Find the time complexity of T(n) = 2T(n/2) + 1.

Ans-

Apply Extended master’s theorem.

In this equation, a = 2, b = 2, k = 0 and p = 0

Now, Case 2 applies because a = bk

-> a = 2, bk = 20 = 1

Value of p is -1, means it should be in the case of p > -1.

-> T(n) = θ(n^logba).

-> T(n) = θ(n1).

 

Q8 – Find the time complexity of T(n) = 2T(n/2) + n.

Ans-

Apply Extended master’s theorem.

In this equation, a = 2, b = 2, k = 1 and p = 0

Now, Case 2 applies because a = bk

-> a = 2, bk = 21 = 2

Value of p is 0, means it should be in the case of p > -1.

-> T(n) = θ(nklogp+1n).

-> T(n) = θ(n*log n).

 

BOOKS

Algorithm T H CoremanAlgorithm by Udit AgarwalAlgorithm Ellis HorowitzData Structure & Algorithm Made Easy Narasimha