Algorithm Complexity Analysis
Algorithm Complexity Analysis
COMPLEXITY
ANALYSIS
Time Complexity (Contd)
Determining an estimate of the time and
memory requirement of the algorithm.
Time estimation is called time complexity
analysis
Memory size estimation is called space
complexity analysis.
Because memory is cheap and abundant, we
rarely do space complexity analysis
Since time is “expensive” , analysis now
defaults to time complexity analysis
Asymptotic Notation
Determining exact step count of a program is a very
difficult task
This is why , step count is not used for comparing
programs.
We determine the rate of growth of a function
If , we have two programs with the complexity of c1n2+c2n
and c3n.
Then c3n will always be faster for sufficiently large values
of n.
If c1=1 , c2=2 and c3=100 , then
c1n2+c2n <= c3n for n<=98
c1n2+c2n > c3n for n>98
There will always be the value of n beyond which , the
program with complexity c3n will always be faster than
program with complexity c1n2+c2n.
This value of n will be called the break-even point.
If the break even point is zero , than program with complexity
c3n will always be faster.
The exact break even point can not be determined
analytically.
The programs have to be run on a computer in order to
determine the break even point.
BIG O NOTATION
Definition
“f(n)=O(g(n)) read as f(n) is of order g(n) iff there
exist positive constants c and M such that
f(n)<=Mg(n) for all , n>=c.”
The statement f(n)=O(g(n)) merely states that
70
60
50 O(2n)
O(n2)
40
O(logn)
30
O(nlogn)
20 O(n)
10
0
1 3 5 7 9