Algorithm analysis and design

Megha V
Megha VResearch Scholar en Kannur University
INTRODUCTION TO ALGORITHM ANALYSIS
AND DESIGN
BY
MEGHA V
RESEARCH SCHOLAR
KANNUR UNIVERSITY
CONTENTS
•INTRODUCTION
•DEFINITION OF ALGORITHMS
•ALGORITHM SPECIFICATION
•ANALYSIS OF ALGORITHMS
•ASYMPTOTIC NOTATIONS
INTRODUCTION
•The word algorithm comes from the name of Persian author, Abu Ja’far
Mohammed ibn Musa al Khowarizmi, who wrote a textbook on mathematics.
•Algorithm” refer to a method that can be used by a computer for the solution of
a problem.
Definition of Algorithms
Definition: An algorithm is a finite set of unambiguous instruction that if
followed accomplishes a particular task
• An algorithm should have finite number of steps
• It should accept Input and produce desired output
• Algorithm should terminate
An algorithm should satisfy the following
criteria
• Input: Algorithm should have Zero or more inputs
• Output: The algorithm should produce correct output
• Definiteness: Each instruction should be clear and unambiguous.
• Finiteness: The algorithm must terminate after finite number of steps.
• Effectiveness: The instructions should be simple and should transform given
input to desired output
• A program is an expression of algorithm in a programming language
Algorithm Specification
• We can use natural languages like English
• Graphic representation is called flow chart
• Another representation is Pseudocode that resembles C or Pascal
1. Comments begin with //
2. Blocks are indicated with matching braces {
}
3. An identifier begins with a letter
4. Simple data types like integer, char, float,
Boolean(True or False) can be used
5. Assignment of values to variables is done
using the assignment statement
< variable> :=<expression> or
< variable> <expression>
6. Logical operators (and, or, not )and the
relational operators <, ≤, =,≠,>, ≥ are
provided
Algorithm Specification
7. The following looping statements are employed:
for, while, repeat-until
8. The following conditional statements can be
used
If……. Then….
if …….then……else……
9. Array indices starts at zero, array elements are
represented using [] eg: A[i]
10. Inputs and outputs are done using the
instructions read and write
11. There is only one procedure: Algorithm
the heading takes the form
Algorithm Name ( parameter list)
While loop
While<condition>do
{
<statement 1>
…………….
…………….
<statement n>
}
While<variable<=n>do
{
<statement 1>
…………….
…………….
<statement n>
variable:=variable + incr
}
For loop
for variable:=value1 to value2 [step stepval]do
{
<statement 1>
………..
………..
<statement n>
}
Repeat-until loop
Repeat
{
<statement 1>
………..
………..
<statement n>
}Until<condition>
Condition
Conditional statements can be given in two
forms
If<condition> then
<statements>
If<condition> then
<statement 1>
else
<statement 2>
selection
Case statement
Case
{ :<condition 1> :<statement 1>
:
:<condition n> :<statement n>
:else :<statement n+1>
}
How to Analyze Algorithms
• 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: Algorithms computing time is obtained in terms of order of
magnitude
• 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
Testing
Testing consists of two phases
• Debugging:
- The process of executing the program on sample data sets and verify if
correct results are obtained.
• Profiling or performance measurement
- The process of executing a correct program on data set and measuring the
time and space it take to compute the result
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.
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. .
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.
Order of growth
The efficiency of algorithm can be analyzed by considering highest order of n.
Asymptotic notations
Asymptotic notations are used to compare the order of growth of algorithms.
The three notations used are
1. Big oh (O) notation
2. Big omega ( ) notation
3. Big theta ( )notation
Big O
Big-O, commonly written as O, is an Asymptotic Notation for the worst case, or ceiling of growth
for a given function.
A function t (n) is said to be in O(g(n)), denoted t (n) ∈ O(g(n)),
if t (n) is bounded above by some constant multiple of g(n) for all large n,
i.e., if there exist some positive constant c
and some nonnegative integer n0 such that
t (n) ≤ cg(n) for all n ≥ n0.
Big-Omega
•commonly written as Ω, is an Asymptotic Notation for the best case, or a floor growth rate for a
given function.
• It provides us with an asymptotic lower bound for the growth rate of runtime of an algorithm.
•A function t (n) is said to be in Ω(g(n)), denoted t (n) ∈ Ω(g(n)),
if t (n) is bounded below by some positive constant
multiple of g(n) for all large n, i.e., if there exist some
positive constant c and some nonnegative integer n0
Such that
t (n) ≥ cg(n) for all n ≥ n0.
Big Theta:
•A function t (n) is said to be in θ(g(n)), denoted t (n) ∈ θ(g(n)),
if t (n) is bounded both above and below by some positive constant multiples of
g(n) for all large n, i.e., if there exist some positive constants c1 and c2 and some
nonnegative integer n0 such that
c2g(n) ≤ t (n) ≤ c1g(n) for all n ≥ n0
REFERENCES
• ‘Introduction to The Design and Analysis of Algorithms’, Anany Levitin, 3rd Edn,
Pearson education
1 de 25

Recomendados

09 intelligent systems-agents por
09 intelligent systems-agents09 intelligent systems-agents
09 intelligent systems-agentsSTI Innsbruck
81 vistas101 diapositivas
3. recurrence relation por
3. recurrence relation3. recurrence relation
3. recurrence relationRajandeep Gill
6.4K vistas32 diapositivas
Algorithms Lecture 2: Analysis of Algorithms I por
Algorithms Lecture 2: Analysis of Algorithms IAlgorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms IBenha University
6.1K vistas43 diapositivas
Algorithms Lecture 1: Introduction to Algorithms por
Algorithms Lecture 1: Introduction to AlgorithmsAlgorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to AlgorithmsBenha University
3.3K vistas31 diapositivas
Survey of Attention mechanism & Use in Computer Vision por
Survey of Attention mechanism & Use in Computer VisionSurvey of Attention mechanism & Use in Computer Vision
Survey of Attention mechanism & Use in Computer VisionSwatiNarkhede1
139 vistas18 diapositivas
Anlysis and design of algorithms part 1 por
Anlysis and design of algorithms part 1Anlysis and design of algorithms part 1
Anlysis and design of algorithms part 1Deepak John
1.4K vistas81 diapositivas

Más contenido relacionado

La actualidad más candente

CS8461 - Design and Analysis of Algorithms por
CS8461 - Design and Analysis of AlgorithmsCS8461 - Design and Analysis of Algorithms
CS8461 - Design and Analysis of AlgorithmsKrishnan MuthuManickam
264 vistas65 diapositivas
Introduction to design and analysis of algorithm por
Introduction to design and analysis of algorithmIntroduction to design and analysis of algorithm
Introduction to design and analysis of algorithmDevaKumari Vijay
205 vistas24 diapositivas
Deep Learning Tutorial | Deep Learning TensorFlow | Deep Learning With Neural... por
Deep Learning Tutorial | Deep Learning TensorFlow | Deep Learning With Neural...Deep Learning Tutorial | Deep Learning TensorFlow | Deep Learning With Neural...
Deep Learning Tutorial | Deep Learning TensorFlow | Deep Learning With Neural...Simplilearn
1.8K vistas72 diapositivas
Nature-Inspired Metaheuristic Algorithms por
Nature-Inspired Metaheuristic AlgorithmsNature-Inspired Metaheuristic Algorithms
Nature-Inspired Metaheuristic AlgorithmsXin-She Yang
2.6K vistas75 diapositivas
Introduction to problem solving in c++ por
Introduction to problem solving in c++Introduction to problem solving in c++
Introduction to problem solving in c++Online
15.6K vistas45 diapositivas

La actualidad más candente(20)

Introduction to design and analysis of algorithm por DevaKumari Vijay
Introduction to design and analysis of algorithmIntroduction to design and analysis of algorithm
Introduction to design and analysis of algorithm
DevaKumari Vijay205 vistas
Deep Learning Tutorial | Deep Learning TensorFlow | Deep Learning With Neural... por Simplilearn
Deep Learning Tutorial | Deep Learning TensorFlow | Deep Learning With Neural...Deep Learning Tutorial | Deep Learning TensorFlow | Deep Learning With Neural...
Deep Learning Tutorial | Deep Learning TensorFlow | Deep Learning With Neural...
Simplilearn1.8K vistas
Nature-Inspired Metaheuristic Algorithms por Xin-She Yang
Nature-Inspired Metaheuristic AlgorithmsNature-Inspired Metaheuristic Algorithms
Nature-Inspired Metaheuristic Algorithms
Xin-She Yang2.6K vistas
Introduction to problem solving in c++ por Online
Introduction to problem solving in c++Introduction to problem solving in c++
Introduction to problem solving in c++
Online 15.6K vistas
Natural Language Processing por Yasir Khan
Natural Language ProcessingNatural Language Processing
Natural Language Processing
Yasir Khan4K vistas
Genetic Algorithm in Artificial Intelligence por Sinbad Konick
Genetic Algorithm in Artificial IntelligenceGenetic Algorithm in Artificial Intelligence
Genetic Algorithm in Artificial Intelligence
Sinbad Konick922 vistas
Lecture 4 asymptotic notations por jayavignesh86
Lecture 4   asymptotic notationsLecture 4   asymptotic notations
Lecture 4 asymptotic notations
jayavignesh861.3K vistas
Np completeness por Rajendran
Np completenessNp completeness
Np completeness
Rajendran 3.5K vistas
Variants of Turing Machine por Rajendran
Variants of Turing MachineVariants of Turing Machine
Variants of Turing Machine
Rajendran 13.3K vistas
Artificial Neural Networks for NIU session 2016 17 por Prof. Neeta Awasthy
Artificial Neural Networks for NIU session 2016 17 Artificial Neural Networks for NIU session 2016 17
Artificial Neural Networks for NIU session 2016 17
Prof. Neeta Awasthy638 vistas

Similar a Algorithm analysis and design

2. Introduction to Algorithm.pptx por
2. Introduction to Algorithm.pptx2. Introduction to Algorithm.pptx
2. Introduction to Algorithm.pptxRahikAhmed1
53 vistas21 diapositivas
Lec 2 algorithms efficiency complexity por
Lec 2 algorithms efficiency  complexityLec 2 algorithms efficiency  complexity
Lec 2 algorithms efficiency complexityAnaya Zafar
380 vistas19 diapositivas
Algorithm.pptx por
Algorithm.pptxAlgorithm.pptx
Algorithm.pptxKoteswari Kasireddy
16 vistas20 diapositivas
Algorithm.pptx por
Algorithm.pptxAlgorithm.pptx
Algorithm.pptxKoteswari Kasireddy
8 vistas20 diapositivas
Unit ii algorithm por
Unit   ii algorithmUnit   ii algorithm
Unit ii algorithmTribhuvan University
592 vistas18 diapositivas
Python algorithm por
Python algorithmPython algorithm
Python algorithmProf. Dr. K. Adisesha
398 vistas18 diapositivas

Similar a Algorithm analysis and design(20)

2. Introduction to Algorithm.pptx por RahikAhmed1
2. Introduction to Algorithm.pptx2. Introduction to Algorithm.pptx
2. Introduction to Algorithm.pptx
RahikAhmed153 vistas
Lec 2 algorithms efficiency complexity por Anaya Zafar
Lec 2 algorithms efficiency  complexityLec 2 algorithms efficiency  complexity
Lec 2 algorithms efficiency complexity
Anaya Zafar380 vistas
Unit i basic concepts of algorithms por sangeetha s
Unit i basic concepts of algorithmsUnit i basic concepts of algorithms
Unit i basic concepts of algorithms
sangeetha s3.6K vistas
Lecture 03 algorithm analysis por Nurjahan Nipa
Lecture 03 algorithm analysisLecture 03 algorithm analysis
Lecture 03 algorithm analysis
Nurjahan Nipa53 vistas
DSA por rrupa2
DSADSA
DSA
rrupa258 vistas
Data structures algorithms basics por ayeshasafdar8
Data structures   algorithms basicsData structures   algorithms basics
Data structures algorithms basics
ayeshasafdar822 vistas
Algorithm Analysis.pdf por MemMem25
Algorithm Analysis.pdfAlgorithm Analysis.pdf
Algorithm Analysis.pdf
MemMem2520 vistas

Más de Megha V

JavaScript- Functions and arrays.pptx por
JavaScript- Functions and arrays.pptxJavaScript- Functions and arrays.pptx
JavaScript- Functions and arrays.pptxMegha V
54 vistas52 diapositivas
Introduction to JavaScript por
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScriptMegha V
118 vistas40 diapositivas
Python Exception Handling por
Python Exception HandlingPython Exception Handling
Python Exception HandlingMegha V
2K vistas20 diapositivas
Python- Regular expression por
Python- Regular expressionPython- Regular expression
Python- Regular expressionMegha V
377 vistas26 diapositivas
File handling in Python por
File handling in PythonFile handling in Python
File handling in PythonMegha V
7.1K vistas45 diapositivas
Python programming -Tuple and Set Data type por
Python programming -Tuple and Set Data typePython programming -Tuple and Set Data type
Python programming -Tuple and Set Data typeMegha V
175 vistas24 diapositivas

Más de Megha V(20)

JavaScript- Functions and arrays.pptx por Megha V
JavaScript- Functions and arrays.pptxJavaScript- Functions and arrays.pptx
JavaScript- Functions and arrays.pptx
Megha V54 vistas
Introduction to JavaScript por Megha V
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
Megha V118 vistas
Python Exception Handling por Megha V
Python Exception HandlingPython Exception Handling
Python Exception Handling
Megha V2K vistas
Python- Regular expression por Megha V
Python- Regular expressionPython- Regular expression
Python- Regular expression
Megha V377 vistas
File handling in Python por Megha V
File handling in PythonFile handling in Python
File handling in Python
Megha V7.1K vistas
Python programming -Tuple and Set Data type por Megha V
Python programming -Tuple and Set Data typePython programming -Tuple and Set Data type
Python programming -Tuple and Set Data type
Megha V175 vistas
Python programming –part 7 por Megha V
Python programming –part 7Python programming –part 7
Python programming –part 7
Megha V113 vistas
Python programming Part -6 por Megha V
Python programming Part -6Python programming Part -6
Python programming Part -6
Megha V111 vistas
Python programming: Anonymous functions, String operations por Megha V
Python programming: Anonymous functions, String operationsPython programming: Anonymous functions, String operations
Python programming: Anonymous functions, String operations
Megha V210 vistas
Python programming- Part IV(Functions) por Megha V
Python programming- Part IV(Functions)Python programming- Part IV(Functions)
Python programming- Part IV(Functions)
Megha V243 vistas
Python programming –part 3 por Megha V
Python programming –part 3Python programming –part 3
Python programming –part 3
Megha V214 vistas
Parts of python programming language por Megha V
Parts of python programming languageParts of python programming language
Parts of python programming language
Megha V682 vistas
Python programming por Megha V
Python programmingPython programming
Python programming
Megha V938 vistas
Strassen's matrix multiplication por Megha V
Strassen's matrix multiplicationStrassen's matrix multiplication
Strassen's matrix multiplication
Megha V1K vistas
Solving recurrences por Megha V
Solving recurrencesSolving recurrences
Solving recurrences
Megha V383 vistas
Algorithm Analysis por Megha V
Algorithm AnalysisAlgorithm Analysis
Algorithm Analysis
Megha V66 vistas
Genetic algorithm por Megha V
Genetic algorithmGenetic algorithm
Genetic algorithm
Megha V275 vistas
UGC NET Paper 1 ICT Memory and data por Megha 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
Megha V129 vistas
Seminar presentation on OpenGL por Megha V
Seminar presentation on OpenGLSeminar presentation on OpenGL
Seminar presentation on OpenGL
Megha V376 vistas
Msc project_CDS Automation por Megha V
Msc project_CDS AutomationMsc project_CDS Automation
Msc project_CDS Automation
Megha V64 vistas

Último

Igniting Next Level Productivity with AI-Infused Data Integration Workflows por
Igniting Next Level Productivity with AI-Infused Data Integration Workflows Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows Safe Software
280 vistas86 diapositivas
Zero to Automated in Under a Year por
Zero to Automated in Under a YearZero to Automated in Under a Year
Zero to Automated in Under a YearNetwork Automation Forum
15 vistas23 diapositivas
Case Study Copenhagen Energy and Business Central.pdf por
Case Study Copenhagen Energy and Business Central.pdfCase Study Copenhagen Energy and Business Central.pdf
Case Study Copenhagen Energy and Business Central.pdfAitana
16 vistas3 diapositivas
Vertical User Stories por
Vertical User StoriesVertical User Stories
Vertical User StoriesMoisés Armani Ramírez
14 vistas16 diapositivas
Special_edition_innovator_2023.pdf por
Special_edition_innovator_2023.pdfSpecial_edition_innovator_2023.pdf
Special_edition_innovator_2023.pdfWillDavies22
18 vistas6 diapositivas
PharoJS - Zürich Smalltalk Group Meetup November 2023 por
PharoJS - Zürich Smalltalk Group Meetup November 2023PharoJS - Zürich Smalltalk Group Meetup November 2023
PharoJS - Zürich Smalltalk Group Meetup November 2023Noury Bouraqadi
132 vistas17 diapositivas

Último(20)

Igniting Next Level Productivity with AI-Infused Data Integration Workflows por Safe Software
Igniting Next Level Productivity with AI-Infused Data Integration Workflows Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Safe Software280 vistas
Case Study Copenhagen Energy and Business Central.pdf por Aitana
Case Study Copenhagen Energy and Business Central.pdfCase Study Copenhagen Energy and Business Central.pdf
Case Study Copenhagen Energy and Business Central.pdf
Aitana16 vistas
Special_edition_innovator_2023.pdf por WillDavies22
Special_edition_innovator_2023.pdfSpecial_edition_innovator_2023.pdf
Special_edition_innovator_2023.pdf
WillDavies2218 vistas
PharoJS - Zürich Smalltalk Group Meetup November 2023 por Noury Bouraqadi
PharoJS - Zürich Smalltalk Group Meetup November 2023PharoJS - Zürich Smalltalk Group Meetup November 2023
PharoJS - Zürich Smalltalk Group Meetup November 2023
Noury Bouraqadi132 vistas
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院 por IttrainingIttraining
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院
The Forbidden VPN Secrets.pdf por Mariam Shaba
The Forbidden VPN Secrets.pdfThe Forbidden VPN Secrets.pdf
The Forbidden VPN Secrets.pdf
Mariam Shaba20 vistas
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ... por Jasper Oosterveld
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
Jasper Oosterveld19 vistas
STKI Israeli Market Study 2023 corrected forecast 2023_24 v3.pdf por Dr. Jimmy Schwarzkopf
STKI Israeli Market Study 2023   corrected forecast 2023_24 v3.pdfSTKI Israeli Market Study 2023   corrected forecast 2023_24 v3.pdf
STKI Israeli Market Study 2023 corrected forecast 2023_24 v3.pdf
Future of AR - Facebook Presentation por ssuserb54b561
Future of AR - Facebook PresentationFuture of AR - Facebook Presentation
Future of AR - Facebook Presentation
ssuserb54b56115 vistas
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive por Network Automation Forum
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLiveAutomating a World-Class Technology Conference; Behind the Scenes of CiscoLive
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive
Unit 1_Lecture 2_Physical Design of IoT.pdf por StephenTec
Unit 1_Lecture 2_Physical Design of IoT.pdfUnit 1_Lecture 2_Physical Design of IoT.pdf
Unit 1_Lecture 2_Physical Design of IoT.pdf
StephenTec12 vistas

Algorithm analysis and design

  • 1. INTRODUCTION TO ALGORITHM ANALYSIS AND DESIGN BY MEGHA V RESEARCH SCHOLAR KANNUR UNIVERSITY
  • 2. CONTENTS •INTRODUCTION •DEFINITION OF ALGORITHMS •ALGORITHM SPECIFICATION •ANALYSIS OF ALGORITHMS •ASYMPTOTIC NOTATIONS
  • 3. INTRODUCTION •The word algorithm comes from the name of Persian author, Abu Ja’far Mohammed ibn Musa al Khowarizmi, who wrote a textbook on mathematics. •Algorithm” refer to a method that can be used by a computer for the solution of a problem.
  • 4. Definition of Algorithms Definition: An algorithm is a finite set of unambiguous instruction that if followed accomplishes a particular task • An algorithm should have finite number of steps • It should accept Input and produce desired output • Algorithm should terminate
  • 5. An algorithm should satisfy the following criteria • Input: Algorithm should have Zero or more inputs • Output: The algorithm should produce correct output • Definiteness: Each instruction should be clear and unambiguous. • Finiteness: The algorithm must terminate after finite number of steps. • Effectiveness: The instructions should be simple and should transform given input to desired output • A program is an expression of algorithm in a programming language
  • 6. Algorithm Specification • We can use natural languages like English • Graphic representation is called flow chart • Another representation is Pseudocode that resembles C or Pascal
  • 7. 1. Comments begin with // 2. Blocks are indicated with matching braces { } 3. An identifier begins with a letter 4. Simple data types like integer, char, float, Boolean(True or False) can be used 5. Assignment of values to variables is done using the assignment statement < variable> :=<expression> or < variable> <expression> 6. Logical operators (and, or, not )and the relational operators <, ≤, =,≠,>, ≥ are provided Algorithm Specification
  • 8. 7. The following looping statements are employed: for, while, repeat-until 8. The following conditional statements can be used If……. Then…. if …….then……else……
  • 9. 9. Array indices starts at zero, array elements are represented using [] eg: A[i] 10. Inputs and outputs are done using the instructions read and write 11. There is only one procedure: Algorithm the heading takes the form Algorithm Name ( parameter list)
  • 10. While loop While<condition>do { <statement 1> ……………. ……………. <statement n> } While<variable<=n>do { <statement 1> ……………. ……………. <statement n> variable:=variable + incr }
  • 11. For loop for variable:=value1 to value2 [step stepval]do { <statement 1> ……….. ……….. <statement n> }
  • 13. Condition Conditional statements can be given in two forms If<condition> then <statements> If<condition> then <statement 1> else <statement 2>
  • 14. selection Case statement Case { :<condition 1> :<statement 1> : :<condition n> :<statement n> :else :<statement n+1> }
  • 15. How to Analyze Algorithms • 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: Algorithms computing time is obtained in terms of order of magnitude • 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
  • 16. Testing Testing consists of two phases • Debugging: - The process of executing the program on sample data sets and verify if correct results are obtained. • Profiling or performance measurement - The process of executing a correct program on data set and measuring the time and space it take to compute the result
  • 17. 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.
  • 18. 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. .
  • 19. 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.
  • 20. Order of growth The efficiency of algorithm can be analyzed by considering highest order of n.
  • 21. Asymptotic notations Asymptotic notations are used to compare the order of growth of algorithms. The three notations used are 1. Big oh (O) notation 2. Big omega ( ) notation 3. Big theta ( )notation
  • 22. Big O Big-O, commonly written as O, is an Asymptotic Notation for the worst case, or ceiling of growth for a given function. A function t (n) is said to be in O(g(n)), denoted t (n) ∈ O(g(n)), if t (n) is bounded above by some constant multiple of g(n) for all large n, i.e., if there exist some positive constant c and some nonnegative integer n0 such that t (n) ≤ cg(n) for all n ≥ n0.
  • 23. Big-Omega •commonly written as Ω, is an Asymptotic Notation for the best case, or a floor growth rate for a given function. • It provides us with an asymptotic lower bound for the growth rate of runtime of an algorithm. •A function t (n) is said to be in Ω(g(n)), denoted t (n) ∈ Ω(g(n)), if t (n) is bounded below by some positive constant multiple of g(n) for all large n, i.e., if there exist some positive constant c and some nonnegative integer n0 Such that t (n) ≥ cg(n) for all n ≥ n0.
  • 24. Big Theta: •A function t (n) is said to be in θ(g(n)), denoted t (n) ∈ θ(g(n)), if t (n) is bounded both above and below by some positive constant multiples of g(n) for all large n, i.e., if there exist some positive constants c1 and c2 and some nonnegative integer n0 such that c2g(n) ≤ t (n) ≤ c1g(n) for all n ≥ n0
  • 25. REFERENCES • ‘Introduction to The Design and Analysis of Algorithms’, Anany Levitin, 3rd Edn, Pearson education