SlideShare une entreprise Scribd logo
1  sur  17
Télécharger pour lire hors ligne
Lecture 2:
     Asymptotic Notation
         Steven Skiena

Department of Computer Science
 State University of New York
 Stony Brook, NY 11794–4400

http://www.cs.sunysb.edu/∼skiena
Problem of the Day
The knapsack problem is as follows: given a set of integers
S = {s1, s2, . . . , sn}, and a given target number T , find a
subset of S which adds up exactly to T . For example, within
S = {1, 2, 5, 9, 10} there is a subset which adds up to T = 22
but not T = 23.
Find counterexamples to each of the following algorithms for
the knapsack problem. That is, give an S and T such that
the subset is selected using the algorithm does not leave the
knapsack completely full, even though such a solution exists.
Solution

 • Put the elements of S in the knapsack in left to right order
   if they fit, i.e. the first-fit algorithm?
 • Put the elements of S in the knapsack from smallest to
   largest, i.e. the best-fit algorithm?
 • Put the elements of S in the knapsack from largest to
   smallest?
The RAM Model of Computation
Algorithms are an important and durable part of computer
science because they can be studied in a machine/language
independent way.
This is because we use the RAM model of computation for
all our analysis.
 • Each “simple” operation (+, -, =, if, call) takes 1 step.
 • Loops and subroutine calls are not simple operations.
   They depend upon the size of the data and the contents
   of a subroutine. “Sort” is not a single step operation.
• Each memory access takes exactly 1 step.
We measure the run time of an algorithm by counting the
number of steps, where:
This model is useful and accurate in the same sense as the
flat-earth model (which is useful)!
Worst-Case Complexity
The worst case complexity of an algorithm is the function
defined by the maximum number of steps taken on any
instance of size n.
              Number of
              Steps                                           Worst   Case




                                                              Average Case




                          .
                          .
                                                              Best Case




                          1   2         3        4   ......                  N

                                  Problem Size
Best-Case and Average-Case Complexity
The best case complexity of an algorithm is the function
defined by the minimum number of steps taken on any
instance of size n.
The average-case complexity of the algorithm is the function
defined by an average number of steps taken on any instance
of size n.
Each of these complexities defines a numerical function: time
vs. size!
Exact Analysis is Hard!
Best, worst, and average are difficult to deal with precisely
because the details are very complicated:




                       1   2   3   4   ......




It easier to talk about upper and lower bounds of the function.
Asymptotic notation (O, Θ, Ω) are as well as we can
practically deal with complexity functions.
Names of Bounding Functions

 • g(n) = O(f (n)) means C × f (n) is an upper bound on
   g(n).
 • g(n) = Ω(f (n)) means C ×f (n) is a lower bound on g(n).
 • g(n) = Θ(f (n)) means C1 × f (n) is an upper bound on
   g(n) and C2 × f (n) is a lower bound on g(n).
C, C1, and C2 are all constants independent of n.
O, Ω, and Θ

                                                            c1*g(n)
                  c*g(n)


                                      f(n)                    f(n)

                  f(n)                c*g(n)
                                                                     c2*g(n)




                    n                        n                        n
       n0                  n0                    n0

            (a)                 (b)                   (c)



The definitions imply a constant n0 beyond which they are
satisfied. We do not care about small values of n.
Formal Definitions

 • f (n) = O(g(n)) if there are positive constants n0 and c
   such that to the right of n0, the value of f (n) always lies
   on or below c · g(n).
 • f (n) = Ω(g(n)) if there are positive constants n0 and c
   such that to the right of n0, the value of f (n) always lies
   on or above c · g(n).
 • f (n) = Θ(g(n)) if there exist positive constants n0 , c1, and
   c2 such that to the right of n0 , the value of f (n) always lies
   between c1 · g(n) and c2 · g(n) inclusive.
Big Oh Examples

3n2 − 100n + 6 = O(n2 ) because 3n2 > 3n2 − 100n + 6
3n2 − 100n + 6 = O(n3 ) because .01n3 > 3n2 − 100n + 6
3n2 − 100n + 6 = O(n) because c · n < 3n2 when n > c


Think of the equality as meaning in the set of functions.
Big Omega Examples

3n2 − 100n + 6 = Ω(n2 ) because 2.99n2 < 3n2 − 100n + 6
3n2 − 100n + 6 = Ω(n3 ) because 3n2 − 100n + 6 < n3
                                 1010
3n − 100n + 6 = Ω(n) because 10 n < 3n2 − 100 + 6
  2
Big Theta Examples

     3n2 − 100n + 6 = Θ(n2 ) because O and Ω
     3n2 − 100n + 6 = Θ(n3 ) because O only
     3n2 − 100n + 6 = Θ(n) because Ω only
Big Oh Addition/Subtraction

Suppose f (n) = O(n2 ) and g(n) = O(n2 ).
 • What do we know about g (n) = f (n) + g(n)? Adding the
   bounding constants shows g (n) = O(n2 ).
 • What do we know about g (n) = f (n) − |g(n)|? Since
   the bounding constants don’t necessary cancel, g (n) =
   O(n2 )
We know nothing about the lower bounds on g and g
because we know nothing about lower bounds on f and g.
Big Oh Multiplication by Constant
Multiplication by a constant does not change the asymptotics:
                  O(c · f (n)) → O(f (n))
                  Ω(c · f (n)) → Ω(f (n))
                  Θ(c · f (n)) → Θ(f (n))
Big Oh Multiplication by Function
But when both functions in a product are increasing, both are
important:

           O(f (n)) ∗ O(g(n)) → O(f (n) ∗ g(n))
           Ω(f (n)) ∗ Ω(g(n)) → Ω(f (n) ∗ g(n))
           Θ(f (n)) ∗ Θ(g(n)) → Θ(f (n) ∗ g(n))

Contenu connexe

Tendances

Numerical analysis convexity, concavity
Numerical analysis  convexity, concavityNumerical analysis  convexity, concavity
Numerical analysis convexity, concavity
SHAMJITH KM
 
Application of derivatives
Application of derivativesApplication of derivatives
Application of derivatives
indu thakur
 
limits and continuity
limits and continuitylimits and continuity
limits and continuity
Elias Dinsa
 
READ Workshop Appendix
READ Workshop AppendixREAD Workshop Appendix
READ Workshop Appendix
Ban Har Yeap
 

Tendances (20)

Numerical analysis convexity, concavity
Numerical analysis  convexity, concavityNumerical analysis  convexity, concavity
Numerical analysis convexity, concavity
 
Linear Algebra
Linear AlgebraLinear Algebra
Linear Algebra
 
Pinning and facetting in multiphase LBMs
Pinning and facetting in multiphase LBMsPinning and facetting in multiphase LBMs
Pinning and facetting in multiphase LBMs
 
Ps02 cmth03 unit 1
Ps02 cmth03 unit 1Ps02 cmth03 unit 1
Ps02 cmth03 unit 1
 
Application of derivatives 2 maxima and minima
Application of derivatives 2  maxima and minimaApplication of derivatives 2  maxima and minima
Application of derivatives 2 maxima and minima
 
Limits
LimitsLimits
Limits
 
Limits, Continuity & Differentiation (Theory)
Limits, Continuity & Differentiation (Theory)Limits, Continuity & Differentiation (Theory)
Limits, Continuity & Differentiation (Theory)
 
Signals Processing Homework Help
Signals Processing Homework HelpSignals Processing Homework Help
Signals Processing Homework Help
 
Application of differentiation
Application of differentiationApplication of differentiation
Application of differentiation
 
Application of derivatives
Application of derivativesApplication of derivatives
Application of derivatives
 
Lesson 19: Maximum and Minimum Values
Lesson 19: Maximum and Minimum ValuesLesson 19: Maximum and Minimum Values
Lesson 19: Maximum and Minimum Values
 
Limits of functions
Limits of functionsLimits of functions
Limits of functions
 
application of partial differentiation
application of partial differentiationapplication of partial differentiation
application of partial differentiation
 
Dynamical systems solved ex
Dynamical systems solved exDynamical systems solved ex
Dynamical systems solved ex
 
limits and continuity
limits and continuitylimits and continuity
limits and continuity
 
READ Workshop Appendix
READ Workshop AppendixREAD Workshop Appendix
READ Workshop Appendix
 
Introduction to differentiation
Introduction to differentiationIntroduction to differentiation
Introduction to differentiation
 
Basic mathematics differentiation application
Basic mathematics differentiation applicationBasic mathematics differentiation application
Basic mathematics differentiation application
 
Workshop presentations l_bworkshop_reis
Workshop presentations l_bworkshop_reisWorkshop presentations l_bworkshop_reis
Workshop presentations l_bworkshop_reis
 
Limit, Continuity and Differentiability for JEE Main 2014
Limit, Continuity and Differentiability for JEE Main 2014Limit, Continuity and Differentiability for JEE Main 2014
Limit, Continuity and Differentiability for JEE Main 2014
 

Similaire à Skiena algorithm 2007 lecture02 asymptotic notation

lecture 1
lecture 1lecture 1
lecture 1
sajinsc
 
Skiena algorithm 2007 lecture09 linear sorting
Skiena algorithm 2007 lecture09 linear sortingSkiena algorithm 2007 lecture09 linear sorting
Skiena algorithm 2007 lecture09 linear sorting
zukun
 

Similaire à Skiena algorithm 2007 lecture02 asymptotic notation (20)

Anlysis and design of algorithms part 1
Anlysis and design of algorithms part 1Anlysis and design of algorithms part 1
Anlysis and design of algorithms part 1
 
Unit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdfUnit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdf
 
DAA_LECT_2.pdf
DAA_LECT_2.pdfDAA_LECT_2.pdf
DAA_LECT_2.pdf
 
asymptotic notations i
asymptotic notations iasymptotic notations i
asymptotic notations i
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithms
 
CMSC 56 | Lecture 8: Growth of Functions
CMSC 56 | Lecture 8: Growth of FunctionsCMSC 56 | Lecture 8: Growth of Functions
CMSC 56 | Lecture 8: Growth of Functions
 
Lecture 3(a) Asymptotic-analysis.pdf
Lecture 3(a) Asymptotic-analysis.pdfLecture 3(a) Asymptotic-analysis.pdf
Lecture 3(a) Asymptotic-analysis.pdf
 
Asymptotic Notation and Complexity
Asymptotic Notation and ComplexityAsymptotic Notation and Complexity
Asymptotic Notation and Complexity
 
Design and analysis of algorithm ppt ppt
Design and analysis of algorithm ppt pptDesign and analysis of algorithm ppt ppt
Design and analysis of algorithm ppt ppt
 
Asymptotic Notation
Asymptotic NotationAsymptotic Notation
Asymptotic Notation
 
Asymptotic notation
Asymptotic notationAsymptotic notation
Asymptotic notation
 
big_oh
big_ohbig_oh
big_oh
 
02 asymp
02 asymp02 asymp
02 asymp
 
lecture 1
lecture 1lecture 1
lecture 1
 
1_Asymptotic_Notation_pptx.pptx
1_Asymptotic_Notation_pptx.pptx1_Asymptotic_Notation_pptx.pptx
1_Asymptotic_Notation_pptx.pptx
 
Asymptotics 140510003721-phpapp02
Asymptotics 140510003721-phpapp02Asymptotics 140510003721-phpapp02
Asymptotics 140510003721-phpapp02
 
Skiena algorithm 2007 lecture09 linear sorting
Skiena algorithm 2007 lecture09 linear sortingSkiena algorithm 2007 lecture09 linear sorting
Skiena algorithm 2007 lecture09 linear sorting
 
Dr hasany 2467_16649_1_lec-2-zabist
Dr hasany 2467_16649_1_lec-2-zabistDr hasany 2467_16649_1_lec-2-zabist
Dr hasany 2467_16649_1_lec-2-zabist
 
Asymptotic Notation
Asymptotic NotationAsymptotic Notation
Asymptotic Notation
 
04. Growth_Rate_AND_Asymptotic Notations_.pptx
04. Growth_Rate_AND_Asymptotic Notations_.pptx04. Growth_Rate_AND_Asymptotic Notations_.pptx
04. Growth_Rate_AND_Asymptotic Notations_.pptx
 

Plus de zukun

My lyn tutorial 2009
My lyn tutorial 2009My lyn tutorial 2009
My lyn tutorial 2009
zukun
 
ETHZ CV2012: Tutorial openCV
ETHZ CV2012: Tutorial openCVETHZ CV2012: Tutorial openCV
ETHZ CV2012: Tutorial openCV
zukun
 
ETHZ CV2012: Information
ETHZ CV2012: InformationETHZ CV2012: Information
ETHZ CV2012: Information
zukun
 
Siwei lyu: natural image statistics
Siwei lyu: natural image statisticsSiwei lyu: natural image statistics
Siwei lyu: natural image statistics
zukun
 
Lecture9 camera calibration
Lecture9 camera calibrationLecture9 camera calibration
Lecture9 camera calibration
zukun
 
Brunelli 2008: template matching techniques in computer vision
Brunelli 2008: template matching techniques in computer visionBrunelli 2008: template matching techniques in computer vision
Brunelli 2008: template matching techniques in computer vision
zukun
 
Modern features-part-4-evaluation
Modern features-part-4-evaluationModern features-part-4-evaluation
Modern features-part-4-evaluation
zukun
 
Modern features-part-3-software
Modern features-part-3-softwareModern features-part-3-software
Modern features-part-3-software
zukun
 
Modern features-part-2-descriptors
Modern features-part-2-descriptorsModern features-part-2-descriptors
Modern features-part-2-descriptors
zukun
 
Modern features-part-1-detectors
Modern features-part-1-detectorsModern features-part-1-detectors
Modern features-part-1-detectors
zukun
 
Modern features-part-0-intro
Modern features-part-0-introModern features-part-0-intro
Modern features-part-0-intro
zukun
 
Lecture 02 internet video search
Lecture 02 internet video searchLecture 02 internet video search
Lecture 02 internet video search
zukun
 
Lecture 01 internet video search
Lecture 01 internet video searchLecture 01 internet video search
Lecture 01 internet video search
zukun
 
Lecture 03 internet video search
Lecture 03 internet video searchLecture 03 internet video search
Lecture 03 internet video search
zukun
 
Icml2012 tutorial representation_learning
Icml2012 tutorial representation_learningIcml2012 tutorial representation_learning
Icml2012 tutorial representation_learning
zukun
 
Advances in discrete energy minimisation for computer vision
Advances in discrete energy minimisation for computer visionAdvances in discrete energy minimisation for computer vision
Advances in discrete energy minimisation for computer vision
zukun
 
Gephi tutorial: quick start
Gephi tutorial: quick startGephi tutorial: quick start
Gephi tutorial: quick start
zukun
 
EM algorithm and its application in probabilistic latent semantic analysis
EM algorithm and its application in probabilistic latent semantic analysisEM algorithm and its application in probabilistic latent semantic analysis
EM algorithm and its application in probabilistic latent semantic analysis
zukun
 
Object recognition with pictorial structures
Object recognition with pictorial structuresObject recognition with pictorial structures
Object recognition with pictorial structures
zukun
 
Iccv2011 learning spatiotemporal graphs of human activities
Iccv2011 learning spatiotemporal graphs of human activities Iccv2011 learning spatiotemporal graphs of human activities
Iccv2011 learning spatiotemporal graphs of human activities
zukun
 

Plus de zukun (20)

My lyn tutorial 2009
My lyn tutorial 2009My lyn tutorial 2009
My lyn tutorial 2009
 
ETHZ CV2012: Tutorial openCV
ETHZ CV2012: Tutorial openCVETHZ CV2012: Tutorial openCV
ETHZ CV2012: Tutorial openCV
 
ETHZ CV2012: Information
ETHZ CV2012: InformationETHZ CV2012: Information
ETHZ CV2012: Information
 
Siwei lyu: natural image statistics
Siwei lyu: natural image statisticsSiwei lyu: natural image statistics
Siwei lyu: natural image statistics
 
Lecture9 camera calibration
Lecture9 camera calibrationLecture9 camera calibration
Lecture9 camera calibration
 
Brunelli 2008: template matching techniques in computer vision
Brunelli 2008: template matching techniques in computer visionBrunelli 2008: template matching techniques in computer vision
Brunelli 2008: template matching techniques in computer vision
 
Modern features-part-4-evaluation
Modern features-part-4-evaluationModern features-part-4-evaluation
Modern features-part-4-evaluation
 
Modern features-part-3-software
Modern features-part-3-softwareModern features-part-3-software
Modern features-part-3-software
 
Modern features-part-2-descriptors
Modern features-part-2-descriptorsModern features-part-2-descriptors
Modern features-part-2-descriptors
 
Modern features-part-1-detectors
Modern features-part-1-detectorsModern features-part-1-detectors
Modern features-part-1-detectors
 
Modern features-part-0-intro
Modern features-part-0-introModern features-part-0-intro
Modern features-part-0-intro
 
Lecture 02 internet video search
Lecture 02 internet video searchLecture 02 internet video search
Lecture 02 internet video search
 
Lecture 01 internet video search
Lecture 01 internet video searchLecture 01 internet video search
Lecture 01 internet video search
 
Lecture 03 internet video search
Lecture 03 internet video searchLecture 03 internet video search
Lecture 03 internet video search
 
Icml2012 tutorial representation_learning
Icml2012 tutorial representation_learningIcml2012 tutorial representation_learning
Icml2012 tutorial representation_learning
 
Advances in discrete energy minimisation for computer vision
Advances in discrete energy minimisation for computer visionAdvances in discrete energy minimisation for computer vision
Advances in discrete energy minimisation for computer vision
 
Gephi tutorial: quick start
Gephi tutorial: quick startGephi tutorial: quick start
Gephi tutorial: quick start
 
EM algorithm and its application in probabilistic latent semantic analysis
EM algorithm and its application in probabilistic latent semantic analysisEM algorithm and its application in probabilistic latent semantic analysis
EM algorithm and its application in probabilistic latent semantic analysis
 
Object recognition with pictorial structures
Object recognition with pictorial structuresObject recognition with pictorial structures
Object recognition with pictorial structures
 
Iccv2011 learning spatiotemporal graphs of human activities
Iccv2011 learning spatiotemporal graphs of human activities Iccv2011 learning spatiotemporal graphs of human activities
Iccv2011 learning spatiotemporal graphs of human activities
 

Dernier

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Dernier (20)

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 

Skiena algorithm 2007 lecture02 asymptotic notation

  • 1. Lecture 2: Asymptotic Notation Steven Skiena Department of Computer Science State University of New York Stony Brook, NY 11794–4400 http://www.cs.sunysb.edu/∼skiena
  • 2. Problem of the Day The knapsack problem is as follows: given a set of integers S = {s1, s2, . . . , sn}, and a given target number T , find a subset of S which adds up exactly to T . For example, within S = {1, 2, 5, 9, 10} there is a subset which adds up to T = 22 but not T = 23. Find counterexamples to each of the following algorithms for the knapsack problem. That is, give an S and T such that the subset is selected using the algorithm does not leave the knapsack completely full, even though such a solution exists.
  • 3. Solution • Put the elements of S in the knapsack in left to right order if they fit, i.e. the first-fit algorithm? • Put the elements of S in the knapsack from smallest to largest, i.e. the best-fit algorithm? • Put the elements of S in the knapsack from largest to smallest?
  • 4. The RAM Model of Computation Algorithms are an important and durable part of computer science because they can be studied in a machine/language independent way. This is because we use the RAM model of computation for all our analysis. • Each “simple” operation (+, -, =, if, call) takes 1 step. • Loops and subroutine calls are not simple operations. They depend upon the size of the data and the contents of a subroutine. “Sort” is not a single step operation.
  • 5. • Each memory access takes exactly 1 step. We measure the run time of an algorithm by counting the number of steps, where: This model is useful and accurate in the same sense as the flat-earth model (which is useful)!
  • 6. Worst-Case Complexity The worst case complexity of an algorithm is the function defined by the maximum number of steps taken on any instance of size n. Number of Steps Worst Case Average Case . . Best Case 1 2 3 4 ...... N Problem Size
  • 7. Best-Case and Average-Case Complexity The best case complexity of an algorithm is the function defined by the minimum number of steps taken on any instance of size n. The average-case complexity of the algorithm is the function defined by an average number of steps taken on any instance of size n. Each of these complexities defines a numerical function: time vs. size!
  • 8. Exact Analysis is Hard! Best, worst, and average are difficult to deal with precisely because the details are very complicated: 1 2 3 4 ...... It easier to talk about upper and lower bounds of the function. Asymptotic notation (O, Θ, Ω) are as well as we can practically deal with complexity functions.
  • 9. Names of Bounding Functions • g(n) = O(f (n)) means C × f (n) is an upper bound on g(n). • g(n) = Ω(f (n)) means C ×f (n) is a lower bound on g(n). • g(n) = Θ(f (n)) means C1 × f (n) is an upper bound on g(n) and C2 × f (n) is a lower bound on g(n). C, C1, and C2 are all constants independent of n.
  • 10. O, Ω, and Θ c1*g(n) c*g(n) f(n) f(n) f(n) c*g(n) c2*g(n) n n n n0 n0 n0 (a) (b) (c) The definitions imply a constant n0 beyond which they are satisfied. We do not care about small values of n.
  • 11. Formal Definitions • f (n) = O(g(n)) if there are positive constants n0 and c such that to the right of n0, the value of f (n) always lies on or below c · g(n). • f (n) = Ω(g(n)) if there are positive constants n0 and c such that to the right of n0, the value of f (n) always lies on or above c · g(n). • f (n) = Θ(g(n)) if there exist positive constants n0 , c1, and c2 such that to the right of n0 , the value of f (n) always lies between c1 · g(n) and c2 · g(n) inclusive.
  • 12. Big Oh Examples 3n2 − 100n + 6 = O(n2 ) because 3n2 > 3n2 − 100n + 6 3n2 − 100n + 6 = O(n3 ) because .01n3 > 3n2 − 100n + 6 3n2 − 100n + 6 = O(n) because c · n < 3n2 when n > c Think of the equality as meaning in the set of functions.
  • 13. Big Omega Examples 3n2 − 100n + 6 = Ω(n2 ) because 2.99n2 < 3n2 − 100n + 6 3n2 − 100n + 6 = Ω(n3 ) because 3n2 − 100n + 6 < n3 1010 3n − 100n + 6 = Ω(n) because 10 n < 3n2 − 100 + 6 2
  • 14. Big Theta Examples 3n2 − 100n + 6 = Θ(n2 ) because O and Ω 3n2 − 100n + 6 = Θ(n3 ) because O only 3n2 − 100n + 6 = Θ(n) because Ω only
  • 15. Big Oh Addition/Subtraction Suppose f (n) = O(n2 ) and g(n) = O(n2 ). • What do we know about g (n) = f (n) + g(n)? Adding the bounding constants shows g (n) = O(n2 ). • What do we know about g (n) = f (n) − |g(n)|? Since the bounding constants don’t necessary cancel, g (n) = O(n2 ) We know nothing about the lower bounds on g and g because we know nothing about lower bounds on f and g.
  • 16. Big Oh Multiplication by Constant Multiplication by a constant does not change the asymptotics: O(c · f (n)) → O(f (n)) Ω(c · f (n)) → Ω(f (n)) Θ(c · f (n)) → Θ(f (n))
  • 17. Big Oh Multiplication by Function But when both functions in a product are increasing, both are important: O(f (n)) ∗ O(g(n)) → O(f (n) ∗ g(n)) Ω(f (n)) ∗ Ω(g(n)) → Ω(f (n) ∗ g(n)) Θ(f (n)) ∗ Θ(g(n)) → Θ(f (n) ∗ g(n))