Master Theorem

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

T(n) = aT(n/b) +Y

Where Y is the complexity required per unit work (for smallest unit) and n/b is n ÷b and the equation is
valid for master theorem

To find complexity:-

1. Find logba
2. Let x= logba
3. Find nx
4. Compare Y and nx
5. If Y > nx then complexity is Y
6. If Y < nx then complexity is nx
7. If they are equal then answer will be nx (logn)

Note:- let Y is 5log n then here we treat Y as logn. Similarly if it is 5n^2 then we treat it as n^2

Q1 T(n) = T(n/2)+ (1/2)n2+ n

Which is equivalent to

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

As Y is the greatest upper bound of the whole (1/2)n2+ n

1 a = 1; b = 2; y = n2
2 Finding x of point 2.

X = logba
X = log21 =0

3 finding Nx = N0 =1

4 Y = n2 >1

5 so answer is n2
Q2. : T(n) = 2T(n/4) + √n + 42

Which is equivalent to

T(n) = 2T(n/4) + √n

1 a = 2; b = 4; Y= √n

2 Finding x of point 2.

X = logba
X = log42 =½

3 finding Nx = N½ =√n

4 Y =√n = Nx

5 so answer is √n xlogn or √n(logn)

Q3 Case 3: T(n) = 3T(n/2) + (3/4)n + 1

Which is equivalent to
Case 3: T(n) = 3T(n/2) + n
Now
1 a = 3; b = 2; Y= √n

2 Finding x of point 2.

X = logba
X = log23= 1.58

3 finding Nx = N 1. 58

4 Y =n < N 1. 58

5 so answer is N 1. 58

You might also like