SlideShare a Scribd company logo
2-1Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2nd
ed., Ch. 2
COMSATS INSTITUTE OFCOMSATS INSTITUTE OF
INFORMATION & TECHNOLOGY,INFORMATION & TECHNOLOGY,
VEHARIVEHARI
Subject Code : CSC201
Subject Teacher : Sir Muhammad Afzal
Name Of Subject : DESIGN & ANALYSIS OF ALGORITHMS
Name of Unit : ANALYSIS OF ALGORITHMS
Topic : Introduction, Analysis, Efficeincy of algorithms
Name of Students : Mubariz Hamza Aslam (FA15-BCS-152)
Muzamil Hayat Khan (FA15-BCS-080)
2-2Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2nd
ed., Ch. 2
CONTENTSCONTENTS
IINTRODUCTION TO ALGORITHMSNTRODUCTION TO ALGORITHMS
ANALYSIS OF ALGORITHMANALYSIS OF ALGORITHM
EFFIECIENCY OF ALGORITHMEFFIECIENCY OF ALGORITHM
BEST CASEBEST CASE
WORST CASEWORST CASE
AVERAGE CASEAVERAGE CASE
EXAMPLESEXAMPLES
Sub: DESIGN & ANALYSIS OF ALGORITHM
Topic: Introduction,Analysis,Effieciency Of Algorithm
2-3Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2nd
ed., Ch. 2
INTRODUCTION OFINTRODUCTION OF
ALGORITHMSALGORITHMS
• An Algorithm is a Step by Step solution of aAn Algorithm is a Step by Step solution of a
specific mathematical or computer relatedspecific mathematical or computer related
problemproblem
• There are different types of AlgorithmsThere are different types of Algorithms
• GreedyGreedy
• DynamicDynamic
• Divide & Conquer ,etcDivide & Conquer ,etc
• They can be expressed in different ways.They can be expressed in different ways.
• Pseudo codePseudo code
• By using simple English statements(Steps)By using simple English statements(Steps)
Sub: DESIGN & ANALYSIS OF ALGORITHM
Topic: Introduction,Analysis,Effieciency Of Algorithm
2-4Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2nd
ed., Ch. 2
ANALYSIS OF ALGORITHMSANALYSIS OF ALGORITHMS
• Issues:Issues:
• correctnesscorrectness
• time efficiencytime efficiency
• space efficiencyspace efficiency
• optimalityoptimality
• Approaches:Approaches:
• theoretical analysistheoretical analysis
• empirical analysisempirical analysis
Sub: DESIGN & ANALYSIS OF ALGORITHM
Topic: Introduction,Analysis,Effieciency Of Algorithm
THEORETICAL ANALYSIS OFTHEORETICAL ANALYSIS OF
TIME EFFICIENCYTIME EFFICIENCY
Time efficiency is analyzed by determining the
number of repetitions of the basic operation as
a function of input size
• Basic operation: the operation that
contributes most towards the running time of
the algorithm
T(n) ≈ copC(n)running time
execution time
for basic operation
Number of times
basic operation is
executed
input size
Sub: DESIGN & ANALYSIS OF ALGORITHM
Topic: Introduction,Analysis,Effieciency Of Algorithm
INPUT SIZE AND BASIC OPERATIONINPUT SIZE AND BASIC OPERATION
EXAMPLESEXAMPLES
ProblemProblem Input size measureInput size measure Basic operationBasic operation
Searching for keySearching for key
in a list ofin a list of nn itemsitems
Number of list’sNumber of list’s
items, i.e.items, i.e. nn
Key comparisonKey comparison
Multiplication ofMultiplication of
two matricestwo matrices
Matrix dimensions orMatrix dimensions or
total number oftotal number of
elementselements
Multiplication ofMultiplication of
two numberstwo numbers
Checking primalityChecking primality
of a given integerof a given integer
nn
n’n’size = number ofsize = number of
digits (in binarydigits (in binary
representation)representation)
DivisionDivision
Typical graphTypical graph
problemproblem
#vertices and/or#vertices and/or
edgesedges
Visiting a vertexVisiting a vertex
or traversing anor traversing an
edgeedge
Sub: DESIGN & ANALYSIS OF ALGORITHM
Topic: Introduction,Analysis,Effieciency Of Algorithm
EMPIRICAL ANALYSIS OF TIMEEMPIRICAL ANALYSIS OF TIME
EFFICIENCYEFFICIENCY
• Select a specific (typical) sample of inputsSelect a specific (typical) sample of inputs
• Use physical unit of time (e.g., milliseconds)Use physical unit of time (e.g., milliseconds)
oror
Count actual number of basic operation’s executionsCount actual number of basic operation’s executions
• Analyze the empirical dataAnalyze the empirical data
Sub: DESIGN & ANALYSIS OF ALGORITHM
Topic: Introduction,Analysis,Effieciency Of Algorithm
BEST-CASE, AVERAGE-CASE,BEST-CASE, AVERAGE-CASE,
WORST-CASEWORST-CASE
For some algorithms efficiency depends on form ofFor some algorithms efficiency depends on form of
input:input:
• Worst case: CWorst case: Cworstworst((nn) – maximum over inputs of size) – maximum over inputs of size nn
• Best case: CBest case: Cbestbest((nn) – minimum over inputs of size) – minimum over inputs of size nn
• Average case: CAverage case: Cavgavg((nn) – “average” over inputs of size) – “average” over inputs of size nn
• Number of times the basic operation will be executed on typical inputNumber of times the basic operation will be executed on typical input
• NOT the average of worst and best caseNOT the average of worst and best case
• Expected number of basic operations considered as a random variable underExpected number of basic operations considered as a random variable under
some assumption about the probability distribution of all possible inputssome assumption about the probability distribution of all possible inputs
Sub: DESIGN & ANALYSIS OF ALGORITHM
Topic: Introduction,Analysis,Effieciency Of Algorithm
EXAMPLE: SEQUENTIAL SEARCHEXAMPLE: SEQUENTIAL SEARCH
• Worst caseWorst case
• Best caseBest case
• Average caseAverage caseSub: DESIGN & ANALYSIS OF ALGORITHM
Topic: Introduction,Analysis,Effieciency Of Algorithm
TYPES OF FORMULAS FOR BASICTYPES OF FORMULAS FOR BASIC
OPERATION’S COUNTOPERATION’S COUNT
• Exact formulaExact formula
e.g., C(e.g., C(nn) =) = nn((nn-1)/2-1)/2
• Formula indicating order of growth with specificFormula indicating order of growth with specific
multiplicative constantmultiplicative constant
e.g., C(e.g., C(nn)) ≈≈ 0.50.5 nn22
• Formula indicating order of growth with unknownFormula indicating order of growth with unknown
multiplicative constantmultiplicative constant
e.g., C(e.g., C(nn)) ≈≈ cncn22
Sub: DESIGN & ANALYSIS OF ALGORITHM
Topic: Introduction,Analysis,Effieciency Of Algorithm
ORDER OF GROWTHORDER OF GROWTH
• Most important: Order of growth within a constantMost important: Order of growth within a constant
multiple asmultiple as nn ∞→∞→
• Example:Example:
• How much faster will algorithm run on computer that is twice as fast?How much faster will algorithm run on computer that is twice as fast?
• How much longer does it take to solve problem of double input size?How much longer does it take to solve problem of double input size?
Sub: DESIGN & ANALYSIS OF ALGORITHM
Topic: Introduction,Analysis,Effieciency Of Algorithm
ASYMPTOTIC ORDER OFASYMPTOTIC ORDER OF
GROWTHGROWTH
A way of comparing functions that ignores constant factors andA way of comparing functions that ignores constant factors and
small input sizessmall input sizes
• O(O(gg((nn)): class of functions)): class of functions ff((nn) that grow) that grow no fasterno faster thanthan gg((nn))
• ΘΘ((gg((nn)): class of functions)): class of functions ff((nn) that grow) that grow at same rateat same rate asas gg((nn))
• ΩΩ((gg((nn)): class of functions)): class of functions ff((nn) that grow) that grow at least as fastat least as fast asas gg((nn))
Sub: DESIGN & ANALYSIS OF ALGORITHM
Topic: Introduction,Analysis,Effieciency Of Algorithm
BIG-OHBIG-OH
Sub: DESIGN & ANALYSIS OF ALGORITHM
Topic: Introduction,Analysis,Effieciency Of Algorithm
BIG-OMEGABIG-OMEGA
Sub: DESIGN & ANALYSIS OF ALGORITHM
Topic: Introduction,Analysis,Effieciency Of Algorithm
BIG-THETABIG-THETA
Sub: DESIGN & ANALYSIS OF ALGORITHM
Topic: Introduction,Analysis,Effieciency Of Algorithm
ORDERS OF GROWTH OF SOMEORDERS OF GROWTH OF SOME
IMPORTANT FUNCTIONSIMPORTANT FUNCTIONS
• All logarithmic functions logAll logarithmic functions logaa nn belong to the same classbelong to the same class
ΘΘ(log(log nn) no matter what the logarithm’s base) no matter what the logarithm’s base aa > 1 is> 1 is
• All polynomials of the same degreeAll polynomials of the same degree kk belong to the samebelong to the same
class:class: aakknnkk
++ aakk-1-1nnkk-1-1
+ … ++ … + aa00 ∈∈ ΘΘ((nnkk
))
• Exponential functionsExponential functions aann
have different orders of growthhave different orders of growth
for differentfor different aa’s’s
• orderorder loglog n <n < orderorder nnαα
((αα>0) < order>0) < order aann
< order< order nn! < order! < order nnnn
Sub: DESIGN & ANALYSIS OF ALGORITHM
Topic: Introduction,Analysis,Effieciency Of Algorithm
BASIC ASYMPTOTIC EFFICIENCYBASIC ASYMPTOTIC EFFICIENCY
CLASSESCLASSES
11 constantconstant
loglog nn logarithmiclogarithmic
nn linearlinear
nn loglog nn n-n-loglog-n-n
nn22
quadraticquadratic
nn33
cubiccubic
22nn
exponentialexponential
nn!! factorialfactorial
Sub: DESIGN & ANALYSIS OF ALGORITHM
Topic: Introduction,Analysis,Effieciency Of Algorithm
TIME EFFICIENCY OF NON-RECURSIVETIME EFFICIENCY OF NON-RECURSIVE
ALGORITHMSALGORITHMS
General Plan for AnalysisGeneral Plan for Analysis
• Decide on parameterDecide on parameter nn indicatingindicating input sizeinput size
• Identify algorithm’sIdentify algorithm’s basic operationbasic operation
• DetermineDetermine worstworst,, averageaverage, and, and bestbest cases for input of sizecases for input of size nn
• Set up a sum for the number of times the basic operation isSet up a sum for the number of times the basic operation is
executedexecuted
• Simplify the sum using standard formulas and rulesSimplify the sum using standard formulas and rules
Sub: DESIGN & ANALYSIS OF ALGORITHM
Topic: Introduction,Analysis,Effieciency Of Algorithm
EXAMPLE 1: MAXIMUM ELEMENTEXAMPLE 1: MAXIMUM ELEMENT
Sub: DESIGN & ANALYSIS OF ALGORITHM
Topic: Introduction,Analysis,Effieciency Of Algorithm
2-20Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2nd
ed., Ch. 2
REFERENCESREFERENCES
Books:-
1. Introduction to design & analysis of
algorithm
By Anany levitin, Pearson Publication
2. Design & Analysis of Algorithm
By A.A.Puntambekar , Technical Publication
3. Introduction to Algorithms
By Thomas Cormen , MIT Press
Web Resources:-
1.Google
2.Wikipedia
Analysis of Algorithms

More Related Content

What's hot (20)

PPT
Cis435 week01
ashish bansal
 
PDF
Design & Analysis of Algorithms Lecture Notes
FellowBuddy.com
 
PPT
Introduction to Algorithms
Venkatesh Iyer
 
PDF
Algorithm chapter 2
chidabdu
 
PDF
Algorithms Lecture 2: Analysis of Algorithms I
Mohamed Loey
 
PPT
Algorithm And analysis Lecture 03& 04-time complexity.
Tariq Khan
 
PPT
Fundamentals of the Analysis of Algorithm Efficiency
Saranya Natarajan
 
PDF
Daa notes 1
smruti sarangi
 
PPTX
Design and analysis of algorithms - Abstract View
Waqas Nawaz
 
PPTX
Complexity analysis in Algorithms
Daffodil International University
 
PPT
Data Structures and Algorithm Analysis
Mary Margarat
 
PDF
Design and analysis of computer algorithms
Krishna Chaytaniah
 
PDF
Design & Analysis Of Algorithm
Computer Hardware & Trouble shooting
 
PDF
A unique sorting algorithm with linear time &amp; space complexity
eSAT Journals
 
PPTX
Keynote at IWLS 2017
Manish Pandey
 
PDF
Daa notes 2
smruti sarangi
 
PDF
Introduction to Algorithms Complexity Analysis
Dr. Pankaj Agarwal
 
PDF
Theory of algorithms final
Dgech
 
PPTX
Daa unit 5
Abhimanyu Mishra
 
PDF
Keynote: Machine Learning for Design Automation at DAC 2018
Manish Pandey
 
Cis435 week01
ashish bansal
 
Design & Analysis of Algorithms Lecture Notes
FellowBuddy.com
 
Introduction to Algorithms
Venkatesh Iyer
 
Algorithm chapter 2
chidabdu
 
Algorithms Lecture 2: Analysis of Algorithms I
Mohamed Loey
 
Algorithm And analysis Lecture 03& 04-time complexity.
Tariq Khan
 
Fundamentals of the Analysis of Algorithm Efficiency
Saranya Natarajan
 
Daa notes 1
smruti sarangi
 
Design and analysis of algorithms - Abstract View
Waqas Nawaz
 
Complexity analysis in Algorithms
Daffodil International University
 
Data Structures and Algorithm Analysis
Mary Margarat
 
Design and analysis of computer algorithms
Krishna Chaytaniah
 
Design & Analysis Of Algorithm
Computer Hardware & Trouble shooting
 
A unique sorting algorithm with linear time &amp; space complexity
eSAT Journals
 
Keynote at IWLS 2017
Manish Pandey
 
Daa notes 2
smruti sarangi
 
Introduction to Algorithms Complexity Analysis
Dr. Pankaj Agarwal
 
Theory of algorithms final
Dgech
 
Daa unit 5
Abhimanyu Mishra
 
Keynote: Machine Learning for Design Automation at DAC 2018
Manish Pandey
 

Similar to Analysis of Algorithms (20)

PPTX
Data Structures - Lecture 1 [introduction]
Muhammad Hammad Waseem
 
PPTX
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...
AntareepMajumder
 
PPTX
AoA Lec Design of algorithm spresentation
HamzaSadaat
 
PPTX
Design and Analysis of Algorithms.pptx
Syed Zaid Irshad
 
PPT
Chapter1.1 Introduction to design and analysis of algorithm.ppt
Tekle12
 
PPT
Chapter1.1 Introduction.ppt
Tekle12
 
PPTX
Analysis of Algorithm full version 2024.pptx
rajesshs31r
 
PPTX
Design Analysis of Alogorithm 1 ppt 2024.pptx
rajesshs31r
 
PPTX
Algorithm description in data structures
ananya195642
 
PPTX
role of algo.pptx
AmirZaman21
 
PDF
Analysis of Algorithms
Amna Saeed
 
PPT
algorithm_lec_1eregdsgdfgdgdfgdfgdfg.ppt
partho5958
 
PPT
Algorithms
yashodhaHR2
 
PPT
lecture1.ppt
SagarDR5
 
PPT
C++ Notes PPT.ppt
Alpha474815
 
PDF
Design Analysis and Algorithm Module1.pdf
Shana799280
 
PDF
Slides [DAA] Unit 2 Ch 2.pdf
Vijayraj799513
 
PDF
Ch01
gurusodhii
 
PPTX
BCSE202Lkkljkljkbbbnbnghghjghghghghghghghgh
shivapatil54
 
Data Structures - Lecture 1 [introduction]
Muhammad Hammad Waseem
 
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...
AntareepMajumder
 
AoA Lec Design of algorithm spresentation
HamzaSadaat
 
Design and Analysis of Algorithms.pptx
Syed Zaid Irshad
 
Chapter1.1 Introduction to design and analysis of algorithm.ppt
Tekle12
 
Chapter1.1 Introduction.ppt
Tekle12
 
Analysis of Algorithm full version 2024.pptx
rajesshs31r
 
Design Analysis of Alogorithm 1 ppt 2024.pptx
rajesshs31r
 
Algorithm description in data structures
ananya195642
 
role of algo.pptx
AmirZaman21
 
Analysis of Algorithms
Amna Saeed
 
algorithm_lec_1eregdsgdfgdgdfgdfgdfg.ppt
partho5958
 
Algorithms
yashodhaHR2
 
lecture1.ppt
SagarDR5
 
C++ Notes PPT.ppt
Alpha474815
 
Design Analysis and Algorithm Module1.pdf
Shana799280
 
Slides [DAA] Unit 2 Ch 2.pdf
Vijayraj799513
 
BCSE202Lkkljkljkbbbnbnghghjghghghghghghghgh
shivapatil54
 
Ad

Recently uploaded (20)

PDF
Building Production-Ready AI Agents with LangGraph.pdf
Tamanna
 
PPTX
apidays Helsinki & North 2025 - From Chaos to Clarity: Designing (AI-Ready) A...
apidays
 
PPTX
apidays Singapore 2025 - Designing for Change, Julie Schiller (Google)
apidays
 
PDF
Copia de Strategic Roadmap Infographics by Slidesgo.pptx (1).pdf
ssuserd4c6911
 
PPTX
apidays Helsinki & North 2025 - Running a Successful API Program: Best Practi...
apidays
 
PPTX
apidays Helsinki & North 2025 - APIs at Scale: Designing for Alignment, Trust...
apidays
 
PDF
apidays Helsinki & North 2025 - APIs in the healthcare sector: hospitals inte...
apidays
 
PPTX
apidays Helsinki & North 2025 - Agentic AI: A Friend or Foe?, Merja Kajava (A...
apidays
 
PPTX
Numbers of a nation: how we estimate population statistics | Accessible slides
Office for National Statistics
 
PDF
Product Management in HealthTech (Case Studies from SnappDoctor)
Hamed Shams
 
PDF
R Cookbook - Processing and Manipulating Geological spatial data with R.pdf
OtnielSimopiaref2
 
PPTX
Climate Action.pptx action plan for climate
justfortalabat
 
PDF
List of all the AI prompt cheat codes.pdf
Avijit Kumar Roy
 
PPTX
ER_Model_with_Diagrams_Presentation.pptx
dharaadhvaryu1992
 
PPT
Data base management system Transactions.ppt
gandhamcharan2006
 
PPTX
b6057ea5-8e8c-4415-90c0-ed8e9666ffcd.pptx
Anees487379
 
PPTX
ER_Model_Relationship_in_DBMS_Presentation.pptx
dharaadhvaryu1992
 
PDF
apidays Helsinki & North 2025 - Monetizing AI APIs: The New API Economy, Alla...
apidays
 
PDF
WEF_Future_of_Global_Fintech_Second_Edition_2025.pdf
AproximacionAlFuturo
 
PDF
Early_Diabetes_Detection_using_Machine_L.pdf
maria879693
 
Building Production-Ready AI Agents with LangGraph.pdf
Tamanna
 
apidays Helsinki & North 2025 - From Chaos to Clarity: Designing (AI-Ready) A...
apidays
 
apidays Singapore 2025 - Designing for Change, Julie Schiller (Google)
apidays
 
Copia de Strategic Roadmap Infographics by Slidesgo.pptx (1).pdf
ssuserd4c6911
 
apidays Helsinki & North 2025 - Running a Successful API Program: Best Practi...
apidays
 
apidays Helsinki & North 2025 - APIs at Scale: Designing for Alignment, Trust...
apidays
 
apidays Helsinki & North 2025 - APIs in the healthcare sector: hospitals inte...
apidays
 
apidays Helsinki & North 2025 - Agentic AI: A Friend or Foe?, Merja Kajava (A...
apidays
 
Numbers of a nation: how we estimate population statistics | Accessible slides
Office for National Statistics
 
Product Management in HealthTech (Case Studies from SnappDoctor)
Hamed Shams
 
R Cookbook - Processing and Manipulating Geological spatial data with R.pdf
OtnielSimopiaref2
 
Climate Action.pptx action plan for climate
justfortalabat
 
List of all the AI prompt cheat codes.pdf
Avijit Kumar Roy
 
ER_Model_with_Diagrams_Presentation.pptx
dharaadhvaryu1992
 
Data base management system Transactions.ppt
gandhamcharan2006
 
b6057ea5-8e8c-4415-90c0-ed8e9666ffcd.pptx
Anees487379
 
ER_Model_Relationship_in_DBMS_Presentation.pptx
dharaadhvaryu1992
 
apidays Helsinki & North 2025 - Monetizing AI APIs: The New API Economy, Alla...
apidays
 
WEF_Future_of_Global_Fintech_Second_Edition_2025.pdf
AproximacionAlFuturo
 
Early_Diabetes_Detection_using_Machine_L.pdf
maria879693
 
Ad

Analysis of Algorithms

  • 1. 2-1Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2nd ed., Ch. 2 COMSATS INSTITUTE OFCOMSATS INSTITUTE OF INFORMATION & TECHNOLOGY,INFORMATION & TECHNOLOGY, VEHARIVEHARI Subject Code : CSC201 Subject Teacher : Sir Muhammad Afzal Name Of Subject : DESIGN & ANALYSIS OF ALGORITHMS Name of Unit : ANALYSIS OF ALGORITHMS Topic : Introduction, Analysis, Efficeincy of algorithms Name of Students : Mubariz Hamza Aslam (FA15-BCS-152) Muzamil Hayat Khan (FA15-BCS-080)
  • 2. 2-2Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2nd ed., Ch. 2 CONTENTSCONTENTS IINTRODUCTION TO ALGORITHMSNTRODUCTION TO ALGORITHMS ANALYSIS OF ALGORITHMANALYSIS OF ALGORITHM EFFIECIENCY OF ALGORITHMEFFIECIENCY OF ALGORITHM BEST CASEBEST CASE WORST CASEWORST CASE AVERAGE CASEAVERAGE CASE EXAMPLESEXAMPLES Sub: DESIGN & ANALYSIS OF ALGORITHM Topic: Introduction,Analysis,Effieciency Of Algorithm
  • 3. 2-3Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2nd ed., Ch. 2 INTRODUCTION OFINTRODUCTION OF ALGORITHMSALGORITHMS • An Algorithm is a Step by Step solution of aAn Algorithm is a Step by Step solution of a specific mathematical or computer relatedspecific mathematical or computer related problemproblem • There are different types of AlgorithmsThere are different types of Algorithms • GreedyGreedy • DynamicDynamic • Divide & Conquer ,etcDivide & Conquer ,etc • They can be expressed in different ways.They can be expressed in different ways. • Pseudo codePseudo code • By using simple English statements(Steps)By using simple English statements(Steps) Sub: DESIGN & ANALYSIS OF ALGORITHM Topic: Introduction,Analysis,Effieciency Of Algorithm
  • 4. 2-4Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2nd ed., Ch. 2 ANALYSIS OF ALGORITHMSANALYSIS OF ALGORITHMS • Issues:Issues: • correctnesscorrectness • time efficiencytime efficiency • space efficiencyspace efficiency • optimalityoptimality • Approaches:Approaches: • theoretical analysistheoretical analysis • empirical analysisempirical analysis Sub: DESIGN & ANALYSIS OF ALGORITHM Topic: Introduction,Analysis,Effieciency Of Algorithm
  • 5. THEORETICAL ANALYSIS OFTHEORETICAL ANALYSIS OF TIME EFFICIENCYTIME EFFICIENCY Time efficiency is analyzed by determining the number of repetitions of the basic operation as a function of input size • Basic operation: the operation that contributes most towards the running time of the algorithm T(n) ≈ copC(n)running time execution time for basic operation Number of times basic operation is executed input size Sub: DESIGN & ANALYSIS OF ALGORITHM Topic: Introduction,Analysis,Effieciency Of Algorithm
  • 6. INPUT SIZE AND BASIC OPERATIONINPUT SIZE AND BASIC OPERATION EXAMPLESEXAMPLES ProblemProblem Input size measureInput size measure Basic operationBasic operation Searching for keySearching for key in a list ofin a list of nn itemsitems Number of list’sNumber of list’s items, i.e.items, i.e. nn Key comparisonKey comparison Multiplication ofMultiplication of two matricestwo matrices Matrix dimensions orMatrix dimensions or total number oftotal number of elementselements Multiplication ofMultiplication of two numberstwo numbers Checking primalityChecking primality of a given integerof a given integer nn n’n’size = number ofsize = number of digits (in binarydigits (in binary representation)representation) DivisionDivision Typical graphTypical graph problemproblem #vertices and/or#vertices and/or edgesedges Visiting a vertexVisiting a vertex or traversing anor traversing an edgeedge Sub: DESIGN & ANALYSIS OF ALGORITHM Topic: Introduction,Analysis,Effieciency Of Algorithm
  • 7. EMPIRICAL ANALYSIS OF TIMEEMPIRICAL ANALYSIS OF TIME EFFICIENCYEFFICIENCY • Select a specific (typical) sample of inputsSelect a specific (typical) sample of inputs • Use physical unit of time (e.g., milliseconds)Use physical unit of time (e.g., milliseconds) oror Count actual number of basic operation’s executionsCount actual number of basic operation’s executions • Analyze the empirical dataAnalyze the empirical data Sub: DESIGN & ANALYSIS OF ALGORITHM Topic: Introduction,Analysis,Effieciency Of Algorithm
  • 8. BEST-CASE, AVERAGE-CASE,BEST-CASE, AVERAGE-CASE, WORST-CASEWORST-CASE For some algorithms efficiency depends on form ofFor some algorithms efficiency depends on form of input:input: • Worst case: CWorst case: Cworstworst((nn) – maximum over inputs of size) – maximum over inputs of size nn • Best case: CBest case: Cbestbest((nn) – minimum over inputs of size) – minimum over inputs of size nn • Average case: CAverage case: Cavgavg((nn) – “average” over inputs of size) – “average” over inputs of size nn • Number of times the basic operation will be executed on typical inputNumber of times the basic operation will be executed on typical input • NOT the average of worst and best caseNOT the average of worst and best case • Expected number of basic operations considered as a random variable underExpected number of basic operations considered as a random variable under some assumption about the probability distribution of all possible inputssome assumption about the probability distribution of all possible inputs Sub: DESIGN & ANALYSIS OF ALGORITHM Topic: Introduction,Analysis,Effieciency Of Algorithm
  • 9. EXAMPLE: SEQUENTIAL SEARCHEXAMPLE: SEQUENTIAL SEARCH • Worst caseWorst case • Best caseBest case • Average caseAverage caseSub: DESIGN & ANALYSIS OF ALGORITHM Topic: Introduction,Analysis,Effieciency Of Algorithm
  • 10. TYPES OF FORMULAS FOR BASICTYPES OF FORMULAS FOR BASIC OPERATION’S COUNTOPERATION’S COUNT • Exact formulaExact formula e.g., C(e.g., C(nn) =) = nn((nn-1)/2-1)/2 • Formula indicating order of growth with specificFormula indicating order of growth with specific multiplicative constantmultiplicative constant e.g., C(e.g., C(nn)) ≈≈ 0.50.5 nn22 • Formula indicating order of growth with unknownFormula indicating order of growth with unknown multiplicative constantmultiplicative constant e.g., C(e.g., C(nn)) ≈≈ cncn22 Sub: DESIGN & ANALYSIS OF ALGORITHM Topic: Introduction,Analysis,Effieciency Of Algorithm
  • 11. ORDER OF GROWTHORDER OF GROWTH • Most important: Order of growth within a constantMost important: Order of growth within a constant multiple asmultiple as nn ∞→∞→ • Example:Example: • How much faster will algorithm run on computer that is twice as fast?How much faster will algorithm run on computer that is twice as fast? • How much longer does it take to solve problem of double input size?How much longer does it take to solve problem of double input size? Sub: DESIGN & ANALYSIS OF ALGORITHM Topic: Introduction,Analysis,Effieciency Of Algorithm
  • 12. ASYMPTOTIC ORDER OFASYMPTOTIC ORDER OF GROWTHGROWTH A way of comparing functions that ignores constant factors andA way of comparing functions that ignores constant factors and small input sizessmall input sizes • O(O(gg((nn)): class of functions)): class of functions ff((nn) that grow) that grow no fasterno faster thanthan gg((nn)) • ΘΘ((gg((nn)): class of functions)): class of functions ff((nn) that grow) that grow at same rateat same rate asas gg((nn)) • ΩΩ((gg((nn)): class of functions)): class of functions ff((nn) that grow) that grow at least as fastat least as fast asas gg((nn)) Sub: DESIGN & ANALYSIS OF ALGORITHM Topic: Introduction,Analysis,Effieciency Of Algorithm
  • 13. BIG-OHBIG-OH Sub: DESIGN & ANALYSIS OF ALGORITHM Topic: Introduction,Analysis,Effieciency Of Algorithm
  • 14. BIG-OMEGABIG-OMEGA Sub: DESIGN & ANALYSIS OF ALGORITHM Topic: Introduction,Analysis,Effieciency Of Algorithm
  • 15. BIG-THETABIG-THETA Sub: DESIGN & ANALYSIS OF ALGORITHM Topic: Introduction,Analysis,Effieciency Of Algorithm
  • 16. ORDERS OF GROWTH OF SOMEORDERS OF GROWTH OF SOME IMPORTANT FUNCTIONSIMPORTANT FUNCTIONS • All logarithmic functions logAll logarithmic functions logaa nn belong to the same classbelong to the same class ΘΘ(log(log nn) no matter what the logarithm’s base) no matter what the logarithm’s base aa > 1 is> 1 is • All polynomials of the same degreeAll polynomials of the same degree kk belong to the samebelong to the same class:class: aakknnkk ++ aakk-1-1nnkk-1-1 + … ++ … + aa00 ∈∈ ΘΘ((nnkk )) • Exponential functionsExponential functions aann have different orders of growthhave different orders of growth for differentfor different aa’s’s • orderorder loglog n <n < orderorder nnαα ((αα>0) < order>0) < order aann < order< order nn! < order! < order nnnn Sub: DESIGN & ANALYSIS OF ALGORITHM Topic: Introduction,Analysis,Effieciency Of Algorithm
  • 17. BASIC ASYMPTOTIC EFFICIENCYBASIC ASYMPTOTIC EFFICIENCY CLASSESCLASSES 11 constantconstant loglog nn logarithmiclogarithmic nn linearlinear nn loglog nn n-n-loglog-n-n nn22 quadraticquadratic nn33 cubiccubic 22nn exponentialexponential nn!! factorialfactorial Sub: DESIGN & ANALYSIS OF ALGORITHM Topic: Introduction,Analysis,Effieciency Of Algorithm
  • 18. TIME EFFICIENCY OF NON-RECURSIVETIME EFFICIENCY OF NON-RECURSIVE ALGORITHMSALGORITHMS General Plan for AnalysisGeneral Plan for Analysis • Decide on parameterDecide on parameter nn indicatingindicating input sizeinput size • Identify algorithm’sIdentify algorithm’s basic operationbasic operation • DetermineDetermine worstworst,, averageaverage, and, and bestbest cases for input of sizecases for input of size nn • Set up a sum for the number of times the basic operation isSet up a sum for the number of times the basic operation is executedexecuted • Simplify the sum using standard formulas and rulesSimplify the sum using standard formulas and rules Sub: DESIGN & ANALYSIS OF ALGORITHM Topic: Introduction,Analysis,Effieciency Of Algorithm
  • 19. EXAMPLE 1: MAXIMUM ELEMENTEXAMPLE 1: MAXIMUM ELEMENT Sub: DESIGN & ANALYSIS OF ALGORITHM Topic: Introduction,Analysis,Effieciency Of Algorithm
  • 20. 2-20Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2nd ed., Ch. 2 REFERENCESREFERENCES Books:- 1. Introduction to design & analysis of algorithm By Anany levitin, Pearson Publication 2. Design & Analysis of Algorithm By A.A.Puntambekar , Technical Publication 3. Introduction to Algorithms By Thomas Cormen , MIT Press Web Resources:- 1.Google 2.Wikipedia

Editor's Notes

  • #12: Example: cn2 how much faster on twice as fast computer? (2) how much longer for 2n? (4)