Professional Documents
Culture Documents
Department of M.Tech-Cse: Course: Design and Analysis of Algorithms Module: Fundamentals of Algorithm Analysis
Department of M.Tech-Cse: Course: Design and Analysis of Algorithms Module: Fundamentals of Algorithm Analysis
DEPARTMENT OF M.TECH-CSE
04/07/2023 1
INTRODUCTION
04/07/2023 2
CONT…
04/07/2023 3
CONT…
04/07/2023 4
The Need for Analysis
04/07/2023 7
CONT…
04/07/2023 10
Algorithmic Cost and Complexity
There are two aspects of algorithmic performance:
• Time
• Instructions take time.
• How fast does the algorithm perform?
• What affects its runtime?
• Space
• Data structures take space
• What kind of data structures can be used?
• How does choice of data structure affect
the runtime?
04/07/2023 11
CONT…
04/07/2023 12
Analysis of Algorithms
ANALYSIS OF
ALGORITHMS
Measuring
Time Measuring
Complexity running
Computing time
Order of
Growth of
algorithms
04/07/2023 15
Time & Space Complexity
04/07/2023 16
Cont...(Analysis Framework)
04/07/2023 17
Cont...
Let
T(n) : running time
04/07/2023 18
Examples: Basic Operation
Problem Operation
Find x in an array Comparison of x with
an entry in the array
Multiplying two matrices Multiplication of two real
with real entries numbers
Sort an array of Comparison of two
numbers array entries plus
moving elements in the
array
Traverse a tree Traverse an edge
04/07/2023 19
The Analysis Framework
04/07/2023 20
Cont...(Analysis Framework)
Measuring Input Size:
• If the input size is larger, then usually algorithm
takes longer time.
• How to validate algorithm?
• Time efficiency: the number of repetitions of the
basic operation as a function of input size.
• Input size is influenced by
the data representation, e.g. matrix
the operations of the algorithm,
the properties of the objects in the problem.
e.g. checking if a given integer is a prime
number
04/07/2023 21
Examples
Problem Size of input
Find x in an array The number of the elements in
the array
Multiply two matrices The dimensions of the matrices
Sort an array The number of elements in the
array
Traverse a binary tree The number of nodes
Solve a system of The number of equations, or
linear equations the number of the unknowns,
or both
04/07/2023 22
Cont...(Analysis Framework)
Change in behaviour of the algorithm according to
input size is called Order of Growth.
04/07/2023 23
Computing Algorithmic Efficiencies
Each of these complexities defines a numerical
function: time versus size.
– The worst case complexity of the algorithm is
the function defined by the maximum
number of steps taken on any instance of
size n.
– The best case complexity of the algorithm is
the function defined by the minimum number
of steps taken on any instance of size n.
– The average-case complexity of the
algorithm is the function defined by an
average number of steps taken on any
instance of size n.
04/07/2023 24
04/07/2023 25
04/07/2023 26
04/07/2023 27