s8
s8
INTRODUCTION TO ALGORITM
DESIGN
Master’s theorem method
⚫ Master Method is a direct way to get the solution. The master method
works only for following type of recurrences or for recurrences that
can be transformed to following type.
T(n) = aT(n/b) + f(n) where a >= 1 and b > 1 and f(n) is an asymptotically
positive function.
3. If f(n) > Ω (nlogba), and f(n) satisfies the regularity condition, then
T (n) = ϴ (f(n)).
Solve the problems
⚫ T(n) = 3T(n/2) + n2
⚫ T(n) = 7T(n/2) + n2
⚫ T(n) = 4T(n/2) + n2
⚫ T(n) = 3T(n/4) + n lg n
T(n) = 3T(n/2) + n2
T(n) = aT(n/b) + f(n) where a >= 1 and b > 1
a=3 b=2 f(n) = n2
1. If f(n) < O(nlogba), then T (n) = ϴ (nlogba).
2. If f(n) = ϴ (nlogba) , then T (n) = ϴ (nlogbalogn).
3. If f(n) > Ω (nlogba), and f(n) satisfies the regularity condition,
then T (n) = ϴ (f(n)).
Step 1: Calculate nlogba = nlog23 = n1.58
Step 2: Compare with f(n)
Since f(n) > nlogba
i.e. n2 > n1.58
Step 3: Case 3 is satisfied hence complexity is given as
T(n) = Θ(f(n)) = Θ (n2)
2
T(n) = 7T(n/2) + n
T(n) = aT(n/b) + f(n) where a >= 1 and b > 1
a=7 b=2 f(n) = n2
1. If f(n) < O(nlogba), then T (n) = ϴ (nlogba).
2. If f(n) = ϴ (nlogba) , then T (n) = ϴ (nlogbalogn).
3. If f(n) > Ω (nlogba), and f(n) satisfies the regularity
condition, then T (n) = ϴ (f(n)).
Step 1: Calculate nlogba = nlog27= n2.80
Step 2: Compare with f(n)
since f(n) < nlogba
Step 3: Case 1 is satisfied hence complexity is given as
T(n) = Θ (nlogba) = Θ (n2.8)
2
T(n) = 4T(n/2) + n
T(n) = aT(n/b) + f(n) where a >= 1 and b > 1
a=4 b=2 f(n) = n2
3. If f(n) > Ω (nlogba), and f(n) satisfies the regularity condition, then T
(n) = ϴ (f(n)).