400 likes | 530 Views
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.
E N D
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 • 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.
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
Objectives • Revisit orders of growth • Formally introduce asymptotic notation:O, W, Q • Classify functions in asymptotic orders of growth
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.
Orders of Growth Efficient
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
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),
Asymptotic Notation Definitions: given an asymptotically non-negative fn. g(n),
f(n) c2g(n) c g(n) f(n) f(n) c1g(n) c g(n) n0 n0 n0 Asymptotic Notation
Distinguishing from • Can you draw a function that is in but not ?
Distinguishing from • Can you draw a function that is in but not ?
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
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
Other proof types? • Induction • Optional example on HW #1 • Deduction • Others!
Useful Identity: L’Hopital’s Rule Applicable when lim f(n) = lim g(n) = 0 and when lim f(n) = lim g(n) =
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.
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
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
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
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
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)
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)