1 / 32

Karatsuba Algorithm and Asymptotic Notation

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.

thompkins
Télécharger la présentation

Karatsuba Algorithm and Asymptotic Notation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS4102 Algorithms Fall 2018 Warm Up What is the asymptotic run time of MergeSort if its recurrence is

  2. Tree method • per level levels of recursion … … … … …

  3. Today’s Keywords • Karatsuba • Guess and check Method • Induction • Master Theorem

  4. CLRS Readings • Chapter 4

  5. Homework • Hw1 due 11pm Wednesday, Sept 12 • Written (use Latex!) • Asymptotic notation • Recurrences • Divide and conquer

  6. 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

  7. Karatsuba 3. Use asymptotic notation to simplify … … … … … … … … …

  8. Karatsuba 3. Use asymptotic notation to simplify Math, math, and more math…(on board, see lecture supplemental)

  9. Recurrence Solving Techniques Tree Guess/Check “Cookbook” Substitution ? (induction)

  10. Induction (review) Goal: holds Base case(s): holds Hypothesis: holds Inductive step:

  11. 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:

  12. Karatsuba Guess and Check (Loose) Goal: Base cases: … up to some small Hypothesis: Inductive step:

  13. Mergesort Guess and Check Goal: Base cases: … up to some small Hypothesis: Inductive step:

  14. Karatsuba Guess and Check Goal: Base cases: by inspection, holds for small (at home) Hypothesis: Inductive step:

  15. 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:

  16. “Bad Mergesort” Guess and Check Goal: Base cases: … up to some small Hypothesis: Inductive step:

  17. Recurrence Solving Techniques Tree Guess/Check “Cookbook” Substitution ?

  18. Observation • Divide: time, • Conquer: recurse on small problems, size • Combine: time • Recurrence: • Many D&C recurrences are of form:

  19. General … … … … … … … … … … … …

  20. 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

  21. 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

  22. Proof of Case 1 , Insert math here… Conclusion:

  23. 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

  24. Tree method … … … … …

  25. 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

  26. Tree method … … … … … … … … … … …

  27. 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

  28. Karatsuba … … … … … … … … …

  29. 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

  30. Tree method … … … … …

  31. 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

More Related