Professional Documents
Culture Documents
Master Theorem: Slides by Christopher M. Bourke Instructor: Berthe Y. Choueiry
Master Theorem: Slides by Christopher M. Bourke Instructor: Berthe Y. Choueiry
Theorem
Pitfalls
Spring 2006
Master
Theorem
CSE235
Introduction
Pitfalls When analyzing algorithms, recall that we only care about the
Examples asymptotic behavior.
4th Condition
Recursive algorithms are no different. Rather than solve exactly
the recurrence relation associated with the cost of an
algorithm, it is enough to give an asymptotic characterization.
The main tool for doing this is the master theorem.
2 / 25
Master Theorem II
Master
Theorem
CSE235
Theorem (Master Theorem)
Introduction
Let T (n) be a monotonically increasing function that satisfies
Pitfalls
Θ(nd ) if a < bd
Θ(nlogb a ) if a > bd
3 / 25
Master Theorem
Pitfalls
Master
Theorem
CSE235
4 / 25
Master Theorem
Example 1
Master
Theorem
n
+ 12 n2 + n. What are the parameters?
CSE235 Let T (n) = T 2
Introduction
a =
Pitfalls
Examples
b =
4th Condition
d =
5 / 25
Master Theorem
Example 1
Master
Theorem
n
+ 12 n2 + n. What are the parameters?
CSE235 Let T (n) = T 2
Introduction
a = 1
Pitfalls
Examples
b =
4th Condition
d =
6 / 25
Master Theorem
Example 1
Master
Theorem
n
+ 12 n2 + n. What are the parameters?
CSE235 Let T (n) = T 2
Introduction
a = 1
Pitfalls
Examples
b = 2
4th Condition
d =
7 / 25
Master Theorem
Example 1
Master
Theorem
n
+ 12 n2 + n. What are the parameters?
CSE235 Let T (n) = T 2
Introduction
a = 1
Pitfalls
Examples
b = 2
4th Condition
d = 2
8 / 25
Master Theorem
Example 1
Master
Theorem
n
+ 12 n2 + n. What are the parameters?
CSE235 Let T (n) = T 2
Introduction
a = 1
Pitfalls
Examples
b = 2
4th Condition
d = 2
9 / 25
Master Theorem
Example 1
Master
Theorem
n
+ 12 n2 + n. What are the parameters?
CSE235 Let T (n) = T 2
Introduction
a = 1
Pitfalls
Examples
b = 2
4th Condition
d = 2
10 / 25
Master Theorem
Example 2
Master
Theorem
n
√
CSE235 Let T (n) = 2T 4 + n + 42. What are the parameters?
Introduction
a =
Pitfalls
Examples
b =
4th Condition
d =
11 / 25
Master Theorem
Example 2
Master
Theorem
n
√
CSE235 Let T (n) = 2T 4 + n + 42. What are the parameters?
Introduction
a = 2
Pitfalls
Examples
b =
4th Condition
d =
12 / 25
Master Theorem
Example 2
Master
Theorem
n
√
CSE235 Let T (n) = 2T 4 + n + 42. What are the parameters?
Introduction
a = 2
Pitfalls
Examples
b = 4
4th Condition
d =
13 / 25
Master Theorem
Example 2
Master
Theorem
n
√
CSE235 Let T (n) = 2T 4 + n + 42. What are the parameters?
Introduction
a = 2
Pitfalls
Examples
b = 4
4th Condition
d = 12
14 / 25
Master Theorem
Example 2
Master
Theorem
n
√
CSE235 Let T (n) = 2T 4 + n + 42. What are the parameters?
Introduction
a = 2
Pitfalls
Examples
b = 4
4th Condition
d = 12
15 / 25
Master Theorem
Example 2
Master
Theorem
n
√
CSE235 Let T (n) = 2T 4 + n + 42. What are the parameters?
Introduction
a = 2
Pitfalls
Examples
b = 4
4th Condition
d = 12
16 / 25
Master Theorem
Example 3
Master
Theorem
n
+ 34 n + 1. What are the parameters?
CSE235 Let T (n) = 3T 2
Introduction
Pitfalls
a =
Examples
b =
4th Condition d =
17 / 25
Master Theorem
Example 3
Master
Theorem
n
+ 34 n + 1. What are the parameters?
CSE235 Let T (n) = 3T 2
Introduction
Pitfalls
a = 3
Examples
b =
4th Condition d =
18 / 25
Master Theorem
Example 3
Master
Theorem
n
+ 34 n + 1. What are the parameters?
CSE235 Let T (n) = 3T 2
Introduction
Pitfalls
a = 3
Examples
b = 2
4th Condition d =
19 / 25
Master Theorem
Example 3
Master
Theorem
n
+ 34 n + 1. What are the parameters?
CSE235 Let T (n) = 3T 2
Introduction
Pitfalls
a = 3
Examples
b = 2
4th Condition d = 1
20 / 25
Master Theorem
Example 3
Master
Theorem
n
+ 34 n + 1. What are the parameters?
CSE235 Let T (n) = 3T 2
Introduction
Pitfalls
a = 3
Examples
b = 2
4th Condition d = 1
21 / 25
Master Theorem
Example 3
Master
Theorem
n
+ 34 n + 1. What are the parameters?
CSE235 Let T (n) = 3T 2
Introduction
Pitfalls
a = 3
Examples
b = 2
4th Condition d = 1
22 / 25
Master Theorem
Example 3
Master
Theorem
n
+ 34 n + 1. What are the parameters?
CSE235 Let T (n) = 3T 2
Introduction
Pitfalls
a = 3
Examples
b = 2
4th Condition d = 1
23 / 25
“Fourth” Condition
Master
Theorem
CSE235 Recall that we cannot use the Master Theorem if f (n) (the
Introduction non-recursive cost) is not polynomial.
Pitfalls
There is a limited 4-th condition of the Master Theorem that
Examples
allows us to consider polylogarithmic functions.
4th Condition
Corollary
If f (n) ∈ Θ(nlogb a logk n) for some k ≥ 0 then
24 / 25
“Fourth” Condition
Example
Master
Theorem
CSE235
Say that we have the following recurrence relation:
Introduction
n
Pitfalls
T (n) = 2T + n log n
Examples 2
4th Condition
Clearly, a = 2, b = 2 but f (n) is not a polynomial. However,
25 / 25