Presentation is loading. Please wait.

Presentation is loading. Please wait.

Equal costs at all levels

Similar presentations


Presentation on theme: "Equal costs at all levels"— Presentation transcript:

1 Equal costs at all levels
Root dominated Leave dominated CSC317

2 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

3 We’ll be comparing: and Question: is there more work at the root or at the leaves (like in the recursion examples)? CSC317

4 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

5 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

6 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

7 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

8 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

9 Master theorem example 1
n3 polynomial larger than f(n) = n2 Case 1 CSC317

10 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

11 Master theorem example 3
1 is equal to f(n)=1 Case 2 CSC317

12 Strassen’s method anyone?
Master theorem example 4 Looks similar? Strassen’s method anyone? Polynomially smaller than f(n) Case 3 CSC317

13 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

14 Substitution method Guess a bound (we need a guess!) Prove correct by induction Find constants in this process CSC317

15 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

16 Induction step: assume
Then we want CSC317

17 Induction step: assume
Then we want CSC317

18 Induction step: assume
Then we want CSC317

19 Induction step: assume
Then we want When? CSC317

20 Induction step: assume
Then we want Holds for CSC317

21 Induction step: assume
Then for CSC317

22 Example Induction needs base condition. For n=1, assume: Then: NO! Asymptotic notation requires only for n>=no CSC317

23 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

24 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


Download ppt "Equal costs at all levels"

Similar presentations


Ads by Google