1 / 40

CS 312: Algorithm Analysis

This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License . CS 312: Algorithm Analysis. Lecture #2: Asymptotic Notation. Slides by: Eric Ringger, with contributions from Mike Jones, Eric Mercer, Sean Warnick. Quiz.

eben
Download Presentation

CS 312: Algorithm Analysis

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. This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License. CS 312: Algorithm Analysis Lecture #2: Asymptotic Notation Slides by: Eric Ringger, with contributions from Mike Jones, Eric Mercer, Sean Warnick

  2. Quiz • What is the reward for submitting project reports early? • How many penalty-free late days are in your budget for the semester? • How many penalty-free late days can you use on any one project? • What is the penalty for late submission of project reports (after you’ve used your penalty-free late days)? • T/F: You may submit late regular homework assignments.

  3. Announcements • Your initial experiences with Visual Studio? • My office hours updated: Tu & Th 2-3 and by appointment • TA office hours are on the course wiki • Different kinds of TAs • Project #1 • Instructions are linked from the online schedule • Help session with TA • Thursday at 4pm • In the Windows help lab (1066 TMCB) • Focus on intro. to C# and Visual Studio • We’ll cover the mathematical ideas in class • Purpose of help sessions

  4. Objectives • Revisit orders of growth • Formally introduce asymptotic notation:O, W, Q • Classify functions in asymptotic orders of growth

  5. Orders of Growth • Efficiency: how cost grows with the size/ difficulty n of a given problem instance. • C(n): the cost (e.g., number of steps) required by an algorithm on an input of size / difficulty n. • Order of growth: the functional form of C(n) up to a constant multipleas ngoes to infinity.

  6. Orders of Growth

  7. Orders of Growth Efficient

  8. Worst Case • Best Case Kinds of Efficiency • Need to decide which instance of a given size to use as the representative for that class: Algorithm Domain Instances • Average Case (over all possible instances) 1 2 3 4 5 Instance size

  9. Translation: An asymptotically non-negative function f(n) belongs to the set Q(g(n)) iff there exist positive constants c1 and c2such that f(n)can be “sandwiched” between c1g(n) and c2g(n), scaled versions of g(n), for sufficiently large n. Convention: Asymptotic Notation Definition: given an asymptotically non-negative fn. g(n),

  10. Asymptotic Notation Definitions: given an asymptotically non-negative fn. g(n),

  11. f(n) c2g(n) c g(n) f(n) f(n) c1g(n) c g(n) n0 n0 n0 Asymptotic Notation

  12. Distinguishing from • Can you draw a function that is in but not ?

  13. Distinguishing from • Can you draw a function that is in but not ?

  14. Show that • Must find positive constants c1, c2, n0 such that • Divide through by n2 to get Example • Hint: consider one side of the inequality at a time: • for n0=7 we have c1 1/14 • for n0=6 we have c2 >1/2; works for larger n0=7 as well • This proof is constructive

  15. Another Example Show that • Use proof by contradiction: assume that • Suppose positive constants c2, n0 exist such that • But this implies that • i.e., is bounded by , a constant • But is unbounded; hence we have a contradiction. • Thus, our assumption was false; hence we have shown that

  16. Other proof types? • Induction • Optional example on HW #1 • Deduction • Others!

  17. Duality

  18. The Limit Rule

  19. The Limit Rule

  20. Example

  21. Example

  22. Useful Identity: L’Hopital’s Rule Applicable when lim f(n) = lim g(n) = 0 and when lim f(n) = lim g(n) = 

  23. Review: Log Identities

  24. Review: Log Identities

  25. Review: More Logarithms

  26. Review: More Logarithms

  27. Assignment • Read: Section 1.3 • HW #1: 0.1 (a-e, g, m) in the textbook • Optional: 0.3 (a) • Remember: • Don’t spend more than 2 focused hours on the homework exercises. • If you reach 2 hours of concentratedeffort, stop and make a note to that effect on your paper (unless you’re having fun and want to continue). • The TAs will take that into consideration when grading.

  28. The following slides are extra

  29. Addition

  30. Addition

  31. Multiplication

  32. Multiplication

  33. Classic Multiplication American Style English Style 5001 x 502 10002 0 + 25005 2510502 5001 x 502 25005 0 + 10002 2510502 O(n2) for 2 n-digit numbers

  34. Multiplication a la Francais / Russe

  35. Multiplication a la Francais / Russe

  36. Mulitplication a la Francais / Russe function multiply(x,y) Input: Two n-bit integers x and y, where y  0 Output: Their product if y = 0: return 0 if y = 1: return x z = multiply(x, floor(y/2)) if y is even: return 2z else: return x+2z

  37. Mulitplication a la Francais / Russe function multiply(x,y) Input: Two n-bit integers x and y, where y  0 Output: Their product if y = 0: return 0 if y = 1: return x z = multiply(x, floor(y/2)) if y is even: return 2z else: return x+2z

  38. 9 8 1 0 0 0 1 2 3 4 1 2 1 0 9 8 1 1 1 0 8 6 2 2 2 0 7 4 3 3 3 0 6 2 4 5 5 4 Arabic Multiplication

  39. Division function divide(x,y) Input: Two n-bit integers x and y, where y  1 Output: The quotient and remainder of x divided by y if x=0: return (q, r) = (0,0) (q, r) = divide(floor(x/2),y) q=2*q, r=2*r if x is odd: r=r+1 if r  y: r=r-y, q=q+1 return (q, r)

  40. Division function divide(x,y) Input: Two n-bit integers x and y, where y  1 Output: The quotient and remainder of x divided by y if x=0: return (q, r) = (0,0) (q, r) = divide(floor(x/2),y) q=2*q, r=2*r if x is odd: r=r+1 if r  y: r=r-y, q=q+1 return (q, r)

More Related