SlideShare ist ein Scribd-Unternehmen logo
1 von 17
Downloaden Sie, um offline zu lesen
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))

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Mehr von 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
 

Mehr von 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
 

Kürzlich hochgeladen

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 

Kürzlich hochgeladen (20)

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 

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))