Presentation is loading. Please wait.

Presentation is loading. Please wait.

Richard Anderson Lecture 12, Winter 2019 Recurrences

Similar presentations


Presentation on theme: "Richard Anderson Lecture 12, Winter 2019 Recurrences"— Presentation transcript:

1 Richard Anderson Lecture 12, Winter 2019 Recurrences
CSE 421 Algorithms Richard Anderson Lecture 12, Winter 2019 Recurrences

2 Announcements No office hour, Wednesday, Feb 6
Midterm, Wednesday, Feb 13 Coverage through KT 5.2 Old midterms posted Homework 5, available

3 Divide and Conquer Recurrences, Sections 5.1 and 5.2 Algorithms
Fast Matrix Multiplication Counting Inversions (5.3) Closest Pair (5.4) Multiplication (5.5)

4 Divide and Conquer Array Mergesort(Array a){ n = a.Length;
if (n <= 1) return a; b = Mergesort(a[0 .. n/2]); c = Mergesort(a[n/ n-1]); return Merge(b, c); }

5 Algorithm Analysis Cost of Merge Cost of Mergesort

6 T(n) = 2T(n/2) + cn; T(1) = c;

7 Recurrence Analysis Solution methods Unrolling recurrence
Guess and verify Plugging in to a “Master Theorem”

8 Unrolling the recurrence

9 Substitution Prove T(n) <= cn (log2n + 1) for n >= 1 Induction:
Base Case: Induction Hypothesis: T(n/2) <= c(n/2) log2(n/2)

10 A better mergesort (?) Divide into 3 subarrays and recursively sort
Apply 3-way merge What is the recurrence?

11 Unroll recurrence for T(n) = 3T(n/3) + dn

12 T(n) = aT(n/b) + f(n)

13 T(n) = T(n/2) + cn Where does this recurrence arise?

14 Solving the recurrence exactly

15 T(n) = 4T(n/2) + n

16 T(n) = 2T(n/2) + n2

17 T(n) = 2T(n/2) + n1/2

18 Recurrences Three basic behaviors Dominated by initial case
Dominated by base case All cases equal – we care about the depth


Download ppt "Richard Anderson Lecture 12, Winter 2019 Recurrences"

Similar presentations


Ads by Google