Karatsuba Algorithm and Asymptotic Notation
320 likes | 338 Vues
This warm-up exercise explores the asymptotic runtime of the Karatsuba algorithm using the Tree method and introduces the concept of guess and check, induction, and the Master Theorem.
Karatsuba Algorithm and Asymptotic Notation
E N D
Presentation Transcript
CS4102 Algorithms Fall 2018 Warm Up What is the asymptotic run time of MergeSort if its recurrence is
Tree method • per level levels of recursion … … … … …
Today’s Keywords • Karatsuba • Guess and check Method • Induction • Master Theorem
CLRS Readings • Chapter 4
Homework • Hw1 due 11pm Wednesday, Sept 12 • Written (use Latex!) • Asymptotic notation • Recurrences • Divide and conquer
Karatsuba Algorithm Recursively compute: , , Return a b c d Pseudo-code x = Karatsuba(a,c) y = Karatsuba(a,d) z = Karatsuba(a+b,c+d)-x-y Return 10nx +10n/2z+y
Karatsuba 3. Use asymptotic notation to simplify … … … … … … … … …
Karatsuba 3. Use asymptotic notation to simplify Math, math, and more math…(on board, see lecture supplemental)
Recurrence Solving Techniques Tree Guess/Check “Cookbook” Substitution ? (induction)
Induction (review) Goal: holds Base case(s): holds Hypothesis: holds Inductive step:
Guess and Check Intuition • To Prove: • Consider: • Goal: show s.t. • (definition of big-O) • Technique: Induction • Base cases: • show for a small number of cases • Hypothesis: • Inductivestep:
Karatsuba Guess and Check (Loose) Goal: Base cases: … up to some small Hypothesis: Inductive step:
Mergesort Guess and Check Goal: Base cases: … up to some small Hypothesis: Inductive step:
Karatsuba Guess and Check Goal: Base cases: by inspection, holds for small (at home) Hypothesis: Inductive step:
What if we leave out the ? Goal: Base cases: by inspection, holds for small (at home) Hypothesis: Inductive step: Induction failed! What we wanted: What we got:
“Bad Mergesort” Guess and Check Goal: Base cases: … up to some small Hypothesis: Inductive step:
Recurrence Solving Techniques Tree Guess/Check “Cookbook” Substitution ?
Observation • Divide: time, • Conquer: recurse on small problems, size • Combine: time • Recurrence: • Many D&C recurrences are of form:
General … … … … … … … … … … … …
3 Cases Case 1: Most work happens at the leaves Case 2: Work happens consistently throughout Case 3: Most work happens at top of tree
Master Theorem • Case 1: if for some constant , then • Case 2: if , then • Case 3: if for some constant , and if for some constant and all sufficiently large , then
Proof of Case 1 , Insert math here… Conclusion:
Master Theorem Example 1 • Case 1: if for some constant , then • Case 2: if , then • Case 3: if for some constant , and if for some constant and all sufficiently large , then Case 2
Tree method … … … … …
Master Theorem Example 2 • Case 1: if for some constant , then • Case 2: if , then • Case 3: if for some constant , and if for some constant and all sufficiently large , then Case 1
Tree method … … … … … … … … … … …
Master Theorem Example 3 • Case 1: if for some constant , then • Case 2: if , then • Case 3: if for some constant , and if for some constant and all sufficiently large , then Case 1
Karatsuba … … … … … … … … …
Master Theorem Example 4 • Case 1: if for some constant , then • Case 2: if , then • Case 3: if for some constant , and if for some constant and all sufficiently large , then Case 3
Tree method … … … … …
Homework Help Algorithm • Algorithm: How to ask a question about homework (efficiently) • Check to see if your question is already on piazza • If it’s not on piazza, ask on piazza • Look for other questions you know the answer to, and provide answers to any that you see • TA office hours • Instructor office hours • Email, set up a meeting