SlideShare a Scribd company logo
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))
Ad

More Related Content

What's hot (20)

Numerical analysis convexity, concavity
Numerical analysis  convexity, concavityNumerical analysis  convexity, concavity
Numerical analysis convexity, concavity
SHAMJITH KM
 
Linear Algebra
Linear AlgebraLinear Algebra
Linear Algebra
Maths Tutoring
 
Pinning and facetting in multiphase LBMs
Pinning and facetting in multiphase LBMsPinning and facetting in multiphase LBMs
Pinning and facetting in multiphase LBMs
Tim Reis
 
Ps02 cmth03 unit 1
Ps02 cmth03 unit 1Ps02 cmth03 unit 1
Ps02 cmth03 unit 1
Prakash Dabhi
 
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
sudersana viswanathan
 
Limits
LimitsLimits
Limits
admercano101
 
Limits, Continuity & Differentiation (Theory)
Limits, Continuity & Differentiation (Theory)Limits, Continuity & Differentiation (Theory)
Limits, Continuity & Differentiation (Theory)
Eduron e-Learning Private Limited
 
Signals Processing Homework Help
Signals Processing Homework HelpSignals Processing Homework Help
Signals Processing Homework Help
Matlab Assignment Experts
 
Application of differentiation
Application of differentiationApplication of differentiation
Application of differentiation
Lily Maryati
 
Application of derivatives
Application of derivativesApplication of derivatives
Application of derivatives
indu thakur
 
Lesson 19: Maximum and Minimum Values
Lesson 19: Maximum and Minimum ValuesLesson 19: Maximum and Minimum Values
Lesson 19: Maximum and Minimum Values
Matthew Leingang
 
Limits of functions
Limits of functionsLimits of functions
Limits of functions
Louie Joy Rosit
 
application of partial differentiation
application of partial differentiationapplication of partial differentiation
application of partial differentiation
eteaching
 
Dynamical systems solved ex
Dynamical systems solved exDynamical systems solved ex
Dynamical systems solved ex
Maths Tutoring
 
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
 
Introduction to differentiation
Introduction to differentiationIntroduction to differentiation
Introduction to differentiation
Shaun Wilson
 
Basic mathematics differentiation application
Basic mathematics differentiation applicationBasic mathematics differentiation application
Basic mathematics differentiation application
Muhammad Luthfan
 
Workshop presentations l_bworkshop_reis
Workshop presentations l_bworkshop_reisWorkshop presentations l_bworkshop_reis
Workshop presentations l_bworkshop_reis
Tim 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
Ednexa
 
Numerical analysis convexity, concavity
Numerical analysis  convexity, concavityNumerical analysis  convexity, concavity
Numerical analysis convexity, concavity
SHAMJITH KM
 
Pinning and facetting in multiphase LBMs
Pinning and facetting in multiphase LBMsPinning and facetting in multiphase LBMs
Pinning and facetting in multiphase LBMs
Tim Reis
 
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
sudersana viswanathan
 
Application of differentiation
Application of differentiationApplication of differentiation
Application of differentiation
Lily Maryati
 
Application of derivatives
Application of derivativesApplication of derivatives
Application of derivatives
indu thakur
 
Lesson 19: Maximum and Minimum Values
Lesson 19: Maximum and Minimum ValuesLesson 19: Maximum and Minimum Values
Lesson 19: Maximum and Minimum Values
Matthew Leingang
 
application of partial differentiation
application of partial differentiationapplication of partial differentiation
application of partial differentiation
eteaching
 
Dynamical systems solved ex
Dynamical systems solved exDynamical systems solved ex
Dynamical systems solved ex
Maths Tutoring
 
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
 
Introduction to differentiation
Introduction to differentiationIntroduction to differentiation
Introduction to differentiation
Shaun Wilson
 
Basic mathematics differentiation application
Basic mathematics differentiation applicationBasic mathematics differentiation application
Basic mathematics differentiation application
Muhammad Luthfan
 
Workshop presentations l_bworkshop_reis
Workshop presentations l_bworkshop_reisWorkshop presentations l_bworkshop_reis
Workshop presentations l_bworkshop_reis
Tim 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
Ednexa
 

Similar to Skiena algorithm 2007 lecture02 asymptotic notation (20)

02 CS316_algorithms_Asymptotic_Notations(2).pdf
02 CS316_algorithms_Asymptotic_Notations(2).pdf02 CS316_algorithms_Asymptotic_Notations(2).pdf
02 CS316_algorithms_Asymptotic_Notations(2).pdf
yahiaf3k
 
6_12_13Asymptotic analysiskfnhlkjsbfbkjs.pdf
6_12_13Asymptotic analysiskfnhlkjsbfbkjs.pdf6_12_13Asymptotic analysiskfnhlkjsbfbkjs.pdf
6_12_13Asymptotic analysiskfnhlkjsbfbkjs.pdf
dipanshutiwari1155
 
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
Deepak John
 
Unit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdfUnit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdf
AmayJaiswal4
 
DAA_LECT_2.pdf
DAA_LECT_2.pdfDAA_LECT_2.pdf
DAA_LECT_2.pdf
AryanSaini69
 
asymptotic notations i
asymptotic notations iasymptotic notations i
asymptotic notations i
Ali mahmood
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithms
S.Shayan Daneshvar
 
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
allyn joy calcaben
 
DAA Week 2 slide for design algorithm and analysis.pptx
DAA Week 2 slide for design algorithm and analysis.pptxDAA Week 2 slide for design algorithm and analysis.pptx
DAA Week 2 slide for design algorithm and analysis.pptx
Abdulahad481035
 
Lecture 3(a) Asymptotic-analysis.pdf
Lecture 3(a) Asymptotic-analysis.pdfLecture 3(a) Asymptotic-analysis.pdf
Lecture 3(a) Asymptotic-analysis.pdf
ShaistaRiaz4
 
Asymptotic Notation and Complexity
Asymptotic Notation and ComplexityAsymptotic Notation and Complexity
Asymptotic Notation and Complexity
Rajandeep Gill
 
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
srushtiivp
 
Asymptotic Notation
Asymptotic NotationAsymptotic Notation
Asymptotic Notation
sohelranasweet
 
Asymptotic notation
Asymptotic notationAsymptotic notation
Asymptotic notation
mustafa sarac
 
big_oh
big_ohbig_oh
big_oh
Jonathan (JT) Cho
 
02 asymp
02 asymp02 asymp
02 asymp
aparnabk7
 
lecture 1
lecture 1lecture 1
lecture 1
sajinsc
 
1_Asymptotic_Notation_pptx.pptx
1_Asymptotic_Notation_pptx.pptx1_Asymptotic_Notation_pptx.pptx
1_Asymptotic_Notation_pptx.pptx
pallavidhade2
 
Asymptotics 140510003721-phpapp02
Asymptotics 140510003721-phpapp02Asymptotics 140510003721-phpapp02
Asymptotics 140510003721-phpapp02
mansab MIRZA
 
Skiena algorithm 2007 lecture09 linear sorting
Skiena algorithm 2007 lecture09 linear sortingSkiena algorithm 2007 lecture09 linear sorting
Skiena algorithm 2007 lecture09 linear sorting
zukun
 
02 CS316_algorithms_Asymptotic_Notations(2).pdf
02 CS316_algorithms_Asymptotic_Notations(2).pdf02 CS316_algorithms_Asymptotic_Notations(2).pdf
02 CS316_algorithms_Asymptotic_Notations(2).pdf
yahiaf3k
 
6_12_13Asymptotic analysiskfnhlkjsbfbkjs.pdf
6_12_13Asymptotic analysiskfnhlkjsbfbkjs.pdf6_12_13Asymptotic analysiskfnhlkjsbfbkjs.pdf
6_12_13Asymptotic analysiskfnhlkjsbfbkjs.pdf
dipanshutiwari1155
 
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
Deepak John
 
Unit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdfUnit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdf
AmayJaiswal4
 
asymptotic notations i
asymptotic notations iasymptotic notations i
asymptotic notations i
Ali mahmood
 
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
allyn joy calcaben
 
DAA Week 2 slide for design algorithm and analysis.pptx
DAA Week 2 slide for design algorithm and analysis.pptxDAA Week 2 slide for design algorithm and analysis.pptx
DAA Week 2 slide for design algorithm and analysis.pptx
Abdulahad481035
 
Lecture 3(a) Asymptotic-analysis.pdf
Lecture 3(a) Asymptotic-analysis.pdfLecture 3(a) Asymptotic-analysis.pdf
Lecture 3(a) Asymptotic-analysis.pdf
ShaistaRiaz4
 
Asymptotic Notation and Complexity
Asymptotic Notation and ComplexityAsymptotic Notation and Complexity
Asymptotic Notation and Complexity
Rajandeep Gill
 
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
srushtiivp
 
lecture 1
lecture 1lecture 1
lecture 1
sajinsc
 
1_Asymptotic_Notation_pptx.pptx
1_Asymptotic_Notation_pptx.pptx1_Asymptotic_Notation_pptx.pptx
1_Asymptotic_Notation_pptx.pptx
pallavidhade2
 
Asymptotics 140510003721-phpapp02
Asymptotics 140510003721-phpapp02Asymptotics 140510003721-phpapp02
Asymptotics 140510003721-phpapp02
mansab MIRZA
 
Skiena algorithm 2007 lecture09 linear sorting
Skiena algorithm 2007 lecture09 linear sortingSkiena algorithm 2007 lecture09 linear sorting
Skiena algorithm 2007 lecture09 linear sorting
zukun
 
Ad

More from zukun (20)

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

Recently uploaded (20)

Harmonizing Multi-Agent Intelligence | Open Data Science Conference | Gary Ar...
Harmonizing Multi-Agent Intelligence | Open Data Science Conference | Gary Ar...Harmonizing Multi-Agent Intelligence | Open Data Science Conference | Gary Ar...
Harmonizing Multi-Agent Intelligence | Open Data Science Conference | Gary Ar...
Gary Arora
 
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
Lorenzo Miniero
 
React Native for Business Solutions: Building Scalable Apps for Success
React Native for Business Solutions: Building Scalable Apps for SuccessReact Native for Business Solutions: Building Scalable Apps for Success
React Native for Business Solutions: Building Scalable Apps for Success
Amelia Swank
 
AI-proof your career by Olivier Vroom and David WIlliamson
AI-proof your career by Olivier Vroom and David WIlliamsonAI-proof your career by Olivier Vroom and David WIlliamson
AI-proof your career by Olivier Vroom and David WIlliamson
UXPA Boston
 
論文紹介:"InfLoRA: Interference-Free Low-Rank Adaptation for Continual Learning" ...
論文紹介:"InfLoRA: Interference-Free Low-Rank Adaptation for Continual Learning" ...論文紹介:"InfLoRA: Interference-Free Low-Rank Adaptation for Continual Learning" ...
論文紹介:"InfLoRA: Interference-Free Low-Rank Adaptation for Continual Learning" ...
Toru Tamaki
 
Refactoring meta-rauc-community: Cleaner Code, Better Maintenance, More Machines
Refactoring meta-rauc-community: Cleaner Code, Better Maintenance, More MachinesRefactoring meta-rauc-community: Cleaner Code, Better Maintenance, More Machines
Refactoring meta-rauc-community: Cleaner Code, Better Maintenance, More Machines
Leon Anavi
 
Secondary Storage for a microcontroller system
Secondary Storage for a microcontroller systemSecondary Storage for a microcontroller system
Secondary Storage for a microcontroller system
fizarcse
 
DNF 2.0 Implementations Challenges in Nepal
DNF 2.0 Implementations Challenges in NepalDNF 2.0 Implementations Challenges in Nepal
DNF 2.0 Implementations Challenges in Nepal
ICT Frame Magazine Pvt. Ltd.
 
Building Connected Agents: An Overview of Google's ADK and A2A Protocol
Building Connected Agents:  An Overview of Google's ADK and A2A ProtocolBuilding Connected Agents:  An Overview of Google's ADK and A2A Protocol
Building Connected Agents: An Overview of Google's ADK and A2A Protocol
Suresh Peiris
 
Cybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and MitigationCybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and Mitigation
VICTOR MAESTRE RAMIREZ
 
ICDCC 2025: Securing Agentic AI - Eryk Budi Pratama.pdf
ICDCC 2025: Securing Agentic AI - Eryk Budi Pratama.pdfICDCC 2025: Securing Agentic AI - Eryk Budi Pratama.pdf
ICDCC 2025: Securing Agentic AI - Eryk Budi Pratama.pdf
Eryk Budi Pratama
 
Dark Dynamism: drones, dark factories and deurbanization
Dark Dynamism: drones, dark factories and deurbanizationDark Dynamism: drones, dark factories and deurbanization
Dark Dynamism: drones, dark factories and deurbanization
Jakub Šimek
 
accessibility Considerations during Design by Rick Blair, Schneider Electric
accessibility Considerations during Design by Rick Blair, Schneider Electricaccessibility Considerations during Design by Rick Blair, Schneider Electric
accessibility Considerations during Design by Rick Blair, Schneider Electric
UXPA Boston
 
Slack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teamsSlack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teams
Nacho Cougil
 
Agentic Automation - Delhi UiPath Community Meetup
Agentic Automation - Delhi UiPath Community MeetupAgentic Automation - Delhi UiPath Community Meetup
Agentic Automation - Delhi UiPath Community Meetup
Manoj Batra (1600 + Connections)
 
Google DeepMind’s New AI Coding Agent AlphaEvolve.pdf
Google DeepMind’s New AI Coding Agent AlphaEvolve.pdfGoogle DeepMind’s New AI Coding Agent AlphaEvolve.pdf
Google DeepMind’s New AI Coding Agent AlphaEvolve.pdf
derrickjswork
 
May Patch Tuesday
May Patch TuesdayMay Patch Tuesday
May Patch Tuesday
Ivanti
 
Kit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdf
Kit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdfKit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdf
Kit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdf
Wonjun Hwang
 
DevOpsDays SLC - Platform Engineers are Product Managers.pptx
DevOpsDays SLC - Platform Engineers are Product Managers.pptxDevOpsDays SLC - Platform Engineers are Product Managers.pptx
DevOpsDays SLC - Platform Engineers are Product Managers.pptx
Justin Reock
 
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Safe Software
 
Harmonizing Multi-Agent Intelligence | Open Data Science Conference | Gary Ar...
Harmonizing Multi-Agent Intelligence | Open Data Science Conference | Gary Ar...Harmonizing Multi-Agent Intelligence | Open Data Science Conference | Gary Ar...
Harmonizing Multi-Agent Intelligence | Open Data Science Conference | Gary Ar...
Gary Arora
 
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
Lorenzo Miniero
 
React Native for Business Solutions: Building Scalable Apps for Success
React Native for Business Solutions: Building Scalable Apps for SuccessReact Native for Business Solutions: Building Scalable Apps for Success
React Native for Business Solutions: Building Scalable Apps for Success
Amelia Swank
 
AI-proof your career by Olivier Vroom and David WIlliamson
AI-proof your career by Olivier Vroom and David WIlliamsonAI-proof your career by Olivier Vroom and David WIlliamson
AI-proof your career by Olivier Vroom and David WIlliamson
UXPA Boston
 
論文紹介:"InfLoRA: Interference-Free Low-Rank Adaptation for Continual Learning" ...
論文紹介:"InfLoRA: Interference-Free Low-Rank Adaptation for Continual Learning" ...論文紹介:"InfLoRA: Interference-Free Low-Rank Adaptation for Continual Learning" ...
論文紹介:"InfLoRA: Interference-Free Low-Rank Adaptation for Continual Learning" ...
Toru Tamaki
 
Refactoring meta-rauc-community: Cleaner Code, Better Maintenance, More Machines
Refactoring meta-rauc-community: Cleaner Code, Better Maintenance, More MachinesRefactoring meta-rauc-community: Cleaner Code, Better Maintenance, More Machines
Refactoring meta-rauc-community: Cleaner Code, Better Maintenance, More Machines
Leon Anavi
 
Secondary Storage for a microcontroller system
Secondary Storage for a microcontroller systemSecondary Storage for a microcontroller system
Secondary Storage for a microcontroller system
fizarcse
 
Building Connected Agents: An Overview of Google's ADK and A2A Protocol
Building Connected Agents:  An Overview of Google's ADK and A2A ProtocolBuilding Connected Agents:  An Overview of Google's ADK and A2A Protocol
Building Connected Agents: An Overview of Google's ADK and A2A Protocol
Suresh Peiris
 
Cybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and MitigationCybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and Mitigation
VICTOR MAESTRE RAMIREZ
 
ICDCC 2025: Securing Agentic AI - Eryk Budi Pratama.pdf
ICDCC 2025: Securing Agentic AI - Eryk Budi Pratama.pdfICDCC 2025: Securing Agentic AI - Eryk Budi Pratama.pdf
ICDCC 2025: Securing Agentic AI - Eryk Budi Pratama.pdf
Eryk Budi Pratama
 
Dark Dynamism: drones, dark factories and deurbanization
Dark Dynamism: drones, dark factories and deurbanizationDark Dynamism: drones, dark factories and deurbanization
Dark Dynamism: drones, dark factories and deurbanization
Jakub Šimek
 
accessibility Considerations during Design by Rick Blair, Schneider Electric
accessibility Considerations during Design by Rick Blair, Schneider Electricaccessibility Considerations during Design by Rick Blair, Schneider Electric
accessibility Considerations during Design by Rick Blair, Schneider Electric
UXPA Boston
 
Slack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teamsSlack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teams
Nacho Cougil
 
Google DeepMind’s New AI Coding Agent AlphaEvolve.pdf
Google DeepMind’s New AI Coding Agent AlphaEvolve.pdfGoogle DeepMind’s New AI Coding Agent AlphaEvolve.pdf
Google DeepMind’s New AI Coding Agent AlphaEvolve.pdf
derrickjswork
 
May Patch Tuesday
May Patch TuesdayMay Patch Tuesday
May Patch Tuesday
Ivanti
 
Kit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdf
Kit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdfKit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdf
Kit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdf
Wonjun Hwang
 
DevOpsDays SLC - Platform Engineers are Product Managers.pptx
DevOpsDays SLC - Platform Engineers are Product Managers.pptxDevOpsDays SLC - Platform Engineers are Product Managers.pptx
DevOpsDays SLC - Platform Engineers are Product Managers.pptx
Justin Reock
 
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Safe Software
 

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