SlideShare ist ein Scribd-Unternehmen logo
1 von 37
Parul Institute of Engineering & Technology
Subject Code : 150703
Name Of Subject : DESIGN & ANALYSIS OF ALGORITHM
Name of Unit : ANALYSIS OF ALGORITHM
Topic : Introduction,Analysis,Efficeincy of algorithm
Name of Student: Agrawal Swapnil
CONTENTS
INTRODUCTION TO ALGORITHMS
ANALYSIS OF ALGORITHM
EFFIECIENCY OF ALGORITHM
BEST CASE
WORST CASE
AVERAGE CASE
EXAMPLES
Sub: DESIGN & ANALYSIS OF ALGORITHM
Topic: Introduction,Analysis,Effieciency Of Algorithm
Introduction of algorithms
• An Algorithm is a Step by Step solution of a specific
mathematical or computer related problem
• There are different types of Algorithms
– Greedy
– Dynamic
– Divide & Conquer ,etc
• They can be expressed in different ways.
– Pseudocode
– By using simple English statements(Steps)
Sub: DESIGN & ANALYSIS OF ALGORITHM
Topic: Introduction,Analysis,Effieciency Of Algorithm
Analysis of algorithms
• Issues:
– correctness
– time efficiency
– space efficiency
– optimality
• Approaches:
– theoretical analysis
– empirical analysis
Sub: DESIGN & ANALYSIS OF ALGORITHM
Topic: Introduction,Analysis,Effieciency Of Algorithm
Theoretical analysis of time 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 operation examples
ProblemProblem Input size measureInput size measure Basic operationBasic operation
Searching for key in aSearching for key in a
list oflist of nn itemsitems
Number of list’s items, i.e.Number of list’s items, i.e.
nn
Key comparisonKey comparison
Multiplication of twoMultiplication of two
matricesmatrices
Matrix dimensions or totalMatrix dimensions or total
number of elementsnumber of elements
Multiplication of twoMultiplication of two
numbersnumbers
Checking primality of aChecking primality of a
given integergiven integer nn
n’n’size = number of digitssize = number of digits
(in binary representation)(in binary representation)
DivisionDivision
Typical graph problemTypical graph problem #vertices and/or edges#vertices and/or edges
Visiting a vertex orVisiting a vertex or
traversing an edgetraversing an edge
Sub: DESIGN & ANALYSIS OF ALGORITHM
Topic: Introduction,Analysis,Effieciency Of Algorithm
Empirical analysis of time
efficiency
• Select a specific (typical) sample of inputs
• Use physical unit of time (e.g., milliseconds)
or
Count actual number of basic operation’s
executions
• Analyze the empirical data
Sub: DESIGN & ANALYSIS OF ALGORITHM
Topic: Introduction,Analysis,Effieciency Of Algorithm
Best-case, average-case, worst-case
For some algorithms efficiency depends on form of input:
• Worst case: Cworst(n) – maximum over inputs of size n
• Best case: Cbest(n) – minimum over inputs of size n
• Average case: Cavg(n) – “average” over inputs of size n
– Number of times the basic operation will be executed
on typical input
– NOT the average of worst and best case
– Expected number of basic operations considered as a
random variable under some assumption about the
probability distribution of all possible inputs
Sub: DESIGN & ANALYSIS OF ALGORITHM
Topic: Introduction,Analysis,Effieciency Of Algorithm
Example: Sequential search
• Worst case
• Best case
• Average case
Sub: DESIGN & ANALYSIS OF ALGORITHM
Topic: Introduction,Analysis,Effieciency Of Algorithm
Types of formulas for basic operation’s count
• Exact formula
e.g., C(n) = n(n-1)/2
• Formula indicating order of growth with specific
multiplicative constant
e.g., C(n) ≈ 0.5 n2
• Formula indicating order of growth with unknown
multiplicative constant
e.g., C(n) ≈ cn2
Sub: DESIGN & ANALYSIS OF ALGORITHM
Topic: Introduction,Analysis,Effieciency Of Algorithm
Order of growth
• Most important: Order of growth within a constant
multiple as n→∞
• Example:
– 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?
Sub: DESIGN & ANALYSIS OF ALGORITHM
Topic: Introduction,Analysis,Effieciency Of Algorithm
Values of some important functions as n → ∞
Sub: DESIGN & ANALYSIS OF ALGORITHM
Topic: Introduction,Analysis,Effieciency Of Algorithm
Asymptotic order of growth
A way of comparing functions that ignores constant factors
and small input sizes
• O(g(n)): class of functions f(n) that grow no faster than
g(n)
• Θ(g(n)): class of functions f(n) that grow at same rate as
g(n)
• Ω(g(n)): class of functions f(n) that grow at least as fast
as g(n)
Sub: DESIGN & ANALYSIS OF ALGORITHM
Topic: Introduction,Analysis,Effieciency Of Algorithm
Big-oh
Sub: DESIGN & ANALYSIS OF ALGORITHM
Topic: Introduction,Analysis,Effieciency Of Algorithm
Big-omega
Sub: DESIGN & ANALYSIS OF ALGORITHM
Topic: Introduction,Analysis,Effieciency Of Algorithm
Big-theta
Sub: DESIGN & ANALYSIS OF ALGORITHM
Topic: Introduction,Analysis,Effieciency Of Algorithm
Establishing order of growth using
the definition
Definition: f(n) is in O(g(n)) if order of growth of f(n) ≤
order of growth of g(n) (within constant multiple),
i.e., there exist positive constant c and non-negative
integer n0 such that
f(n) ≤ c g(n) for every n ≥ n0
Examples:
• 10n is O(n2
)
• 5n+20 is O(n)
Sub: DESIGN & ANALYSIS OF ALGORITHM
Topic: Introduction,Analysis,Effieciency Of Algorithm
Some properties of asymptotic order of growth
• f(n) ∈ O(f(n))
• f(n) ∈ O(g(n)) iff g(n) ∈Ω(f(n))
• If f(n) ∈ O(g(n)) and g(n) ∈ O(h(n)) , then f(n) ∈
O(h(n))
Note similarity with a ≤ b
• If f1(n) ∈ O(g1(n)) and f2(n) ∈ O(g2(n)) , then
f1(n) + f2(n) ∈ O(max{g1(n), g2(n)})
Sub: DESIGN & ANALYSIS OF ALGORITHM
Topic: Introduction,Analysis,Effieciency Of Algorithm
Establishing order of growth using limits
limT(n)/g(n) =
00 order of growth of TT((n)n) < order of growth of gg((nn))
cc > 0> 0 order of growth of TT((n)n) = order of growth of gg((nn))
∞∞ order of growth of TT((n)n) > order of growth of gg((nn))
Examples:Examples:
• 1010nn vs.vs. nn22
• nn((nn+1)/2 vs.+1)/2 vs. nn22
nn→∞→∞
Sub: DESIGN & ANALYSIS OF ALGORITHM
Topic: Introduction,Analysis,Effieciency Of Algorithm
L’Hôpital’s rule and Stirling’s formula
L’Hôpital’s rule: If limn→∞f(n) = limn→∞g(n) = ∞ and
the derivatives f´, g´ exist, then
Stirling’s formula: n! ≈ (2πn)1/2
(n/e)n
ff((nn))
gg((nn))
limlim
nn→∞→∞
=
ff ´(´(nn))
gg ´(´(nn))
limlim
nn→∞→∞
Example: logExample: log nn vs.vs. nn
Example: 2Example: 2nn
vs.vs. nn!!
Sub: DESIGN & ANALYSIS OF ALGORITHM
Topic: Introduction,Analysis,Effieciency Of Algorithm
Orders of growth of some important functions
• All logarithmic functions logan belong to the same class
Θ(log n) no matter what the logarithm’s base a > 1 is
• All polynomials of the same degree k belong to the same
class: aknk
+ ak-1nk-1
+ … + a0∈ Θ(nk
)
• Exponential functions an
have different orders of growth
for different a’s
• order log n < order nα
(Îą>0) < order an
< order n! <
order nn
Sub: DESIGN & ANALYSIS OF ALGORITHM
Topic: Introduction,Analysis,Effieciency Of Algorithm
Basic asymptotic efficiency classes
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 nonrecursive
algorithms
General Plan for Analysis
• Decide on parameter n indicating input size
• Identify algorithm’s basic operation
• Determine worst, average, and best cases for input of
size n
• Set up a sum for the number of times the basic
operation is executed
• Simplify the sum using standard formulas and rules
Sub: DESIGN & ANALYSIS OF ALGORITHM
Topic: Introduction,Analysis,Effieciency Of Algorithm
Useful summation formulas and rules
• Σl≤i≤u1 = 1+1+…+1 = u - l + 1
• In particular, Σl≤i≤u1 = n - 1 + 1 = n ∈ Θ(n)
• Σ1≤i≤ni = 1+2+…+n = n(n+1)/2 ≈ n2
/2 ∈ Θ(n2
)
• Σ1≤i≤ni2
= 12
+22
+…+n2
= n(n+1)(2n+1)/6 ≈ n3
/3 ∈ Θ(n3
)
• Σ0≤i≤nai
= 1+ a +…+ an
= (an+1
- 1)/(a - 1) for any a ≠ 1
• In particular, Σ0≤i≤n2i
= 20
+ 21
+…+ 2n
= 2n+1
- 1 ∈ Θ(2n
)
• Σ(ai± bi) = Σai± Σbi
• Σcai = cΣai
• Σl≤i≤uai = Σl≤i≤mai+ Σm+1≤i≤uai
Sub: DESIGN & ANALYSIS OF ALGORITHM
Topic: Introduction,Analysis,Effieciency Of Algorithm
Example 1: Maximum element
Sub: DESIGN & ANALYSIS OF ALGORITHM
Topic: Introduction,Analysis,Effieciency Of Algorithm
Example 2: Element uniqueness
problem
Sub: DESIGN & ANALYSIS OF ALGORITHM
Topic: Introduction,Analysis,Effieciency Of Algorithm
Example 3: Matrix multiplication
Sub: DESIGN & ANALYSIS OF ALGORITHM
Topic: Introduction,Analysis,Effieciency Of Algorithm
Example 4: Gaussian elimination
Algorithm GaussianElimination(A[0..n-1,0..n])
//Implements Gaussian elimination of an n-by-(n+1)
matrix A
for i ← 0 to n - 2 do
for j ← i + 1 to n - 1 do
for k ← i to n do
A[j,k] ← A[j,k] - A[i,k] ∗ A[j,i] / A[i,i]
Find the efficiency class and a constant factor
improvement.
Sub: DESIGN & ANALYSIS OF ALGORITHM
Topic: Introduction,Analysis,Effieciency Of Algorithm
Example 5: Counting binary digits
It cannot be investigated the way the previous
examples are.
Sub: DESIGN & ANALYSIS OF ALGORITHM
Topic: Introduction,Analysis,Effieciency Of Algorithm
Plan for Analysis of Recursive
Algorithms
• Decide on a parameter indicating an input’s size.
• Identify the algorithm’s basic operation.
• Check whether the number of times the basic op. is
executed may vary on different inputs of the same size.
(If it may, the worst, average, and best cases must be
investigated separately.)
• Set up a recurrence relation with an appropriate initial
condition expressing the number of times the basic op.
is executed.
• Solve the recurrence (or, at the very least, establish its
solution’s order of growth) by backward substitutions
or another method.
Sub: DESIGN & ANALYSIS OF ALGORITHM
Topic: Introduction,Analysis,Effieciency Of Algorithm
Example 1: Recursive evaluation of n!
Definition: n ! = 1 ∗ 2 ∗ … ∗(n-1) ∗ n for n ≥ 1
and 0! = 1
Recursive definition of n!: F(n) = F(n-1) ∗ n for n ≥ 1
and F(0) = 1
Sub: DESIGN & ANALYSIS OF ALGORITHM
Topic: Introduction,Analysis,Effieciency Of Algorithm
Example 2: Counting #bits
Sub: DESIGN & ANALYSIS OF ALGORITHM
Topic: Introduction,Analysis,Effieciency Of Algorithm
Fibonacci numbers
 The Fibonacci numbers:
0, 1, 1, 2, 3, 5, 8, 13, 21, …
 The Fibonacci recurrence:
F(n) = F(n-1) + F(n-2)
F(0) = 0
F(1) = 1
 General 2nd
order linear homogeneous recurrence
with constant coefficients:
 aX(n) + bX(n-1) + cX(n-2) = 0
Sub: DESIGN & ANALYSIS OF ALGORITHM
Topic: Introduction,Analysis,Effieciency Of Algorithm
Solving aX(n) + bX(n-1) + cX(n-2) = 0
• Set up the characteristic equation (quadratic)
ar2
+ br + c = 0
• Solve to obtain roots r1 and r2
• General solution to the recurrence
if r1and r2 are two distinct real roots: X(n) = Îąr1
n
+ βr2
n
if r1=r2= r are two equal real roots: X(n) = Îąrn
+ βnrn
• Particular solution can be found by using initial
conditions
Sub: DESIGN & ANALYSIS OF ALGORITHM
Topic: Introduction,Analysis,Effieciency Of Algorithm
Application to the Fibonacci
numbers
F(n) = F(n-1) + F(n-2) or F(n) - F(n-1) - F(n-2) = 0
Characteristic equation:
Roots of the characteristic equation:
General solution to the recurrence:
Particular solution for F(0) =0, F(1)=1:
Sub: DESIGN & ANALYSIS OF ALGORITHM
Topic: Introduction,Analysis,Effieciency Of Algorithm
Computing Fibonacci numbers
1. Definition-based recursive algorithm
2. Non recursive definition-based algorithm
3. Explicit formula algorithm
4. Logarithmic algorithm based on formula:
FF((nn-1)-1) FF((nn))
FF((nn)) FF((nn+1)+1)
0 10 1
1 11 1
==
nn
forfor nn≥≥1,1, assuming an efficient way of computing matrix powersassuming an efficient way of computing matrix powers..
Sub: DESIGN & ANALYSIS OF ALGORITHM
Topic: Introduction,Analysis,Effieciency Of Algorithm
REFERENCES
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

Weitere ähnliche Inhalte

Was ist angesagt?

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
 
Divide and Conquer - Part 1
Divide and Conquer - Part 1Divide and Conquer - Part 1
Divide and Conquer - Part 1Amrinder Arora
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithmsGanesh Solanke
 
Analysis of algorithm
Analysis of algorithmAnalysis of algorithm
Analysis of algorithmRajendra Dangwal
 
Analysis and Design of Algorithms
Analysis and Design of AlgorithmsAnalysis and Design of Algorithms
Analysis and Design of AlgorithmsBulbul Agrawal
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notationsNikhil Sharma
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notationsEhtisham Ali
 
Design and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptxDesign and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptxSyed Zaid Irshad
 
Algorithm analysis (All in one)
Algorithm analysis (All in one)Algorithm analysis (All in one)
Algorithm analysis (All in one)jehan1987
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysissumitbardhan
 
Algorithms Lecture 7: Graph Algorithms
Algorithms Lecture 7: Graph AlgorithmsAlgorithms Lecture 7: Graph Algorithms
Algorithms Lecture 7: Graph AlgorithmsMohamed Loey
 
Complexity of Algorithm
Complexity of AlgorithmComplexity of Algorithm
Complexity of AlgorithmMuhammad Muzammal
 
chapter 1
chapter 1chapter 1
chapter 1yatheesha
 
Greedy Algorithms
Greedy AlgorithmsGreedy Algorithms
Greedy AlgorithmsAmrinder Arora
 

Was ist angesagt? (20)

Daa unit 1
Daa unit 1Daa unit 1
Daa unit 1
 
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
 
Divide and Conquer - Part 1
Divide and Conquer - Part 1Divide and Conquer - Part 1
Divide and Conquer - Part 1
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithms
 
Analysis of algorithm
Analysis of algorithmAnalysis of algorithm
Analysis of algorithm
 
Unit 1 chapter 1 Design and Analysis of Algorithms
Unit 1   chapter 1 Design and Analysis of AlgorithmsUnit 1   chapter 1 Design and Analysis of Algorithms
Unit 1 chapter 1 Design and Analysis of Algorithms
 
Analysis and Design of Algorithms
Analysis and Design of AlgorithmsAnalysis and Design of Algorithms
Analysis and Design of Algorithms
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
Design and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptxDesign and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptx
 
Algorithm analysis (All in one)
Algorithm analysis (All in one)Algorithm analysis (All in one)
Algorithm analysis (All in one)
 
Daa notes 1
Daa notes 1Daa notes 1
Daa notes 1
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysis
 
Algorithms Lecture 7: Graph Algorithms
Algorithms Lecture 7: Graph AlgorithmsAlgorithms Lecture 7: Graph Algorithms
Algorithms Lecture 7: Graph Algorithms
 
Complexity of Algorithm
Complexity of AlgorithmComplexity of Algorithm
Complexity of Algorithm
 
Graph coloring problem
Graph coloring problemGraph coloring problem
Graph coloring problem
 
Backtracking
BacktrackingBacktracking
Backtracking
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
 
chapter 1
chapter 1chapter 1
chapter 1
 
Greedy Algorithms
Greedy AlgorithmsGreedy Algorithms
Greedy Algorithms
 

Andere mochten auch

Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of AlgorithmsArvind Krishnaa
 
Algorithm Analysis and Design Class Notes
Algorithm Analysis and Design Class NotesAlgorithm Analysis and Design Class Notes
Algorithm Analysis and Design Class NotesKumar Avinash
 
ADA complete notes
ADA complete notesADA complete notes
ADA complete notesVinay Kumar C
 
Introduction to Algorithms
Introduction to AlgorithmsIntroduction to Algorithms
Introduction to AlgorithmsVenkatesh Iyer
 
Time and space complexity
Time and space complexityTime and space complexity
Time and space complexityAnkit Katiyar
 
Cs6402 design and analysis of algorithms may june 2016 answer key
Cs6402 design and analysis of algorithms may june 2016 answer keyCs6402 design and analysis of algorithms may june 2016 answer key
Cs6402 design and analysis of algorithms may june 2016 answer keyappasami
 
Algorithms and Flowcharts
Algorithms and FlowchartsAlgorithms and Flowcharts
Algorithms and FlowchartsDeva Singh
 
design and analysis of algorithm
design and analysis of algorithmdesign and analysis of algorithm
design and analysis of algorithmMuhammad Arish
 
Design and analysis of algorithms - Abstract View
Design and analysis of algorithms - Abstract ViewDesign and analysis of algorithms - Abstract View
Design and analysis of algorithms - Abstract ViewWaqas Nawaz
 
Cs6402 design and analysis of algorithms impartant part b questions appasami
Cs6402 design and analysis of algorithms  impartant part b questions appasamiCs6402 design and analysis of algorithms  impartant part b questions appasami
Cs6402 design and analysis of algorithms impartant part b questions appasamiappasami
 
CS 6402 – DESIGN AND ANALYSIS OF ALGORITHMS questio
CS 6402 – DESIGN AND ANALYSIS OF ALGORITHMS questioCS 6402 – DESIGN AND ANALYSIS OF ALGORITHMS questio
CS 6402 – DESIGN AND ANALYSIS OF ALGORITHMS questioKarthik Venkatachalam
 
how to calclute time complexity of algortihm
how to calclute time complexity of algortihmhow to calclute time complexity of algortihm
how to calclute time complexity of algortihmSajid Marwat
 
Our presentation on algorithm design
Our presentation on algorithm designOur presentation on algorithm design
Our presentation on algorithm designNahid Hasan
 
The Travelling Salesman Problem
The Travelling Salesman ProblemThe Travelling Salesman Problem
The Travelling Salesman Problemguest3d82c4
 
VTU 4TH SEM CSE MICROPROCESSORS SOLVED PAPERS OF JUNE-2014 & JUNE-2015
VTU 4TH SEM CSE MICROPROCESSORS SOLVED PAPERS OF JUNE-2014 & JUNE-2015VTU 4TH SEM CSE MICROPROCESSORS SOLVED PAPERS OF JUNE-2014 & JUNE-2015
VTU 4TH SEM CSE MICROPROCESSORS SOLVED PAPERS OF JUNE-2014 & JUNE-2015vtunotesbysree
 

Andere mochten auch (18)

Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of Algorithms
 
Design & Analysis Of Algorithm
Design & Analysis Of AlgorithmDesign & Analysis Of Algorithm
Design & Analysis Of Algorithm
 
Algorithm Analysis and Design Class Notes
Algorithm Analysis and Design Class NotesAlgorithm Analysis and Design Class Notes
Algorithm Analysis and Design Class Notes
 
ADA complete notes
ADA complete notesADA complete notes
ADA complete notes
 
DESIGN AND ANALYSIS OF ALGORITHM (DAA)
DESIGN AND ANALYSIS OF ALGORITHM (DAA)DESIGN AND ANALYSIS OF ALGORITHM (DAA)
DESIGN AND ANALYSIS OF ALGORITHM (DAA)
 
Introduction to Algorithms
Introduction to AlgorithmsIntroduction to Algorithms
Introduction to Algorithms
 
Time and space complexity
Time and space complexityTime and space complexity
Time and space complexity
 
Analysis of Algorithm
Analysis of AlgorithmAnalysis of Algorithm
Analysis of Algorithm
 
Cs6402 design and analysis of algorithms may june 2016 answer key
Cs6402 design and analysis of algorithms may june 2016 answer keyCs6402 design and analysis of algorithms may june 2016 answer key
Cs6402 design and analysis of algorithms may june 2016 answer key
 
Algorithms and Flowcharts
Algorithms and FlowchartsAlgorithms and Flowcharts
Algorithms and Flowcharts
 
design and analysis of algorithm
design and analysis of algorithmdesign and analysis of algorithm
design and analysis of algorithm
 
Design and analysis of algorithms - Abstract View
Design and analysis of algorithms - Abstract ViewDesign and analysis of algorithms - Abstract View
Design and analysis of algorithms - Abstract View
 
Cs6402 design and analysis of algorithms impartant part b questions appasami
Cs6402 design and analysis of algorithms  impartant part b questions appasamiCs6402 design and analysis of algorithms  impartant part b questions appasami
Cs6402 design and analysis of algorithms impartant part b questions appasami
 
CS 6402 – DESIGN AND ANALYSIS OF ALGORITHMS questio
CS 6402 – DESIGN AND ANALYSIS OF ALGORITHMS questioCS 6402 – DESIGN AND ANALYSIS OF ALGORITHMS questio
CS 6402 – DESIGN AND ANALYSIS OF ALGORITHMS questio
 
how to calclute time complexity of algortihm
how to calclute time complexity of algortihmhow to calclute time complexity of algortihm
how to calclute time complexity of algortihm
 
Our presentation on algorithm design
Our presentation on algorithm designOur presentation on algorithm design
Our presentation on algorithm design
 
The Travelling Salesman Problem
The Travelling Salesman ProblemThe Travelling Salesman Problem
The Travelling Salesman Problem
 
VTU 4TH SEM CSE MICROPROCESSORS SOLVED PAPERS OF JUNE-2014 & JUNE-2015
VTU 4TH SEM CSE MICROPROCESSORS SOLVED PAPERS OF JUNE-2014 & JUNE-2015VTU 4TH SEM CSE MICROPROCESSORS SOLVED PAPERS OF JUNE-2014 & JUNE-2015
VTU 4TH SEM CSE MICROPROCESSORS SOLVED PAPERS OF JUNE-2014 & JUNE-2015
 

Ähnlich wie Design and Analysis of Algorithms

Algorithms
Algorithms Algorithms
Algorithms yashodhaHR2
 
Algorithm
AlgorithmAlgorithm
AlgorithmSyam Kumar
 
C++ Notes PPT.ppt
C++ Notes PPT.pptC++ Notes PPT.ppt
C++ Notes PPT.pptAlpha474815
 
lecture1.ppt
lecture1.pptlecture1.ppt
lecture1.pptSagarDR5
 
Analysis of Algorithm full version 2024.pptx
Analysis of Algorithm  full version  2024.pptxAnalysis of Algorithm  full version  2024.pptx
Analysis of Algorithm full version 2024.pptxrajesshs31r
 
Design Analysis of Alogorithm 1 ppt 2024.pptx
Design Analysis of Alogorithm 1 ppt 2024.pptxDesign Analysis of Alogorithm 1 ppt 2024.pptx
Design Analysis of Alogorithm 1 ppt 2024.pptxrajesshs31r
 
Data Structures - Lecture 1 [introduction]
Data Structures - Lecture 1 [introduction]Data Structures - Lecture 1 [introduction]
Data Structures - Lecture 1 [introduction]Muhammad Hammad Waseem
 
asymptotic analysis and insertion sort analysis
asymptotic analysis and insertion sort analysisasymptotic analysis and insertion sort analysis
asymptotic analysis and insertion sort analysisAnindita Kundu
 
DS Unit-1.pptx very easy to understand..
DS Unit-1.pptx very easy to understand..DS Unit-1.pptx very easy to understand..
DS Unit-1.pptx very easy to understand..KarthikeyaLanka1
 
a581a6a2cb5778045788f0b1d7da1c0236f.pptx
a581a6a2cb5778045788f0b1d7da1c0236f.pptxa581a6a2cb5778045788f0b1d7da1c0236f.pptx
a581a6a2cb5778045788f0b1d7da1c0236f.pptxchristinamary2620
 
Algorithm in Computer, Sorting and Notations
Algorithm in Computer, Sorting  and NotationsAlgorithm in Computer, Sorting  and Notations
Algorithm in Computer, Sorting and NotationsAbid Kohistani
 
2 chapter2 algorithm_analysispart1
2 chapter2 algorithm_analysispart12 chapter2 algorithm_analysispart1
2 chapter2 algorithm_analysispart1SSE_AndyLi
 
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...AntareepMajumder
 
2. Asymptotic Notations and Complexity Analysis.pptx
2. Asymptotic Notations and Complexity Analysis.pptx2. Asymptotic Notations and Complexity Analysis.pptx
2. Asymptotic Notations and Complexity Analysis.pptxRams715121
 
02 order of growth
02 order of growth02 order of growth
02 order of growthHira Gul
 
Asymptotics 140510003721-phpapp02
Asymptotics 140510003721-phpapp02Asymptotics 140510003721-phpapp02
Asymptotics 140510003721-phpapp02mansab MIRZA
 

Ähnlich wie Design and Analysis of Algorithms (20)

Analysis of Algorithms
Analysis of AlgorithmsAnalysis of Algorithms
Analysis of Algorithms
 
Algorithms
Algorithms Algorithms
Algorithms
 
Algorithm
AlgorithmAlgorithm
Algorithm
 
Algorithm
AlgorithmAlgorithm
Algorithm
 
C++ Notes PPT.ppt
C++ Notes PPT.pptC++ Notes PPT.ppt
C++ Notes PPT.ppt
 
lecture1.ppt
lecture1.pptlecture1.ppt
lecture1.ppt
 
Analysis of Algorithm full version 2024.pptx
Analysis of Algorithm  full version  2024.pptxAnalysis of Algorithm  full version  2024.pptx
Analysis of Algorithm full version 2024.pptx
 
Design Analysis of Alogorithm 1 ppt 2024.pptx
Design Analysis of Alogorithm 1 ppt 2024.pptxDesign Analysis of Alogorithm 1 ppt 2024.pptx
Design Analysis of Alogorithm 1 ppt 2024.pptx
 
Data Structures - Lecture 1 [introduction]
Data Structures - Lecture 1 [introduction]Data Structures - Lecture 1 [introduction]
Data Structures - Lecture 1 [introduction]
 
Chapter two
Chapter twoChapter two
Chapter two
 
asymptotic analysis and insertion sort analysis
asymptotic analysis and insertion sort analysisasymptotic analysis and insertion sort analysis
asymptotic analysis and insertion sort analysis
 
DS Unit-1.pptx very easy to understand..
DS Unit-1.pptx very easy to understand..DS Unit-1.pptx very easy to understand..
DS Unit-1.pptx very easy to understand..
 
a581a6a2cb5778045788f0b1d7da1c0236f.pptx
a581a6a2cb5778045788f0b1d7da1c0236f.pptxa581a6a2cb5778045788f0b1d7da1c0236f.pptx
a581a6a2cb5778045788f0b1d7da1c0236f.pptx
 
Algorithm in Computer, Sorting and Notations
Algorithm in Computer, Sorting  and NotationsAlgorithm in Computer, Sorting  and Notations
Algorithm in Computer, Sorting and Notations
 
2 chapter2 algorithm_analysispart1
2 chapter2 algorithm_analysispart12 chapter2 algorithm_analysispart1
2 chapter2 algorithm_analysispart1
 
Lec1
Lec1Lec1
Lec1
 
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...
 
2. Asymptotic Notations and Complexity Analysis.pptx
2. Asymptotic Notations and Complexity Analysis.pptx2. Asymptotic Notations and Complexity Analysis.pptx
2. Asymptotic Notations and Complexity Analysis.pptx
 
02 order of growth
02 order of growth02 order of growth
02 order of growth
 
Asymptotics 140510003721-phpapp02
Asymptotics 140510003721-phpapp02Asymptotics 140510003721-phpapp02
Asymptotics 140510003721-phpapp02
 

KĂźrzlich hochgeladen

Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvLewisJB
 
home automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasadhome automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasadaditya806802
 
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...Amil Baba Dawood bangali
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substationstephanwindworld
 
Industrial Safety Unit-IV workplace health and safety.ppt
Industrial Safety Unit-IV workplace health and safety.pptIndustrial Safety Unit-IV workplace health and safety.ppt
Industrial Safety Unit-IV workplace health and safety.pptNarmatha D
 
Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...121011101441
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptSAURABHKUMAR892774
 
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgUnit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgsaravananr517913
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...Chandu841456
 
Industrial Safety Unit-I SAFETY TERMINOLOGIES
Industrial Safety Unit-I SAFETY TERMINOLOGIESIndustrial Safety Unit-I SAFETY TERMINOLOGIES
Industrial Safety Unit-I SAFETY TERMINOLOGIESNarmatha D
 
Steel Structures - Building technology.pptx
Steel Structures - Building technology.pptxSteel Structures - Building technology.pptx
Steel Structures - Building technology.pptxNikhil Raut
 
Energy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptxEnergy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptxsiddharthjain2303
 
Internet of things -Arshdeep Bahga .pptx
Internet of things -Arshdeep Bahga .pptxInternet of things -Arshdeep Bahga .pptx
Internet of things -Arshdeep Bahga .pptxVelmuruganTECE
 
US Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionUS Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionMebane Rash
 
TechTACÂŽ CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTACÂŽ CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTACÂŽ CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTACÂŽ CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catcherssdickerson1
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 

KĂźrzlich hochgeladen (20)

Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvv
 
home automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasadhome automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasad
 
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substation
 
Industrial Safety Unit-IV workplace health and safety.ppt
Industrial Safety Unit-IV workplace health and safety.pptIndustrial Safety Unit-IV workplace health and safety.ppt
Industrial Safety Unit-IV workplace health and safety.ppt
 
Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.ppt
 
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgUnit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...
 
Industrial Safety Unit-I SAFETY TERMINOLOGIES
Industrial Safety Unit-I SAFETY TERMINOLOGIESIndustrial Safety Unit-I SAFETY TERMINOLOGIES
Industrial Safety Unit-I SAFETY TERMINOLOGIES
 
Steel Structures - Building technology.pptx
Steel Structures - Building technology.pptxSteel Structures - Building technology.pptx
Steel Structures - Building technology.pptx
 
Energy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptxEnergy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptx
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Internet of things -Arshdeep Bahga .pptx
Internet of things -Arshdeep Bahga .pptxInternet of things -Arshdeep Bahga .pptx
Internet of things -Arshdeep Bahga .pptx
 
US Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionUS Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of Action
 
TechTACÂŽ CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTACÂŽ CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTACÂŽ CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTACÂŽ CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 

Design and Analysis of Algorithms

  • 1. Parul Institute of Engineering & Technology Subject Code : 150703 Name Of Subject : DESIGN & ANALYSIS OF ALGORITHM Name of Unit : ANALYSIS OF ALGORITHM Topic : Introduction,Analysis,Efficeincy of algorithm Name of Student: Agrawal Swapnil
  • 2. CONTENTS INTRODUCTION TO ALGORITHMS ANALYSIS OF ALGORITHM EFFIECIENCY OF ALGORITHM BEST CASE WORST CASE AVERAGE CASE EXAMPLES Sub: DESIGN & ANALYSIS OF ALGORITHM Topic: Introduction,Analysis,Effieciency Of Algorithm
  • 3. Introduction of algorithms • An Algorithm is a Step by Step solution of a specific mathematical or computer related problem • There are different types of Algorithms – Greedy – Dynamic – Divide & Conquer ,etc • They can be expressed in different ways. – Pseudocode – By using simple English statements(Steps) Sub: DESIGN & ANALYSIS OF ALGORITHM Topic: Introduction,Analysis,Effieciency Of Algorithm
  • 4. Analysis of algorithms • Issues: – correctness – time efficiency – space efficiency – optimality • Approaches: – theoretical analysis – empirical analysis Sub: DESIGN & ANALYSIS OF ALGORITHM Topic: Introduction,Analysis,Effieciency Of Algorithm
  • 5. Theoretical analysis of time 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 operation examples ProblemProblem Input size measureInput size measure Basic operationBasic operation Searching for key in aSearching for key in a list oflist of nn itemsitems Number of list’s items, i.e.Number of list’s items, i.e. nn Key comparisonKey comparison Multiplication of twoMultiplication of two matricesmatrices Matrix dimensions or totalMatrix dimensions or total number of elementsnumber of elements Multiplication of twoMultiplication of two numbersnumbers Checking primality of aChecking primality of a given integergiven integer nn n’n’size = number of digitssize = number of digits (in binary representation)(in binary representation) DivisionDivision Typical graph problemTypical graph problem #vertices and/or edges#vertices and/or edges Visiting a vertex orVisiting a vertex or traversing an edgetraversing an edge Sub: DESIGN & ANALYSIS OF ALGORITHM Topic: Introduction,Analysis,Effieciency Of Algorithm
  • 7. Empirical analysis of time efficiency • Select a specific (typical) sample of inputs • Use physical unit of time (e.g., milliseconds) or Count actual number of basic operation’s executions • Analyze the empirical data Sub: DESIGN & ANALYSIS OF ALGORITHM Topic: Introduction,Analysis,Effieciency Of Algorithm
  • 8. Best-case, average-case, worst-case For some algorithms efficiency depends on form of input: • Worst case: Cworst(n) – maximum over inputs of size n • Best case: Cbest(n) – minimum over inputs of size n • Average case: Cavg(n) – “average” over inputs of size n – Number of times the basic operation will be executed on typical input – NOT the average of worst and best case – Expected number of basic operations considered as a random variable under some assumption about the probability distribution of all possible inputs Sub: DESIGN & ANALYSIS OF ALGORITHM Topic: Introduction,Analysis,Effieciency Of Algorithm
  • 9. Example: Sequential search • Worst case • Best case • Average case Sub: DESIGN & ANALYSIS OF ALGORITHM Topic: Introduction,Analysis,Effieciency Of Algorithm
  • 10. Types of formulas for basic operation’s count • Exact formula e.g., C(n) = n(n-1)/2 • Formula indicating order of growth with specific multiplicative constant e.g., C(n) ≈ 0.5 n2 • Formula indicating order of growth with unknown multiplicative constant e.g., C(n) ≈ cn2 Sub: DESIGN & ANALYSIS OF ALGORITHM Topic: Introduction,Analysis,Effieciency Of Algorithm
  • 11. Order of growth • Most important: Order of growth within a constant multiple as n→∞ • Example: – 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? Sub: DESIGN & ANALYSIS OF ALGORITHM Topic: Introduction,Analysis,Effieciency Of Algorithm
  • 12. Values of some important functions as n → ∞ Sub: DESIGN & ANALYSIS OF ALGORITHM Topic: Introduction,Analysis,Effieciency Of Algorithm
  • 13. Asymptotic order of growth A way of comparing functions that ignores constant factors and small input sizes • O(g(n)): class of functions f(n) that grow no faster than g(n) • Θ(g(n)): class of functions f(n) that grow at same rate as g(n) • Ί(g(n)): class of functions f(n) that grow at least as fast as g(n) Sub: DESIGN & ANALYSIS OF ALGORITHM Topic: Introduction,Analysis,Effieciency Of Algorithm
  • 14. Big-oh Sub: DESIGN & ANALYSIS OF ALGORITHM Topic: Introduction,Analysis,Effieciency Of Algorithm
  • 15. Big-omega Sub: DESIGN & ANALYSIS OF ALGORITHM Topic: Introduction,Analysis,Effieciency Of Algorithm
  • 16. Big-theta Sub: DESIGN & ANALYSIS OF ALGORITHM Topic: Introduction,Analysis,Effieciency Of Algorithm
  • 17. Establishing order of growth using the definition Definition: f(n) is in O(g(n)) if order of growth of f(n) ≤ order of growth of g(n) (within constant multiple), i.e., there exist positive constant c and non-negative integer n0 such that f(n) ≤ c g(n) for every n ≥ n0 Examples: • 10n is O(n2 ) • 5n+20 is O(n) Sub: DESIGN & ANALYSIS OF ALGORITHM Topic: Introduction,Analysis,Effieciency Of Algorithm
  • 18. Some properties of asymptotic order of growth • f(n) ∈ O(f(n)) • f(n) ∈ O(g(n)) iff g(n) ∈Ω(f(n)) • If f(n) ∈ O(g(n)) and g(n) ∈ O(h(n)) , then f(n) ∈ O(h(n)) Note similarity with a ≤ b • If f1(n) ∈ O(g1(n)) and f2(n) ∈ O(g2(n)) , then f1(n) + f2(n) ∈ O(max{g1(n), g2(n)}) Sub: DESIGN & ANALYSIS OF ALGORITHM Topic: Introduction,Analysis,Effieciency Of Algorithm
  • 19. Establishing order of growth using limits limT(n)/g(n) = 00 order of growth of TT((n)n) < order of growth of gg((nn)) cc > 0> 0 order of growth of TT((n)n) = order of growth of gg((nn)) ∞∞ order of growth of TT((n)n) > order of growth of gg((nn)) Examples:Examples: • 1010nn vs.vs. nn22 • nn((nn+1)/2 vs.+1)/2 vs. nn22 nn→∞→∞ Sub: DESIGN & ANALYSIS OF ALGORITHM Topic: Introduction,Analysis,Effieciency Of Algorithm
  • 20. L’HĂ´pital’s rule and Stirling’s formula L’HĂ´pital’s rule: If limn→∞f(n) = limn→∞g(n) = ∞ and the derivatives f´, g´ exist, then Stirling’s formula: n! ≈ (2πn)1/2 (n/e)n ff((nn)) gg((nn)) limlim nn→∞→∞ = ff ´(´(nn)) gg ´(´(nn)) limlim nn→∞→∞ Example: logExample: log nn vs.vs. nn Example: 2Example: 2nn vs.vs. nn!! Sub: DESIGN & ANALYSIS OF ALGORITHM Topic: Introduction,Analysis,Effieciency Of Algorithm
  • 21. Orders of growth of some important functions • All logarithmic functions logan belong to the same class Θ(log n) no matter what the logarithm’s base a > 1 is • All polynomials of the same degree k belong to the same class: aknk + ak-1nk-1 + … + a0∈ Θ(nk ) • Exponential functions an have different orders of growth for different a’s • order log n < order nÎą (Îą>0) < order an < order n! < order nn Sub: DESIGN & ANALYSIS OF ALGORITHM Topic: Introduction,Analysis,Effieciency Of Algorithm
  • 22. Basic asymptotic efficiency classes 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
  • 23. Time efficiency of nonrecursive algorithms General Plan for Analysis • Decide on parameter n indicating input size • Identify algorithm’s basic operation • Determine worst, average, and best cases for input of size n • Set up a sum for the number of times the basic operation is executed • Simplify the sum using standard formulas and rules Sub: DESIGN & ANALYSIS OF ALGORITHM Topic: Introduction,Analysis,Effieciency Of Algorithm
  • 24. Useful summation formulas and rules • ÎŁl≤i≤u1 = 1+1+…+1 = u - l + 1 • In particular, ÎŁl≤i≤u1 = n - 1 + 1 = n ∈ Θ(n) • ÎŁ1≤i≤ni = 1+2+…+n = n(n+1)/2 ≈ n2 /2 ∈ Θ(n2 ) • ÎŁ1≤i≤ni2 = 12 +22 +…+n2 = n(n+1)(2n+1)/6 ≈ n3 /3 ∈ Θ(n3 ) • ÎŁ0≤i≤nai = 1+ a +…+ an = (an+1 - 1)/(a - 1) for any a ≠ 1 • In particular, ÎŁ0≤i≤n2i = 20 + 21 +…+ 2n = 2n+1 - 1 ∈ Θ(2n ) • ÎŁ(aiÂą bi) = ÎŁaiÂą ÎŁbi • ÎŁcai = cÎŁai • ÎŁl≤i≤uai = ÎŁl≤i≤mai+ ÎŁm+1≤i≤uai Sub: DESIGN & ANALYSIS OF ALGORITHM Topic: Introduction,Analysis,Effieciency Of Algorithm
  • 25. Example 1: Maximum element Sub: DESIGN & ANALYSIS OF ALGORITHM Topic: Introduction,Analysis,Effieciency Of Algorithm
  • 26. Example 2: Element uniqueness problem Sub: DESIGN & ANALYSIS OF ALGORITHM Topic: Introduction,Analysis,Effieciency Of Algorithm
  • 27. Example 3: Matrix multiplication Sub: DESIGN & ANALYSIS OF ALGORITHM Topic: Introduction,Analysis,Effieciency Of Algorithm
  • 28. Example 4: Gaussian elimination Algorithm GaussianElimination(A[0..n-1,0..n]) //Implements Gaussian elimination of an n-by-(n+1) matrix A for i ← 0 to n - 2 do for j ← i + 1 to n - 1 do for k ← i to n do A[j,k] ← A[j,k] - A[i,k] ∗ A[j,i] / A[i,i] Find the efficiency class and a constant factor improvement. Sub: DESIGN & ANALYSIS OF ALGORITHM Topic: Introduction,Analysis,Effieciency Of Algorithm
  • 29. Example 5: Counting binary digits It cannot be investigated the way the previous examples are. Sub: DESIGN & ANALYSIS OF ALGORITHM Topic: Introduction,Analysis,Effieciency Of Algorithm
  • 30. Plan for Analysis of Recursive Algorithms • Decide on a parameter indicating an input’s size. • Identify the algorithm’s basic operation. • Check whether the number of times the basic op. is executed may vary on different inputs of the same size. (If it may, the worst, average, and best cases must be investigated separately.) • Set up a recurrence relation with an appropriate initial condition expressing the number of times the basic op. is executed. • Solve the recurrence (or, at the very least, establish its solution’s order of growth) by backward substitutions or another method. Sub: DESIGN & ANALYSIS OF ALGORITHM Topic: Introduction,Analysis,Effieciency Of Algorithm
  • 31. Example 1: Recursive evaluation of n! Definition: n ! = 1 ∗ 2 ∗ … ∗(n-1) ∗ n for n ≥ 1 and 0! = 1 Recursive definition of n!: F(n) = F(n-1) ∗ n for n ≥ 1 and F(0) = 1 Sub: DESIGN & ANALYSIS OF ALGORITHM Topic: Introduction,Analysis,Effieciency Of Algorithm
  • 32. Example 2: Counting #bits Sub: DESIGN & ANALYSIS OF ALGORITHM Topic: Introduction,Analysis,Effieciency Of Algorithm
  • 33. Fibonacci numbers  The Fibonacci numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, …  The Fibonacci recurrence: F(n) = F(n-1) + F(n-2) F(0) = 0 F(1) = 1  General 2nd order linear homogeneous recurrence with constant coefficients:  aX(n) + bX(n-1) + cX(n-2) = 0 Sub: DESIGN & ANALYSIS OF ALGORITHM Topic: Introduction,Analysis,Effieciency Of Algorithm
  • 34. Solving aX(n) + bX(n-1) + cX(n-2) = 0 • Set up the characteristic equation (quadratic) ar2 + br + c = 0 • Solve to obtain roots r1 and r2 • General solution to the recurrence if r1and r2 are two distinct real roots: X(n) = Îąr1 n + βr2 n if r1=r2= r are two equal real roots: X(n) = Îąrn + βnrn • Particular solution can be found by using initial conditions Sub: DESIGN & ANALYSIS OF ALGORITHM Topic: Introduction,Analysis,Effieciency Of Algorithm
  • 35. Application to the Fibonacci numbers F(n) = F(n-1) + F(n-2) or F(n) - F(n-1) - F(n-2) = 0 Characteristic equation: Roots of the characteristic equation: General solution to the recurrence: Particular solution for F(0) =0, F(1)=1: Sub: DESIGN & ANALYSIS OF ALGORITHM Topic: Introduction,Analysis,Effieciency Of Algorithm
  • 36. Computing Fibonacci numbers 1. Definition-based recursive algorithm 2. Non recursive definition-based algorithm 3. Explicit formula algorithm 4. Logarithmic algorithm based on formula: FF((nn-1)-1) FF((nn)) FF((nn)) FF((nn+1)+1) 0 10 1 1 11 1 == nn forfor nn≥≥1,1, assuming an efficient way of computing matrix powersassuming an efficient way of computing matrix powers.. Sub: DESIGN & ANALYSIS OF ALGORITHM Topic: Introduction,Analysis,Effieciency Of Algorithm
  • 37. REFERENCES 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

Hinweis der Redaktion

  1. Example: cn2 how much faster on twice as fast computer? (2) how much longer for 2n? (4)