SUNY Geneseo Department of Computer Science
Master Theorem, Part 2
{Date}
CSci 240, Spring 2007
Prof. Doug Baldwin
Return to List of Lectures
Previous Lecture
Misc
Exam 1 Friday (Feb. 23)
- Covers material from start of semester through class
before exam (e.g., pre- and post-conditions,
recursion, induction, recurrences, experiments, etc.)
- 4 - 6 short-answer questions
- Similar to problem set or lab problems
- Full class period (50 minutes)
- Open book, open notes, open computer; closed person
Faculty applicant (Apan Qasem) interviewing today
- Student roundtable 11:30 - 12:00, Fraser 208
- Research talk (automatically tuning code to architecture)
2:30, Milne 213
- Model class (caches) 4:30 - 5:30, Welles 123
Last applicant (Gahyun Park) interviewing Friday, 2/23
- Student roundtable 2:00 - 2:30, Fraser 208
- Research talk (distributed contention resolution) 2:45,
South 340
- Model class (Programmer-defined classes in Java),
4:30, South 340
Questions?
The Master Theorem
Let f be defined by a recurrence of the form
- f(n) = Θ(1) in the base case
- f(n) = a f(n/b) + g(n) in the recursive case, b > 1
Consider how this expands
- Red part contributes a logbn = (b logba )logbn = (b logbn )logba = nlogba
- Because a = b logba
Then...
- f(n) = Θ( nlogba ) if g(n) = O( nlogba - ε ) for ε > 0
- f(n) = Θ( nlogba log n ) if g(n) = Θ( nlogba )
- f(n) = Θ( g(n) ) if g(n) = Ω( nlogba + ε ) for ε > 0
and if a g(n/b) ≤ c g(n) for c < 1 and large enough n
... Which really isn't as bad as it looks
Intuition: a f(n/b) term yields behavior of the form nlogba.
- If nlogba grows faster than g(n), then nlogba dominates
the closed form
- If nlogba and g(n) grow at the same rate, then closed form
is slightly larger than nlogba
- If nlogba grows slower than g(n), then g(n) dominates the
closed form
Application: Figure out how nlogba relates to g(n) and plug in
a, b, and/or g to get a closed form
Try it on the recurrence from the pattern-drawing algorithm
- Recurrence
- T(n) = 4 T( n/2 ) + 1 if n > limit
- T(n) = 1 if n <= limit
- Identify parameters
- Plug in
- Figure out which case applies
- 1 = n0 = O( n2-ε )? Yes! ε = 2
- 1 = n0 = Θ(n2)?
- 1 = n0 = Ω( n2+ε )?
- Plug a, b in to get closed form
- T(n) = Θ( nlogba ) = Θ( n2 )
Hand out problem set 8
Lab 5
Hand out
Why you might care about vectors and matrices (done in lab)
Next
(After exam)
Reasoning about loops
Read section 8.1
Next Lecture