Master Theorem Flashcards
Describe the Master Theorem formula:
T(n) = aT(n/b) + f(n) Where: a = how many subproblems n/b = size of each subproblem
What is the master theorem time complexity for Karatsuba’s algorithm?
T(n) = 3T(n/2) + cn
- n*logb a = nlog2 3 ≈ n1.59
- f(n)* = cn
- cn* is O(n1.59-0.1)
T(n) is θ(nlog2 3)
What is the master theorem time complexity for the Merge Sort algorithm?
T(n) = 2T(n/2) + cn
- n*log2 2 = n
- f(n)* = cn
- cn* is θ(n)
T(n) is θ(n log n)
We solve the recurrence of T(n) = aT(n/b) + f(n) by comparing ? with ?
f(n) is compared with nlogb a
Master Theorem solutions - Case 1: if f(n) is much smaller than nlogb a then…
f(n) is O(nlogb a)
and
T(n) has time complexity nlogb a
if f(n) is O(nlogb a-e) for some e>0, then
T(n) = θ(nlogb a)
Master Theorem solutions - Case 2: if f(n) is the same as nlogb a then…
f(n) is θ(n<em>l</em>ogb a)
and
T(n) has time complexity nlogb a log n
T(n) = θ(nlogb a log n)
Master Theorem solutions - Case 3: if f(n) is much bigger than nlogb a then…
f(n) = Ω(nlogb a)
and
T(n) has time complexity f(n)
if f(n) is Ω(nlogb a+e) for some e>0,
and the regularity condition holds, then
T(n) = (f(n))
What are the three cases when the Master Theorem doesn’t work?
when a < 1
T(n) = 0.5T(n/2) + n
when f(n) is negative
T(n) = 2T(n/2) - log n
When f(n) is smaller but not small enough:
- f(n)* is O(nlogb a) but f(n) is not O(nlogba-e) for any e>0
- T(n)* = 2T(n/2) + n/log n