SlideShare a Scribd company logo
1 of 23
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

What's hot

Fundamentals of the Analysis of Algorithm Efficiency
Fundamentals of the Analysis of Algorithm EfficiencyFundamentals of the Analysis of Algorithm Efficiency
Fundamentals of the Analysis of Algorithm EfficiencySaranya Natarajan
 
Introduction to toc and compiler
Introduction to toc and compilerIntroduction to toc and compiler
Introduction to toc and compilersavitamhaske
 
Code generation in Compiler Design
Code generation in Compiler DesignCode generation in Compiler Design
Code generation in Compiler DesignKuppusamy P
 
Minimization of DFA
Minimization of DFAMinimization of DFA
Minimization of DFAkunj desai
 
Introduction to NP Completeness
Introduction to NP CompletenessIntroduction to NP Completeness
Introduction to NP CompletenessGene Moo Lee
 
Master method
Master method Master method
Master method Rajendran
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithmsGanesh Solanke
 
DESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSDESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSGayathri Gaayu
 
Intermediate code generation
Intermediate code generationIntermediate code generation
Intermediate code generationAkshaya Arunan
 
Lexical Analysis - Compiler Design
Lexical Analysis - Compiler DesignLexical Analysis - Compiler Design
Lexical Analysis - Compiler DesignAkhil Kaushik
 
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 IMohamed Loey
 
Compiler vs interpreter
Compiler vs interpreterCompiler vs interpreter
Compiler vs interpreterParas Patel
 

What's hot (20)

Asymptotic Notation
Asymptotic NotationAsymptotic Notation
Asymptotic Notation
 
Fundamentals of the Analysis of Algorithm Efficiency
Fundamentals of the Analysis of Algorithm EfficiencyFundamentals of the Analysis of Algorithm Efficiency
Fundamentals of the Analysis of Algorithm Efficiency
 
Introduction to toc and compiler
Introduction to toc and compilerIntroduction to toc and compiler
Introduction to toc and compiler
 
Code generation in Compiler Design
Code generation in Compiler DesignCode generation in Compiler Design
Code generation in Compiler Design
 
Minimization of DFA
Minimization of DFAMinimization of DFA
Minimization of DFA
 
Introduction to NP Completeness
Introduction to NP CompletenessIntroduction to NP Completeness
Introduction to NP Completeness
 
Pumping lemma
Pumping lemmaPumping lemma
Pumping lemma
 
Master method
Master method Master method
Master method
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithms
 
Daa unit 1
Daa unit 1Daa unit 1
Daa unit 1
 
DESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSDESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMS
 
Python Flow Control
Python Flow ControlPython Flow Control
Python Flow Control
 
Intermediate code generation
Intermediate code generationIntermediate code generation
Intermediate code generation
 
Analysis of algorithm
Analysis of algorithmAnalysis of algorithm
Analysis of algorithm
 
NP completeness
NP completenessNP completeness
NP completeness
 
Asymptotic notation
Asymptotic notationAsymptotic notation
Asymptotic notation
 
Lexical Analysis - Compiler Design
Lexical Analysis - Compiler DesignLexical Analysis - Compiler Design
Lexical Analysis - Compiler Design
 
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
 
Compiler vs interpreter
Compiler vs interpreterCompiler vs interpreter
Compiler vs interpreter
 
Finite automata
Finite automataFinite automata
Finite automata
 

Similar to Algorithm Analysis

Data Structure & Algorithms - Mathematical
Data Structure & Algorithms - MathematicalData Structure & Algorithms - Mathematical
Data Structure & Algorithms - Mathematicalbabuk110
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic NotationsRishabh Soni
 
Asymptotic Analysis in Data Structure using C
Asymptotic Analysis in Data Structure using CAsymptotic Analysis in Data Structure using C
Asymptotic Analysis in Data Structure using CMeghaj Mallick
 
CS8451 - Design and Analysis of Algorithms
CS8451 - Design and Analysis of AlgorithmsCS8451 - Design and Analysis of Algorithms
CS8451 - Design and Analysis of AlgorithmsKrishnan MuthuManickam
 
Daa unit 6_efficiency of algorithms
Daa unit 6_efficiency of algorithmsDaa unit 6_efficiency of algorithms
Daa unit 6_efficiency of algorithmssnehajiyani
 
Asymptotic Notations.pptx
Asymptotic Notations.pptxAsymptotic Notations.pptx
Asymptotic Notations.pptxSunilWork1
 
Asymptotics 140510003721-phpapp02
Asymptotics 140510003721-phpapp02Asymptotics 140510003721-phpapp02
Asymptotics 140510003721-phpapp02mansab MIRZA
 
Design and Analysis of Algorithms Lecture Notes
Design and Analysis of Algorithms Lecture NotesDesign and Analysis of Algorithms Lecture Notes
Design and Analysis of Algorithms Lecture NotesSreedhar Chowdam
 
Analysis Of Algorithms I
Analysis Of Algorithms IAnalysis Of Algorithms I
Analysis Of Algorithms ISri Prasanna
 
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 algorithmDevaKumari Vijay
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic NotationsNagendraK18
 
ASYMTOTIC NOTATIONS BIG O OEMGA THETE NOTATION.pptx
ASYMTOTIC NOTATIONS BIG O OEMGA THETE NOTATION.pptxASYMTOTIC NOTATIONS BIG O OEMGA THETE NOTATION.pptx
ASYMTOTIC NOTATIONS BIG O OEMGA THETE NOTATION.pptxsunitha1792
 
Algorithms required for data structures(basics like Arrays, Stacks ,Linked Li...
Algorithms required for data structures(basics like Arrays, Stacks ,Linked Li...Algorithms required for data structures(basics like Arrays, Stacks ,Linked Li...
Algorithms required for data structures(basics like Arrays, Stacks ,Linked Li...DebiPrasadSen
 
Data Structures- Part2 analysis tools
Data Structures- Part2 analysis toolsData Structures- Part2 analysis tools
Data Structures- Part2 analysis toolsAbdullah Al-hazmy
 
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.Tariq Khan
 

Similar to Algorithm Analysis (20)

Data Structure & Algorithms - Mathematical
Data Structure & Algorithms - MathematicalData Structure & Algorithms - Mathematical
Data Structure & Algorithms - Mathematical
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic Notations
 
Asymptotic Analysis in Data Structure using C
Asymptotic Analysis in Data Structure using CAsymptotic Analysis in Data Structure using C
Asymptotic Analysis in Data Structure using C
 
Unit ii algorithm
Unit   ii algorithmUnit   ii algorithm
Unit ii algorithm
 
CS8451 - Design and Analysis of Algorithms
CS8451 - Design and Analysis of AlgorithmsCS8451 - Design and Analysis of Algorithms
CS8451 - Design and Analysis of Algorithms
 
Daa unit 6_efficiency of algorithms
Daa unit 6_efficiency of algorithmsDaa unit 6_efficiency of algorithms
Daa unit 6_efficiency of algorithms
 
Asymptotic Notations.pptx
Asymptotic Notations.pptxAsymptotic Notations.pptx
Asymptotic Notations.pptx
 
Asymptotics 140510003721-phpapp02
Asymptotics 140510003721-phpapp02Asymptotics 140510003721-phpapp02
Asymptotics 140510003721-phpapp02
 
Design and Analysis of Algorithms Lecture Notes
Design and Analysis of Algorithms Lecture NotesDesign and Analysis of Algorithms Lecture Notes
Design and Analysis of Algorithms Lecture Notes
 
Analysis Of Algorithms I
Analysis Of Algorithms IAnalysis Of Algorithms I
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, 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, Kukatpall...Algorithm Class at KPHB  (C, C++ Course Training Institute in KPHB, Kukatpall...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpall...
 
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, Kukatpally...
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, Kukatpally...Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
 
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
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic Notations
 
ASYMTOTIC NOTATIONS BIG O OEMGA THETE NOTATION.pptx
ASYMTOTIC NOTATIONS BIG O OEMGA THETE NOTATION.pptxASYMTOTIC NOTATIONS BIG O OEMGA THETE NOTATION.pptx
ASYMTOTIC NOTATIONS BIG O OEMGA THETE NOTATION.pptx
 
Algorithms required for data structures(basics like Arrays, Stacks ,Linked Li...
Algorithms required for data structures(basics like Arrays, Stacks ,Linked Li...Algorithms required for data structures(basics like Arrays, Stacks ,Linked Li...
Algorithms required for data structures(basics like Arrays, Stacks ,Linked Li...
 
Data Structures- Part2 analysis tools
Data Structures- Part2 analysis toolsData Structures- Part2 analysis tools
Data Structures- Part2 analysis tools
 
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.
 

More from Megha V

Soft Computing Techniques_Part 1.pptx
Soft Computing Techniques_Part 1.pptxSoft Computing Techniques_Part 1.pptx
Soft Computing Techniques_Part 1.pptxMegha V
 
JavaScript- Functions and arrays.pptx
JavaScript- Functions and arrays.pptxJavaScript- Functions and arrays.pptx
JavaScript- Functions and arrays.pptxMegha V
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScriptMegha V
 
Python Exception Handling
Python Exception HandlingPython Exception Handling
Python Exception HandlingMegha V
 
Python- Regular expression
Python- Regular expressionPython- Regular expression
Python- Regular expressionMegha V
 
File handling in Python
File handling in PythonFile handling in Python
File handling in PythonMegha V
 
Python programming -Tuple and Set Data type
Python programming -Tuple and Set Data typePython programming -Tuple and Set Data type
Python programming -Tuple and Set Data typeMegha V
 
Python programming –part 7
Python programming –part 7Python programming –part 7
Python programming –part 7Megha V
 
Python programming Part -6
Python programming Part -6Python programming Part -6
Python programming Part -6Megha V
 
Python programming: Anonymous functions, String operations
Python programming: Anonymous functions, String operationsPython programming: Anonymous functions, String operations
Python programming: Anonymous functions, String operationsMegha V
 
Python programming- Part IV(Functions)
Python programming- Part IV(Functions)Python programming- Part IV(Functions)
Python programming- Part IV(Functions)Megha V
 
Python programming –part 3
Python programming –part 3Python programming –part 3
Python programming –part 3Megha V
 
Parts of python programming language
Parts of python programming languageParts of python programming language
Parts of python programming languageMegha V
 
Python programming
Python programmingPython programming
Python programmingMegha V
 
Strassen's matrix multiplication
Strassen's matrix multiplicationStrassen's matrix multiplication
Strassen's matrix multiplicationMegha V
 
Solving recurrences
Solving recurrencesSolving recurrences
Solving recurrencesMegha V
 
Algorithm analysis and design
Algorithm analysis and designAlgorithm analysis and design
Algorithm analysis and designMegha V
 
Genetic algorithm
Genetic algorithmGenetic algorithm
Genetic algorithmMegha V
 
UGC NET Paper 1 ICT Memory and data
UGC NET Paper 1 ICT Memory and data  UGC NET Paper 1 ICT Memory and data
UGC NET Paper 1 ICT Memory and data Megha V
 
Seminar presentation on OpenGL
Seminar presentation on OpenGLSeminar presentation on OpenGL
Seminar presentation on OpenGLMegha V
 

More from Megha V (20)

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

Recently uploaded

Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxnada99848
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 

Recently uploaded (20)

Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptx
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 

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