Download presentation
Presentation is loading. Please wait.
Published byKelley Dalton Modified over 8 years ago
1
CS 312: Algorithm Design & Analysis Lecture #2: Asymptotic Notation This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.Creative Commons Attribution-Share Alike 3.0 Unported License Slides by: Eric Ringger, with contributions from Mike Jones, Eric Mercer, Sean Warnick
2
Pop Quiz 1.What is the reward for submitting project reports early? 2.How many penalty-free late days are in your budget for the semester? 3.How many penalty-free late days can you use on any one project? 4.What is the penalty for late submission of project reports (after you’ve used your penalty-free late days)? 5.What is the time of day for project deadlines? 6.T/F: You may submit late regular homework assignments. 7.T/F: You can do a whiteboard experience alone.
3
Announcements TA and instructor office hours are on the course wiki Project #1 Due dates on the schedule Instructions linked from the online schedule We’ll cover the mathematical ideas in class Help session with TA Purpose of help sessions HW #0 C# surprises?
4
Objectives Revisit orders of growth Formally introduce asymptotic notation: O, Classify functions in asymptotic orders of growth
5
Orders of Growth
6
nlog 2 nnnlog 2 nn2n2 n3n3 103.3103.3*1010 2 10 3 10 2 6.610 2 6.6*10 2 10 4 10 6 10 3 1010 3 1.0*10 4 10 6 10 9 10 4 1310 4 1.3*10 5 10 8 10 12 10 5 1710 5 1.7*10 610 10 15 10 6 2010 6 2.0*10 7 10 12 10 18
7
Orders of Growth nlog 2 nnnlog 2 nn2n2 n3n3 2n2n n!n! 103.3103.3*1010 2 10 3 ~10 3 ~3.6*10 6 10 2 6.610 2 6.6*10 2 10 4 10 6 ~1.3*10 30 ~9*10 157 10 3 1010 3 1.0*10 4 10 6 10 9 …… 10 4 1310 4 1.3*10 5 10 8 10 12 10 5 1710 5 1.7*10 610 10 15 10 6 2010 6 2.0*10 7 10 12 10 18 Efficient
8
Kinds of Efficiency Need to decide which instance of a given size to use as the representative for that class: Algorithm Domain Instance size 1 2 3 4 5 Instances Average Case (over all possible instances) Worst Case Best Case
9
Asymptotic Notation
10
Definitions: given an asymptotically non-negative fn. g(n),
11
Notational Convention
12
Asymptotic Notation f(n) c g(n) n0n0 f(n) c g(n) n0n0 n0n0 c 1 g(n) c 2 g(n) f(n)
13
Cases vs. Orders
16
Example Show that Must find positive constants c 1, c 2, n 0 such that Divide through by n 2 to get This proof is constructive
17
Another Example
18
Other proof types? Induction Optional example on HW #1 Deduction Others!
19
Duality
20
g(n) in O(f(n)) means all instances of size n are solvable within c 1 f(n) time. f(n) in Ω(g(n)) means at least one instance of size n is solvable in c 2 g(n) time. … for worst case performance.
21
Duality Suppose t(n) models worst case behavior of an algorithm. Then t(n) = O(n!) means every instance of size n is solvable in factorial time. Then t(n) = (n!) means at least one instance of size n requires factorial time. But infinitely many size-n instances may require n 2 time! Using our definition of , a bound on the worst case isn’t useful. 1. Change the definition. But then duality fails. 2. Live with it. That’s what we’ll do. Similarly, using duality we also conclude that a O bound on a best case isn’t useful!
22
The Limit Rule
24
Example
26
Useful Identity: L’Hopital’s Rule
27
Review: Log Identities
29
Review: More Logarithms
31
Assignment HW #1: 0.1 (a-e, g, m) in the textbook Problems like these will appear on the mid-term and final exams Justify your answers and show your work Remember: Don’t spend more than 2 focused hours on the homework exercises. If you reach 2 hours of concentrated effort, 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.
32
The following slides are extra
33
Addition
35
Multiplication
37
Classic Multiplication 5001 x 502 10002 0 + 25005 2510502 5001 x 502 25005 0 + 10002 2510502 American Style English Style O(n 2 ) for 2 n-digit numbers
38
Multiplication a la Francais / Russe
40
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
41
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
42
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
43
Multiplication a la russe 98112341234 4902468 24549364936 1229872 61 19744 19744 30 39488 15 78976 78976 7 157952 157952 3 315904 315904 1 631808 + 631808 1210554. Don’t need to know multiplication tables Just need to know how to double, halve, and add!
44
Multiplication a la russe 101 2 x 2 101 2 101 101 101 10 1010 0 1 10100 10100 11001 2 = 25 10 101 0 10100 11001 2 = 25 10 O(n 2 )
45
Arabic Multiplication 9 8 1 12341234 0 0 0 1 1 0 2 2 0 3 3 0 9 8 1 8 6 2 7 4 3 6 2 4 12101210 5 5 4
46
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)
47
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)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.