Equal costs at all levels Root dominated Leave dominated CSC317
Master method a subproblems n/b size of each subproblem f(n) cost of dividing problem and combining results of subproblems Competition between: a number of recursive calls made – bad b how much problem size decreased each call – good f(n) determines work outside of recursive call we compare to CSC317
We’ll be comparing: and Question: is there more work at the root or at the leaves (like in the recursion examples)? CSC317
Master theorem case 1: Let a ≥ 1 and b > 1 be constants, f(n) a function, and let T(n) be defined on the nonnegative integers by the recurrence Then T(n) has the following asymptotic bounds: 1: If for some constant e>0 then: If polynomial larger than f(n): dominates. leaves dominating in a recursion tree CSC317
Master theorem case 2: Let a ≥ 1 and b > 1 be constants, f(n) a function, and let T(n) be defined on the nonnegative integers by the recurrence Then T(n) has the following asymptotic bounds: 2: If then: If equals f(n): equal work at each level CSC317
Let a ≥ 1 and b > 1 be constants, f(n) a function, and let Master theorem case 3: Let a ≥ 1 and b > 1 be constants, f(n) a function, and let T(n) be defined on the nonnegative integers by the recurrence Then T(n) has the following asymptotic bounds: 3: If for some constants e>0 and regularity conditions (ignore for now): If polynomial smaller than f(n): f(n) dominates. root dominating in a recursion tree CSC317
Master theorem summary – 3 cases If dominates leaves dominating in a recursion tree Like merge sort – equal work at each level If dominates root dominating in a recursion tree CSC317
Master theorem summary In all cases we compare to f(n) Intuition: Either the leaves and recursion process dominate the cost, or the root dominates the cost, or they are balanced Proof: we won’t show; but relies on recursion trees and geometric sums, similar to example cases we looked at CSC317
Master theorem example 1 n3 polynomial larger than f(n) = n2 Case 1 CSC317
Strassen’s method anyone? Master theorem example 2 Looks similar? Strassen’s method anyone? n2.8 polynomial larger than f(n) = n2 Case 1 CSC317
Master theorem example 3 1 is equal to f(n)=1 Case 2 CSC317
Strassen’s method anyone? Master theorem example 4 Looks similar? Strassen’s method anyone? Polynomially smaller than f(n) Case 3 CSC317
Strassen’s method anyone? Master theorem example 5 Looks similar? Strassen’s method anyone? Polynomially smaller than nlogn Case 3? No, not polynomially smaller CSC317
Substitution method Guess a bound (we need a guess!) Prove correct by induction Find constants in this process CSC317
Example Prove that is We need to show that For appropriate choices of c > 0. (can’t use big Oh in substitution because of induction, need to write out definition with constants!) CSC317
Induction step: assume Then we want CSC317
Induction step: assume Then we want CSC317
Induction step: assume Then we want CSC317
Induction step: assume Then we want When? CSC317
Induction step: assume Then we want Holds for CSC317
Induction step: assume Then for CSC317
Example Induction needs base condition. For n=1, assume: Then: NO! Asymptotic notation requires only for n>=no CSC317
Example Induction needs base condition. Asymptotic notation requires only for n>=no Let’s try n=3, so as not to depend directly on T(1): Holds for c ≥ 2 CSC317
Randomized algorithms Hiring problem We always want the best hire for a job! • Using employment agency to send one candidate at a time • Each day, we interview one candidate • We must decide immediately if to hire candidate and if so, fire previous In other words … • Always want the best hire… • Cost to interview (low) • Cost to fire/hire… (expensive) CSC317