PPT on Analysis Of Algorithms.
The ppt includes Algorithms,notations,analysis,analysis of algorithms,theta notation, big oh notation, omega notation, notation graphs
1. Presented By: Presented To:
Rajendra Dangwal Mr. Yogesh Jain
CS Branch Lecturer
(IV Sem) CS Deptt.
2. Algorithm
• Algorithm is step by step procedure to solve
any problem.
Analyzing / Judgment of the Algorithm
• An algorithm can be written in different ways
for solving a single problem.
• So by analyzing the algorithms we can find the
best solution (algorithm) to the problem.
3. Order of Growth
• Any algorithm is expected to work fast for any
input size.
• For smaller input size our algorithm will work fine
but for higher input size the execution time is
much higher
• By increasing the size of n (input size) we can
analyze how well our algorithm works.
4. • Let input size, n=5 and we have to sort the list of
elements for e.g. 25,29,10,15,2
• So for n=5 our algorithm will work fine but what
if n=5000?
• So our algorithm will take much longer time to
sort the elements
or cause small delays to give the result
• So how the behaviour of algorithm changes with
the no. of inputs will give the analysis of the
algorithm and is called the Order of Growth.
5. • For calculating the order of growth we have to
go for higher value of n, because
i. as the input size grow higher algorithm
makes delays.
ii. for all real time applications we have higher
values for n.
6. Efficiencies of the Algorithm
There are three cases
i. Best case
ii. Worst case
iii. Average case
• Let we have 5 nos.(n=5) 25,31,42,71,105 and
we have to find any element in the list.
7. Best case efficiency
• let we have to find 25 in List =>25,31,42,71,105
• k=25
• 25 is present at the first position
• Since only single comparison is made to search
the element so we say that it is best case
efficiency
• CBest (n)=1
8. Worst case efficiency
• If we want to search the element which is present at
the last of the list or not present at all in the list then
such cases are called the worst case efficiency.
• let we have to find 105 in List =>25,31,42,71,105
• k=105
• Therefore we have to make 5 (=n) comparisons to
search the element
• CWorst (n)=n
• And if we have to find 110
• k=110
• Since the element is not in the list even then we have
to make 5 (=n) comparisons to search the element
• CWorst (n)=n
9. Average case efficiency
• Let the element is not present at the first or the
last position
• Let it is present somewhere in middle of the list
• We know that probability of a successful search =
p where 0≤p≤1.
• And probability of unsuccessful search = 1-p
10. • Let the element we are searching for is present at
position 'i' in the list
• Therefore probability of the element to be found
is given by p/n.
• Therefore CAvg (n)
=[1*p/n + 2*p/n + ... + i*p/n + ... + n*p/n] + n(1-p)
=p/n[1+2+...+i+...+n] + n(1-p)
=p/n[n*(n+1)/2] + n(1-p)
=p[(n+1)/2] + n(1-p)
I II
11. • case 1. If element is available
therefore p=1 (for successful search)
Now substituting p=1 in above eqn
• CAvg (n) = 1[(n+1)/2] + n(1-1)
= (n+1)/2
• case 2. If element is unavailable
therefore p=0 (for unsuccessful search)
Now substituting p=0 in above eqn
• CAvg (n) = 0[(n+1)/2] + n(1-0)
= n
Therefore on average half of list will be searched to find
the element in the list
12. Operations in Order of Growth
• i.Big 'O‘ (Oh)
• ii.Big Ω (Omega)
• iii.Big θ (Theta)
• Consider an algorithm representing two
functions f(n) and g(n)
13. Big O
• It represents the maximum time that the
algorithm takes for its execution.
g(n)
f(n)
• Growth rate of f(n) is not more than growth
rate of g(n).
• f(n)≤O[g(n)]
Time
No. of inputs
14. Big Ω
• It represents the minimum time that the
algorithm takes for its execution.
f(n)
g(n)
• Growth rate of f(n) is not less than growth rate
of g(n).
• f(n)≥ Ω[g(n)]
Time
No. of inputs
15. Big θ
• It represents the average time an algorithm takes for its
execution.
C1.g(n)
f(n)
C2.g(n)
• Let C1*g(n) and C2*g(n) are two constant multiples of g(n)
• f(n) is bound above and below by two constant multiples of
g(n). f(n)<=O[g(n)]
Time
No. of inputs
16. • The growth rate of f(n) will not be less than
the growth rate of C2*g(n) and not more than
c1*g(n).
• C2*g(n)<=f(n)<=C1*g(n)