SlideShare a Scribd company logo
1 of 31
Download to read offline
Lecture 4 : Asymptotic Notations
Jayavignesh T
Asst Professor
SENSE
How to calculate running time then?
for (i=0; i < n ; i ++) // 1 ; n+1 ; n times
{
for (j=0; j < n ; j ++) // n ; n(n+1) ; n(n)
{
c[i][j] = a[i][j] + b[i][j];
}
}
3n2+4n+ 2 = O(n2)
Analysis – Insertion Sort
Insertion Sort – Tracing Input
Analysis – Insertion Sort
• Assume that the i th line takes time ci , which is a constant.
(Since the third line is a comment, it takes no time.)
• For j = 2, 3, . . . , n, let tj be the number of times that the
while loop test is executed for that value of j .
• Note that when a for or while loop exits in the usual way -
due to the test in the loop header - the test is executed
one time more than the loop body.
Analysis – Insertion Sort – Running time
Best case Analysis
Worst case Analysis
Average Case
Importance of Constants during Algorithmic
Analysis
• Problem Size gets sufficiently large, lower order
terms and constants do not matter and are dropped
• Two Algorithms may have same Big-Oh Time
Complexity even if one is faster than other
• Algorithm 1 : N2 time
• Algorithm 2 : 10N2 + N
– Both these algorithms time is O(N2) but Alg 1 faster.
• Constants do not matter when algorithm scales?
Linear Time vs Quadratic Time
2 Algorithms have different Big-Oh time complexity, constants & lower order terms
matter only when problem size is small.
What is Asymptote?
• Provides a behavior in respect of other function for
varying value of input size.
• An asymptote is a line or curve that a graph
approaches but does not intersect.
• An asymptote of a curve is a line in such a way that
distance between curve and line approaches zero
towards large values or infinity.
Asymptotic Notations
• Asymptotic notations (as n tends to ∞)
– used to express the running time of an algorithm in terms
of function, whose domain is the set of natural numbers
N={1,2,3,…..}.
• Asymptotic notation gives the rate of growth,
– i.e. performance of the run time for “sufficiently large
input sizes” (as n tends to infinity)
• Easier to predict bounds for the algorithm than to
predict an exact speed.
– Short-hand way to represent fastest possible, slowest
possible running times of algorithm using high and low
bounds on speed.
Asymptotic Notations contd..
• O (Big – Oh)
– This notation is used to express Upper bound (maximum
steps) required to solve a problem
– Worst case growth of algorithm
• Ω (Big – Omega)
– To express Lower bound i.e. minimum (at least) steps
required to solve a problem
– Best case growth of algorithm
• Θ (Big - Theta)
– To express both Upper & Lower bound, also called tight
bound
– (i.e. Average case) on a function
Asymptotic Order of Growth
• A way of comparing functions that ignores constant
factors and small input sizes
• O(g(n)): class of functions f(n) that grow no faster
than g(n)
• Θ(g(n)): class of functions f(n) that grow at same
rate as g(n)
• Ω(g(n)): class of functions f(n) that grow at least as
fast as g(n)
Why are asymptotic notations important?
• They give a simple characterization of an algorithm’s
efficiency.
• They allow the comparison of the performances of
various algorithms.
• For large values of components/inputs, the
multiplicative constants and lower order terms of an
exact running time are dominated by the effects of
the input size (the number of components).
Asymptotic – Summary
• A way to describe behavior of functions in the limit.
• Describe growth of functions.
• Focus on what’s important by abstracting away low order
terms and constant factors.
• Indicate running times of algorithms.
• A way to compare “sizes” of functions.
• Examples: – n steps vs. n+5 steps, – n steps vs. n2 steps
• Running time of an algorithm as a function of input size n for
large n.
• Expressed using only the highest-order term in the expression
for the exact running time.
Asymptotic Notations..
Asymptotic Notations..
Problems – Big Oh, Big Omega, Big Thetha
• First two functions are linear and hence have a lower order
of growth than g(n) = n2, while the last one is quadratic and
hence has the same order of growth as n2
• Functions n3 and 0.00001n3 are both cubic and hence have a
higher order of growth than n2, and so has the fourth-
degree polynomial n4 + n + 1
Problems – Big Oh, Big Omega, Big Thetha
• Ω(g(n)), stands for the set of all functions with a higher or
same order of growth as g(n) (to within a constant multiple,
as n goes to infinity).
• Θ(g(n)) is the set of all functions that have the same order of
growth as g(n) (to within a constant multiple, as n goes to
infinity). Every quadratic function an2 + bn + c with a > 0 is in
Θ(n2).
Exercise

More Related Content

What's hot

What's hot (20)

asymptotic notation
asymptotic notationasymptotic notation
asymptotic notation
 
Daa notes 1
Daa notes 1Daa notes 1
Daa notes 1
 
Lecture 5: Asymptotic analysis of algorithms
Lecture 5: Asymptotic analysis of algorithmsLecture 5: Asymptotic analysis of algorithms
Lecture 5: Asymptotic analysis of algorithms
 
Introduction to design and analysis of algorithm
Introduction to design and analysis of algorithmIntroduction to design and analysis of algorithm
Introduction to design and analysis of algorithm
 
Design and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptxDesign and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptx
 
Algorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms IAlgorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms I
 
Asymptotic Notation
Asymptotic NotationAsymptotic Notation
Asymptotic Notation
 
Complexity analysis in Algorithms
Complexity analysis in AlgorithmsComplexity analysis in Algorithms
Complexity analysis in Algorithms
 
Time complexity
Time complexityTime complexity
Time complexity
 
Analysis of algorithm
Analysis of algorithmAnalysis of algorithm
Analysis of algorithm
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
 
Algorithm And analysis Lecture 03& 04-time complexity.
 Algorithm And analysis Lecture 03& 04-time complexity. Algorithm And analysis Lecture 03& 04-time complexity.
Algorithm And analysis Lecture 03& 04-time complexity.
 
Measuring algorithm performance
Measuring algorithm performanceMeasuring algorithm performance
Measuring algorithm performance
 
Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of Algorithms
 
Divide and Conquer - Part 1
Divide and Conquer - Part 1Divide and Conquer - Part 1
Divide and Conquer - Part 1
 
Unit 1 chapter 1 Design and Analysis of Algorithms
Unit 1   chapter 1 Design and Analysis of AlgorithmsUnit 1   chapter 1 Design and Analysis of Algorithms
Unit 1 chapter 1 Design and Analysis of Algorithms
 
Specification and complexity - algorithm
Specification and complexity - algorithmSpecification and complexity - algorithm
Specification and complexity - algorithm
 
Asymptotic notations(Big O, Omega, Theta )
Asymptotic notations(Big O, Omega, Theta )Asymptotic notations(Big O, Omega, Theta )
Asymptotic notations(Big O, Omega, Theta )
 
Primality
PrimalityPrimality
Primality
 

Viewers also liked (10)

Asymptotic notation
Asymptotic notationAsymptotic notation
Asymptotic notation
 
02 order of growth
02 order of growth02 order of growth
02 order of growth
 
asymptotic analysis and insertion sort analysis
asymptotic analysis and insertion sort analysisasymptotic analysis and insertion sort analysis
asymptotic analysis and insertion sort analysis
 
Asymptotic Growth of Functions
Asymptotic Growth of FunctionsAsymptotic Growth of Functions
Asymptotic Growth of Functions
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
Asymptotic Notation and Data Structures
Asymptotic Notation and Data StructuresAsymptotic Notation and Data Structures
Asymptotic Notation and Data Structures
 
Introduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic NotationIntroduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic Notation
 
Distributed Database Management System
Distributed Database Management SystemDistributed Database Management System
Distributed Database Management System
 
Lec1
Lec1Lec1
Lec1
 
Distributed Database System
Distributed Database SystemDistributed Database System
Distributed Database System
 

Similar to Lecture 4 asymptotic notations

Data Structure & Algorithms - Mathematical
Data Structure & Algorithms - MathematicalData Structure & Algorithms - Mathematical
Data Structure & Algorithms - Mathematical
babuk110
 
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...
AntareepMajumder
 
Analysis of algorithn class 2
Analysis of algorithn class 2Analysis of algorithn class 2
Analysis of algorithn class 2
Kumar
 

Similar to Lecture 4 asymptotic notations (20)

Analysis and Algorithms: basic Introduction
Analysis and Algorithms: basic IntroductionAnalysis and Algorithms: basic Introduction
Analysis and Algorithms: basic Introduction
 
Lec 2 algorithms efficiency complexity
Lec 2 algorithms efficiency  complexityLec 2 algorithms efficiency  complexity
Lec 2 algorithms efficiency complexity
 
DSA
DSADSA
DSA
 
Searching Algorithms
Searching AlgorithmsSearching Algorithms
Searching Algorithms
 
Unit ii algorithm
Unit   ii algorithmUnit   ii algorithm
Unit ii algorithm
 
Algorithms & Complexity Calculation
Algorithms & Complexity CalculationAlgorithms & Complexity Calculation
Algorithms & Complexity Calculation
 
Data Structures- Part2 analysis tools
Data Structures- Part2 analysis toolsData Structures- Part2 analysis tools
Data Structures- Part2 analysis tools
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithms
 
2. Introduction to Algorithm.pptx
2. Introduction to Algorithm.pptx2. Introduction to Algorithm.pptx
2. Introduction to Algorithm.pptx
 
Algorithms
Algorithms Algorithms
Algorithms
 
Data Structure & Algorithms - Mathematical
Data Structure & Algorithms - MathematicalData Structure & Algorithms - Mathematical
Data Structure & Algorithms - Mathematical
 
DSA Complexity.pptx What is Complexity Analysis? What is the need for Compl...
DSA Complexity.pptx   What is Complexity Analysis? What is the need for Compl...DSA Complexity.pptx   What is Complexity Analysis? What is the need for Compl...
DSA Complexity.pptx What is Complexity Analysis? What is the need for Compl...
 
Algorithm.pptx
Algorithm.pptxAlgorithm.pptx
Algorithm.pptx
 
Algorithm.pptx
Algorithm.pptxAlgorithm.pptx
Algorithm.pptx
 
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...
 
CS8451 - Design and Analysis of Algorithms
CS8451 - Design and Analysis of AlgorithmsCS8451 - Design and Analysis of Algorithms
CS8451 - Design and Analysis of Algorithms
 
Big O Notation
Big O NotationBig O Notation
Big O Notation
 
Analysis of algorithn class 2
Analysis of algorithn class 2Analysis of algorithn class 2
Analysis of algorithn class 2
 
Lecture 3 insertion sort and complexity analysis
Lecture 3   insertion sort and complexity analysisLecture 3   insertion sort and complexity analysis
Lecture 3 insertion sort and complexity analysis
 
Algorithm
AlgorithmAlgorithm
Algorithm
 

Recently uploaded

DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
MayuraD1
 
Digital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptxDigital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptx
pritamlangde
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
AldoGarca30
 

Recently uploaded (20)

DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
Digital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptxDigital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptx
 
Basic Electronics for diploma students as per technical education Kerala Syll...
Basic Electronics for diploma students as per technical education Kerala Syll...Basic Electronics for diploma students as per technical education Kerala Syll...
Basic Electronics for diploma students as per technical education Kerala Syll...
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
Electromagnetic relays used for power system .pptx
Electromagnetic relays used for power system .pptxElectromagnetic relays used for power system .pptx
Electromagnetic relays used for power system .pptx
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
 
Computer Graphics Introduction To Curves
Computer Graphics Introduction To CurvesComputer Graphics Introduction To Curves
Computer Graphics Introduction To Curves
 
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 

Lecture 4 asymptotic notations

  • 1. Lecture 4 : Asymptotic Notations Jayavignesh T Asst Professor SENSE
  • 2. How to calculate running time then? for (i=0; i < n ; i ++) // 1 ; n+1 ; n times { for (j=0; j < n ; j ++) // n ; n(n+1) ; n(n) { c[i][j] = a[i][j] + b[i][j]; } } 3n2+4n+ 2 = O(n2)
  • 4. Insertion Sort – Tracing Input
  • 5. Analysis – Insertion Sort • Assume that the i th line takes time ci , which is a constant. (Since the third line is a comment, it takes no time.) • For j = 2, 3, . . . , n, let tj be the number of times that the while loop test is executed for that value of j . • Note that when a for or while loop exits in the usual way - due to the test in the loop header - the test is executed one time more than the loop body.
  • 6. Analysis – Insertion Sort – Running time
  • 8.
  • 9.
  • 12.
  • 13. Importance of Constants during Algorithmic Analysis • Problem Size gets sufficiently large, lower order terms and constants do not matter and are dropped • Two Algorithms may have same Big-Oh Time Complexity even if one is faster than other • Algorithm 1 : N2 time • Algorithm 2 : 10N2 + N – Both these algorithms time is O(N2) but Alg 1 faster. • Constants do not matter when algorithm scales?
  • 14. Linear Time vs Quadratic Time 2 Algorithms have different Big-Oh time complexity, constants & lower order terms matter only when problem size is small.
  • 15. What is Asymptote? • Provides a behavior in respect of other function for varying value of input size. • An asymptote is a line or curve that a graph approaches but does not intersect. • An asymptote of a curve is a line in such a way that distance between curve and line approaches zero towards large values or infinity.
  • 16.
  • 17. Asymptotic Notations • Asymptotic notations (as n tends to ∞) – used to express the running time of an algorithm in terms of function, whose domain is the set of natural numbers N={1,2,3,…..}. • Asymptotic notation gives the rate of growth, – i.e. performance of the run time for “sufficiently large input sizes” (as n tends to infinity) • Easier to predict bounds for the algorithm than to predict an exact speed. – Short-hand way to represent fastest possible, slowest possible running times of algorithm using high and low bounds on speed.
  • 18. Asymptotic Notations contd.. • O (Big – Oh) – This notation is used to express Upper bound (maximum steps) required to solve a problem – Worst case growth of algorithm • Ω (Big – Omega) – To express Lower bound i.e. minimum (at least) steps required to solve a problem – Best case growth of algorithm • Θ (Big - Theta) – To express both Upper & Lower bound, also called tight bound – (i.e. Average case) on a function
  • 19. Asymptotic Order of Growth • A way of comparing functions that ignores constant factors and small input sizes • O(g(n)): class of functions f(n) that grow no faster than g(n) • Θ(g(n)): class of functions f(n) that grow at same rate as g(n) • Ω(g(n)): class of functions f(n) that grow at least as fast as g(n)
  • 20. Why are asymptotic notations important? • They give a simple characterization of an algorithm’s efficiency. • They allow the comparison of the performances of various algorithms. • For large values of components/inputs, the multiplicative constants and lower order terms of an exact running time are dominated by the effects of the input size (the number of components).
  • 21. Asymptotic – Summary • A way to describe behavior of functions in the limit. • Describe growth of functions. • Focus on what’s important by abstracting away low order terms and constant factors. • Indicate running times of algorithms. • A way to compare “sizes” of functions. • Examples: – n steps vs. n+5 steps, – n steps vs. n2 steps • Running time of an algorithm as a function of input size n for large n. • Expressed using only the highest-order term in the expression for the exact running time.
  • 22.
  • 23.
  • 24.
  • 25.
  • 28.
  • 29. Problems – Big Oh, Big Omega, Big Thetha • First two functions are linear and hence have a lower order of growth than g(n) = n2, while the last one is quadratic and hence has the same order of growth as n2 • Functions n3 and 0.00001n3 are both cubic and hence have a higher order of growth than n2, and so has the fourth- degree polynomial n4 + n + 1
  • 30. Problems – Big Oh, Big Omega, Big Thetha • Ω(g(n)), stands for the set of all functions with a higher or same order of growth as g(n) (to within a constant multiple, as n goes to infinity). • Θ(g(n)) is the set of all functions that have the same order of growth as g(n) (to within a constant multiple, as n goes to infinity). Every quadratic function an2 + bn + c with a > 0 is in Θ(n2).