6
Most read
9
Most read
10
Most read
Algorithm Analysis
5/25/2021
MeghaV
ResearchScholar
Dept. of IT
Kannur University
How to compare Algorithms
• The running time of a given algorithm can be expressed as a function of input size n
• Comparison of algorithms can be done in terms of f(n)
• These kinds of comparisons are independent of machine time.
Rate of Growth
The rate at which the running time increases as a function of input is called rate of growth.
5/25/2021
Time Name Example
1 Constant Linear search(best case)
log n Logarithmic Binary search
n Linear Linear search
n log n linear logarithm Merge sort complexity
n2 Quadratic Bubble sort
n3 Cubic Matrix Multiplication
2n Exponential Travelling salesman problem
5/25/2021
Algorithm analysis:
Importance of algorithm analysis
• Analysis of Algorithm or performance analysis refers to the task of determining how much computing time and storage
an algorithm requires.
• It involves 2 phases
1.Priori analysis
2.Posterior analysis
• Priori analysis: this is a theoretical analysis. Efficiency of an algorithm is measured by assuming that factors like
processor speed, are constant and have no effect on the implementation.
• Posterior analysis: Statistics about the algorithm in terms of space and time is obtained during execution
• This is a challenging area which some times requires great mathematical skill
5/25/2021
Analysis of algorithms
Efficiency of algorithm depends on
1.Space efficiency
2.Time efficiency
Space Efficiency: It is the amount of memory required to run the program
completely and efficiently.
Space complexity depends on:
- Program space: space required to store the compiled program.
- Data space: Space required to store the constants variables.
- Stack space: Space required to store return address , parameters passed
etc.
5/25/2021
Time complexity
• The time T(P) taken by a program is the sum of the compile time and runtime.
• We may assume that a compiled program will run several times without
recompilation
• Consequently we consider only the run time of the program. This runtime is
denoted as tp. .
5/25/2021
Types of Analysis
1. Best case
2. Worst case
3. Average case
Best case: Defines the input for which the algorithm takes lowest time
Input is one for which the algorithm runs fastest
Worst case: Defines the input for which the algorithm takes largest time
Input is one for which the algorithm runs slower
Average case: Provides a prediction about the running time of the algorithm
Assumes that the input is random
5/25/2021
Contd..
Time efficiency: Measure of how fast algorithm executes
Time complexity depends on:
• Speed of computer
• Choice of programming language
• Compiler used
• Choice of algorithm
• Number of inputs/outputs
• Operations count and Steps count
Time efficiency mainly depends on size of input n, hence expressed in terms of n.
5/25/2021
Order of growth
The efficiency of algorithm can be analyzed by considering highest order of n.
5/25/2021
Asymptotic notations
• Accurate measurement of time complexity is possible with asymptotic notation.
• Asymptotic complexity gives an idea of how rapidly the space requirement or
time requirement grow as problem size increase.
• Asymptotic complexity is a measure of algorithm not problem.
• The complexity of an algorithm is a function relating the input length to the
number of steps (time complexity) or storage location (space complexity).
For example, the running time is expressed as a function of the input size ‘n’ as
follows.
f(n)=n4+100n2+10n+50 (running time)
5/25/2021
Big O notation
• Big oh notation is denoted by ‘O’. It is used to describe the efficiency of an algorithm.
• It is used to represent the upper bound of an algorithm running time. Using Big O notation, we
can give largest amount of time taken by the algorithm to complete.
Definition: Let f(n) and g(n) be the two non-negative functions. We say that f(n) is said to be
O(g(n)) if and only if there exists positive constants ‘c’ and ‘n0’ such that,
f(n)≤ c*g(n) for all non-negative values of n, where n≥n0
Here, g(n) is the upper bound for f(n).
5/25/2021
Big O notation (contd.)
Ex: Let f(n)= 2n4+5n2+2n+3
≤ 2n4+5n4+2n4+3n4
≤ (2+5+2+3)n4
≤ 12n4
f(n) =12n4
This implies g(n)=n4, n≥1
c=12 and n0=1
f(n)=O(n4)
The above definition states that the function
‘f’ if almost ‘c’ times the function ‘g’ when ‘n’ is greater than or equal to n0.
This notation provides an upper bound for the function ‘f’ i.e. the function g(n) is an upper
bound on the value of f(n) for all n, where n ≥n0
5/25/2021
Big-Omega notation
• Big omega notation is denoted by ‘Ω’. It is used to represent the lower bound of an algorithm
running time.
• Using Big omega notation we can give shortest amount of time taken by the algorithm to
complete.
Definition:
The function f(n)=Ω(g(n)) , if and only if there exist positive constants ‘c’ and n0, such that
f(n)≥c*g(n) for all n, n ≥ n0
5/25/2021
Big-Omega notation (Contd.)
Example:
Let f(n) = 2n4+5n2+2n+3
≥ 2n4 (for example as n ∞,
lower order terms are insignificant)
f(n) ≥ 2n4, n ≥1
g(n)=n4, c=2 and n0=1
f(n)= Ω(n4)
5/25/2021
Big Theta notation
5/25/2021
•The big theta notation is denoted by ‘θ’
•It is in between the upper bound and lower bound of an algorithms running time.
Definition:
Let f(n) and g(n) be two non-negative functions. We say that f(n) is said to be θ(g(n)) if and only
if there exists positive constants ‘c1’ and ’c2’, such that,
c1g(n) ≤ f(n) ≤ c2g(n) for all non-negative values n, where n ≥ n0
• The above definition states that the function f(n) lies between ‘c1’ times the function g(n) and
‘c2’ times the function g(n).
• In other words theta notation says that f(n) is both O(g(n)) and Ω(g(n)) for all n, where n≥n0
Big Theta notation (contd.)
Example:
f(n) =2n4+5n2+2n+3
2n4≤ 2n4+5n2+2n+3 ≤ 12n4
2n4 ≤f(n) ≤12n4 , n ≥1
g(n) =n4
c1=2, c2=12 and n0=1
f(n)=n4
5/25/2021
Little Oh (o) notation
• It is a method of expressing the upper bound on the growth rate of an algorithm’s running time
which may or may not be asymptotically tight,
• Also called loose upper bound
Definition
Given functions f(n) and g(n), we say that f(n) is o(g(n)) if there are positive constants c and n0
Such that f(n) < cg(n) for all n, n≥ n0
• The main difference between Big O and Little o lies in their definition
• In Big O f(n) = O(g(n)) and the bound is 0 ≤ f(n) ≤ cg(n) so it is true only for some positive value
of c
• In little o, it is true for all constant c>0 because f(n)= o(g(n)) and the bound f(n)<cg(n).
5/25/2021
Little omega (ω) notation
• It is a method of expressing the lower bound on the growth rate of an algorithm’s running time which
may or may not be asymptotically tight.
• Little omega is also called a loose lower bound.
Definition:
Given functions f(n) and g(n), we say that f(n) is little omega of (g(n)) if there are positive
constants c and n0
Such that f(n) > cg(n) for all n, n≥ n0
• The main difference between Big Omega and Little omega lies in their definition
• In Big Omega f(n) = Ω(g(n)) and the bound is 0 ≤ cg(n)<f(n) so it is true only for some positive value of
c
• In little o, it is true for all constant c>0
5/25/2021
Analysing algorithm control structures
We start by considering how to count operations in for-loops.
• First of all, we should know the number of iterations of the loop; say it is x
• Then the loop condition is executed x + 1 times.
• Each of the statements in the loop body is executed x times
• The loop-index update statement is executed x times
5/25/2021
Analysing algorithm control structures contd.
5/25/2021
Loops: Complexity is determined by the number of iterations in the loop times the complexity of the body
of the loop
EXAMPLE
Analysing algorithm control structures contd.
Nested independent loops: Complexity of inner loop * complexity of outer loop
5/25/2021
Example
Nested dependent loops: Examples:
Number of repetitions of the inner
loop is: 1 + 2 + 3 + . . . + n = n(n+2)/2
Hence the segment is O(n2)
Analysing algorithm control structures contd.
If Statement: O(max(O(condition1), O(condition2), . . , O(branch1), O(branch2), . . ., O(branchN))
5/25/2021
Analysing algorithm control structures contd.
Switch: Take the complexity of the most expensive case including the default case
5/25/2021

More Related Content

PPT
Asymptotic notation
PPTX
Local beam search example
PPTX
Scheme Programming Language
PPT
Predicate logic_2(Artificial Intelligence)
PPTX
Analysis of algorithm
PPT
UNIT-1-PPTS-DAA.ppt
PPT
First order logic in knowledge representation
PDF
Heapsort quick sort
Asymptotic notation
Local beam search example
Scheme Programming Language
Predicate logic_2(Artificial Intelligence)
Analysis of algorithm
UNIT-1-PPTS-DAA.ppt
First order logic in knowledge representation
Heapsort quick sort

What's hot (20)

PPTX
Genetic programming
PDF
PPT
Algoritmos Voraces (Greedy)
PPTX
Algorithm Complexity and Main Concepts
PDF
Time and Space Complexity
PDF
Master theorem
PDF
The Design and Analysis of Algorithms.pdf
PPT
how to calclute time complexity of algortihm
PDF
Network programming Using Python
PDF
First Order Logic resolution
PDF
Daa notes 1
PPT
ADVANCED ALGORITHMS-UNIT-3-Final.ppt
PPT
Asymptotic notations
PPT
Asymptoptic notations
PPTX
Traveling Salesman Problem
PPT
Game Playing in Artificial Intelligence
PPT
String matching algorithm
PPTX
Semantics analysis
PPTX
Presentación de matlab electromagnetismo ...
PPTX
The Traveling Salesman problem ppt.pptx
Genetic programming
Algoritmos Voraces (Greedy)
Algorithm Complexity and Main Concepts
Time and Space Complexity
Master theorem
The Design and Analysis of Algorithms.pdf
how to calclute time complexity of algortihm
Network programming Using Python
First Order Logic resolution
Daa notes 1
ADVANCED ALGORITHMS-UNIT-3-Final.ppt
Asymptotic notations
Asymptoptic notations
Traveling Salesman Problem
Game Playing in Artificial Intelligence
String matching algorithm
Semantics analysis
Presentación de matlab electromagnetismo ...
The Traveling Salesman problem ppt.pptx
Ad

Similar to Algorithm Analysis (20)

PDF
Data Structure & Algorithms - Mathematical
PDF
ESINF03-AlgAnalis.pdfESINF03-AlgAnalis.pdf
PPTX
Asymptotic Notations
PPTX
Asymptotic Analysis in Data Structure using C
PPTX
Unit ii algorithm
PPTX
Algorithm for the DAA agscsnak javausmagagah
PPT
CS8451 - Design and Analysis of Algorithms
PPTX
Daa unit 6_efficiency of algorithms
PPTX
Asymptotic Notations.pptx
PPTX
Asymptotics 140510003721-phpapp02
PPTX
Design and Analysis of Algorithms Lecture Notes
PPT
Analysis Of Algorithms I
PDF
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
PDF
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
PDF
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpall...
PDF
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
PPT
Introduction to design and analysis of algorithm
PPTX
Asymptotic Notations
PPTX
BCSE202Lkkljkljkbbbnbnghghjghghghghghghghgh
PPTX
ASYMTOTIC NOTATIONS BIG O OEMGA THETE NOTATION.pptx
Data Structure & Algorithms - Mathematical
ESINF03-AlgAnalis.pdfESINF03-AlgAnalis.pdf
Asymptotic Notations
Asymptotic Analysis in Data Structure using C
Unit ii algorithm
Algorithm for the DAA agscsnak javausmagagah
CS8451 - Design and Analysis of Algorithms
Daa unit 6_efficiency of algorithms
Asymptotic Notations.pptx
Asymptotics 140510003721-phpapp02
Design and Analysis of Algorithms Lecture Notes
Analysis Of Algorithms I
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpall...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
Introduction to design and analysis of algorithm
Asymptotic Notations
BCSE202Lkkljkljkbbbnbnghghjghghghghghghghgh
ASYMTOTIC NOTATIONS BIG O OEMGA THETE NOTATION.pptx
Ad

More from Megha V (20)

PPTX
Soft Computing Techniques_Part 1.pptx
PPTX
JavaScript- Functions and arrays.pptx
PPTX
Introduction to JavaScript
PPTX
Python Exception Handling
PPTX
Python- Regular expression
PPTX
File handling in Python
PPTX
Python programming -Tuple and Set Data type
PPTX
Python programming –part 7
PPTX
Python programming Part -6
PPTX
Python programming: Anonymous functions, String operations
PPTX
Python programming- Part IV(Functions)
PPTX
Python programming –part 3
PPTX
Parts of python programming language
PPTX
Python programming
PPTX
Strassen's matrix multiplication
PPTX
Solving recurrences
PPTX
Algorithm analysis and design
PPTX
Genetic algorithm
PPTX
UGC NET Paper 1 ICT Memory and data
PPTX
Seminar presentation on OpenGL
Soft Computing Techniques_Part 1.pptx
JavaScript- Functions and arrays.pptx
Introduction to JavaScript
Python Exception Handling
Python- Regular expression
File handling in Python
Python programming -Tuple and Set Data type
Python programming –part 7
Python programming Part -6
Python programming: Anonymous functions, String operations
Python programming- Part IV(Functions)
Python programming –part 3
Parts of python programming language
Python programming
Strassen's matrix multiplication
Solving recurrences
Algorithm analysis and design
Genetic algorithm
UGC NET Paper 1 ICT Memory and data
Seminar presentation on OpenGL

Recently uploaded (20)

PPTX
ESDS_SAP Application Cloud Offerings.pptx
PPTX
Improving Audience Engagement ROI with ERP-Powered Insights
PDF
solman-7.0-ehp1-sp21-incident-management
PPTX
Relevance Tuning with Genetic Algorithms
PDF
Canva Desktop App With Crack Free Download 2025?
PDF
Streamlining Project Management in Microsoft Project, Planner, and Teams with...
PDF
Top 10 Project Management Software for Small Teams in 2025.pdf
PPTX
SAP Business AI_L1 Overview_EXTERNAL.pptx
PDF
Ragic Data Security Overview: Certifications, Compliance, and Network Safegua...
PDF
Module 1 - Introduction to Generative AI.pdf
PDF
Difference Between Website and Web Application.pdf
PDF
OpenTimelineIO Virtual Town Hall - August 2025
PPTX
FLIGHT TICKET API | API INTEGRATION PLATFORM
PDF
10 Mistakes Agile Project Managers Still Make
PPTX
WJQSJXNAZJVCVSAXJHBZKSJXKJKXJSBHJBJEHHJB
PDF
MaterialX Virtual Town Hall - August 2025
PDF
OpenEXR Virtual Town Hall - August 2025
PPTX
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
PPTX
AI Tools Revolutionizing Software Development Workflows
PDF
C language slides for c programming book by ANSI
ESDS_SAP Application Cloud Offerings.pptx
Improving Audience Engagement ROI with ERP-Powered Insights
solman-7.0-ehp1-sp21-incident-management
Relevance Tuning with Genetic Algorithms
Canva Desktop App With Crack Free Download 2025?
Streamlining Project Management in Microsoft Project, Planner, and Teams with...
Top 10 Project Management Software for Small Teams in 2025.pdf
SAP Business AI_L1 Overview_EXTERNAL.pptx
Ragic Data Security Overview: Certifications, Compliance, and Network Safegua...
Module 1 - Introduction to Generative AI.pdf
Difference Between Website and Web Application.pdf
OpenTimelineIO Virtual Town Hall - August 2025
FLIGHT TICKET API | API INTEGRATION PLATFORM
10 Mistakes Agile Project Managers Still Make
WJQSJXNAZJVCVSAXJHBZKSJXKJKXJSBHJBJEHHJB
MaterialX Virtual Town Hall - August 2025
OpenEXR Virtual Town Hall - August 2025
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
AI Tools Revolutionizing Software Development Workflows
C language slides for c programming book by ANSI

Algorithm Analysis

  • 2. How to compare Algorithms • The running time of a given algorithm can be expressed as a function of input size n • Comparison of algorithms can be done in terms of f(n) • These kinds of comparisons are independent of machine time. Rate of Growth The rate at which the running time increases as a function of input is called rate of growth. 5/25/2021
  • 3. Time Name Example 1 Constant Linear search(best case) log n Logarithmic Binary search n Linear Linear search n log n linear logarithm Merge sort complexity n2 Quadratic Bubble sort n3 Cubic Matrix Multiplication 2n Exponential Travelling salesman problem 5/25/2021
  • 4. Algorithm analysis: Importance of algorithm analysis • Analysis of Algorithm or performance analysis refers to the task of determining how much computing time and storage an algorithm requires. • It involves 2 phases 1.Priori analysis 2.Posterior analysis • Priori analysis: this is a theoretical analysis. Efficiency of an algorithm is measured by assuming that factors like processor speed, are constant and have no effect on the implementation. • Posterior analysis: Statistics about the algorithm in terms of space and time is obtained during execution • This is a challenging area which some times requires great mathematical skill 5/25/2021
  • 5. Analysis of algorithms Efficiency of algorithm depends on 1.Space efficiency 2.Time efficiency Space Efficiency: It is the amount of memory required to run the program completely and efficiently. Space complexity depends on: - Program space: space required to store the compiled program. - Data space: Space required to store the constants variables. - Stack space: Space required to store return address , parameters passed etc. 5/25/2021
  • 6. Time complexity • The time T(P) taken by a program is the sum of the compile time and runtime. • We may assume that a compiled program will run several times without recompilation • Consequently we consider only the run time of the program. This runtime is denoted as tp. . 5/25/2021
  • 7. Types of Analysis 1. Best case 2. Worst case 3. Average case Best case: Defines the input for which the algorithm takes lowest time Input is one for which the algorithm runs fastest Worst case: Defines the input for which the algorithm takes largest time Input is one for which the algorithm runs slower Average case: Provides a prediction about the running time of the algorithm Assumes that the input is random 5/25/2021
  • 8. Contd.. Time efficiency: Measure of how fast algorithm executes Time complexity depends on: • Speed of computer • Choice of programming language • Compiler used • Choice of algorithm • Number of inputs/outputs • Operations count and Steps count Time efficiency mainly depends on size of input n, hence expressed in terms of n. 5/25/2021
  • 9. Order of growth The efficiency of algorithm can be analyzed by considering highest order of n. 5/25/2021
  • 10. Asymptotic notations • Accurate measurement of time complexity is possible with asymptotic notation. • Asymptotic complexity gives an idea of how rapidly the space requirement or time requirement grow as problem size increase. • Asymptotic complexity is a measure of algorithm not problem. • The complexity of an algorithm is a function relating the input length to the number of steps (time complexity) or storage location (space complexity). For example, the running time is expressed as a function of the input size ‘n’ as follows. f(n)=n4+100n2+10n+50 (running time) 5/25/2021
  • 11. Big O notation • Big oh notation is denoted by ‘O’. It is used to describe the efficiency of an algorithm. • It is used to represent the upper bound of an algorithm running time. Using Big O notation, we can give largest amount of time taken by the algorithm to complete. Definition: Let f(n) and g(n) be the two non-negative functions. We say that f(n) is said to be O(g(n)) if and only if there exists positive constants ‘c’ and ‘n0’ such that, f(n)≤ c*g(n) for all non-negative values of n, where n≥n0 Here, g(n) is the upper bound for f(n). 5/25/2021
  • 12. Big O notation (contd.) Ex: Let f(n)= 2n4+5n2+2n+3 ≤ 2n4+5n4+2n4+3n4 ≤ (2+5+2+3)n4 ≤ 12n4 f(n) =12n4 This implies g(n)=n4, n≥1 c=12 and n0=1 f(n)=O(n4) The above definition states that the function ‘f’ if almost ‘c’ times the function ‘g’ when ‘n’ is greater than or equal to n0. This notation provides an upper bound for the function ‘f’ i.e. the function g(n) is an upper bound on the value of f(n) for all n, where n ≥n0 5/25/2021
  • 13. Big-Omega notation • Big omega notation is denoted by ‘Ω’. It is used to represent the lower bound of an algorithm running time. • Using Big omega notation we can give shortest amount of time taken by the algorithm to complete. Definition: The function f(n)=Ω(g(n)) , if and only if there exist positive constants ‘c’ and n0, such that f(n)≥c*g(n) for all n, n ≥ n0 5/25/2021
  • 14. Big-Omega notation (Contd.) Example: Let f(n) = 2n4+5n2+2n+3 ≥ 2n4 (for example as n ∞, lower order terms are insignificant) f(n) ≥ 2n4, n ≥1 g(n)=n4, c=2 and n0=1 f(n)= Ω(n4) 5/25/2021
  • 15. Big Theta notation 5/25/2021 •The big theta notation is denoted by ‘θ’ •It is in between the upper bound and lower bound of an algorithms running time. Definition: Let f(n) and g(n) be two non-negative functions. We say that f(n) is said to be θ(g(n)) if and only if there exists positive constants ‘c1’ and ’c2’, such that, c1g(n) ≤ f(n) ≤ c2g(n) for all non-negative values n, where n ≥ n0 • The above definition states that the function f(n) lies between ‘c1’ times the function g(n) and ‘c2’ times the function g(n). • In other words theta notation says that f(n) is both O(g(n)) and Ω(g(n)) for all n, where n≥n0
  • 16. Big Theta notation (contd.) Example: f(n) =2n4+5n2+2n+3 2n4≤ 2n4+5n2+2n+3 ≤ 12n4 2n4 ≤f(n) ≤12n4 , n ≥1 g(n) =n4 c1=2, c2=12 and n0=1 f(n)=n4 5/25/2021
  • 17. Little Oh (o) notation • It is a method of expressing the upper bound on the growth rate of an algorithm’s running time which may or may not be asymptotically tight, • Also called loose upper bound Definition Given functions f(n) and g(n), we say that f(n) is o(g(n)) if there are positive constants c and n0 Such that f(n) < cg(n) for all n, n≥ n0 • The main difference between Big O and Little o lies in their definition • In Big O f(n) = O(g(n)) and the bound is 0 ≤ f(n) ≤ cg(n) so it is true only for some positive value of c • In little o, it is true for all constant c>0 because f(n)= o(g(n)) and the bound f(n)<cg(n). 5/25/2021
  • 18. Little omega (ω) notation • It is a method of expressing the lower bound on the growth rate of an algorithm’s running time which may or may not be asymptotically tight. • Little omega is also called a loose lower bound. Definition: Given functions f(n) and g(n), we say that f(n) is little omega of (g(n)) if there are positive constants c and n0 Such that f(n) > cg(n) for all n, n≥ n0 • The main difference between Big Omega and Little omega lies in their definition • In Big Omega f(n) = Ω(g(n)) and the bound is 0 ≤ cg(n)<f(n) so it is true only for some positive value of c • In little o, it is true for all constant c>0 5/25/2021
  • 19. Analysing algorithm control structures We start by considering how to count operations in for-loops. • First of all, we should know the number of iterations of the loop; say it is x • Then the loop condition is executed x + 1 times. • Each of the statements in the loop body is executed x times • The loop-index update statement is executed x times 5/25/2021
  • 20. Analysing algorithm control structures contd. 5/25/2021 Loops: Complexity is determined by the number of iterations in the loop times the complexity of the body of the loop EXAMPLE
  • 21. Analysing algorithm control structures contd. Nested independent loops: Complexity of inner loop * complexity of outer loop 5/25/2021 Example Nested dependent loops: Examples: Number of repetitions of the inner loop is: 1 + 2 + 3 + . . . + n = n(n+2)/2 Hence the segment is O(n2)
  • 22. Analysing algorithm control structures contd. If Statement: O(max(O(condition1), O(condition2), . . , O(branch1), O(branch2), . . ., O(branchN)) 5/25/2021
  • 23. Analysing algorithm control structures contd. Switch: Take the complexity of the most expensive case including the default case 5/25/2021