Daa Unit-1 PPT-3
Daa Unit-1 PPT-3
What is an Algorithm
Algorithm Specification, Pseudo code Conventions
Recursive Algorithm
Performance Analysis
Space Complexity, Time Complexity
Amortized Complexity
Asymptotic Notation
Practical Complexities, Performance Measurement.
2
TIME COMPLEXITY AND SPACE COMPLEXITY
1. Time Complexity
2. Space Complexity
3
Space Complexity
Def: Space complexity of an algorithm represents the amount
of memory space required by the algorithm in its life cycle.
Space complexity S(P) of any algorithm
P is
S(P) = C + SP(I)
where C is the fixed part and
S(I) is the variable part of the algorithm, which depends
on instance characteristic I
Then
S(P)=C+Sp
Where
C is the Fixed Space
where as
Sp is the Variable Space (Space may Vary )
5
Space Complexity-Example
Algorithm Sum(A, n) //algorithm heading part requires zero units of
space
{ //Open brace requires zero units of space
S:=0; //Variable S requires One unit of space
for i=1 to n // Variable i, n requires one Unit of space
each
s=s+a[i]; //array a[i] requires n units of space
return s; //Variable S requires one unit of space
} // Close brace requires Zero units of space
Space Complexity of an algorithm is S(P)=C+Sp
T(n)=C+Rp
Where as
Time Complexity=T(n)
Compile Time=C
Runtime=Rp
7
Time Complexity-Example 1
Definition:
Let f(n) define running time of an
algorithm
The function f(n)=O(g(n)) if and only if,
there exist all positive constants C and n 0,
such that f(n)<=C*g(n) for all, n>= n0 12
Asymptotic Notations: Omega- Ω Notation
Definition:
Let f(n) define running time of an
algorithm
The function f(n)= Ω(g(n)) if and only if,
there exist all positive constants C and n 0,
such that f(n)>=C*g(n) for all, n>= n0
13
Asymptotic Notations: Theta- Θ Notation
1. Θ notation represents the average
bound of the running time of an
algorithm.
Definition:
Let f(n) define running time of an
algorithm
The function f(n)= Θ(g(n)) if and only if,
there exist all positive constants C 1 and
IfCa2 function
andf(n) lies
n0anywhere
, in such
between c1that
g(n) and c2g(n) for all n ≥ n0,
then f(n) is said to be asymptotically tight bound. 14
C1*g(n)<=f(n)<=C2*g(n) for all, n>= n0
Asymptotic Notations: Definitions
15
THANK YOU
16