0% found this document useful (0 votes)
4 views17 pages

03 Algorithm Analysis

The document discusses algorithm analysis, focusing on the rate of growth of running time as a function of input size. It covers basic efficiency classes, types of analysis (best, average, and worst case), and asymptotic notations (O, Ω, Θ) used to describe algorithm performance. The document concludes with a mention of upcoming content on insertion sort.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views17 pages

03 Algorithm Analysis

The document discusses algorithm analysis, focusing on the rate of growth of running time as a function of input size. It covers basic efficiency classes, types of analysis (best, average, and worst case), and asymptotic notations (O, Ω, Θ) used to describe algorithm performance. The document concludes with a mention of upcoming content on insertion sort.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

D EPARTMENT OF C OMPUTER S CIENCE ,

FACULTY OF S CIENCE ,
S HARQ I NSTITUTE OF H IGHER E DUCATION

Algorithm Analysis

By: Abdul waris samadi


BY: ABDUL WARIS 1
O RDER OF G ROWTH (R ATE OF G ROWTH )
 Rate of Growth : -
The rate at which the running time increases as a function of input is called rate of
growth .
 Algorithm can be analyzed mathematically by functions.
 Example : input size = 10 , find the biggest value among the 10 number ,
obviously it will take some time and having comparison between 10 number .
 If input size =100 , what happened ?
 Or input size = 1000 …….
BY: ABDUL WARIS 2
E XAMPLE
Y
Running time

Number of input
BY: ABDUL WARIS 3
E XAMPLE
Y

2n+1 3n
Running time

3n
1 0
2n+1 3 3
5 6
X 7 9

Number of input
BY: ABDUL WARIS 4
E XAMPLE

 F(n) = n4+2n2+100n+500
 F(n) = n4 for some n > n0

BY: ABDUL WARIS 5


B ASIC EFFICIENCY CLASSES

1 constant
log n logarithmic
n linear
n log n n-log-n
n2 quadratic
n3 cubic
2n exponential

BY: ABDUL WARIS


n! factorial 6
E XAMPLE

BY: ABDUL WARIS 7


T YPES OF ANALYSIS

 To analyze the given algorithm , we need to know on what inputs the algorithm is taking
less time and on what inputs the algorithm is taking huge time .

 Worst case
 Average case
 Best case

BY: ABDUL WARIS 8


B EST, AVERAGE , AND WORST C ASE A NALYSIS
 Best Case Analysis :
It takes minimum time to execute.
 The best-case running time of an algorithm is a lower bound on the running time for
any input.
 Times taken if the best possible thing happens.
 It gives us a guarantee that the algorithm will never take any less time than time in
best case.

BY: ABDUL WARIS 9


B EST, AVERAGE , AND WORST C ASE A NALYSIS
 Average Case Analysis
 It takes average time to execute.
 T(n) is the average time taken over all inputs of size n.
 Average case time is often difficult to determine.

BY: ABDUL WARIS 10


B EST, AVERAGE , AND WORST C ASE A NALYSIS
 Worst Case Analysis
 It takes maximum time to execute .
 The worst-case running time of an algorithm is an upper bound on the running time
for any input.
 It gives us a guarantee that the algorithm will never take any longer.
 For some algorithms, the worst case occurs fairly often.

BY: ABDUL WARIS 11


A SYMPTOTIC N OTATIONS
 Asymptotic Notations are used to describe the running time of an algorithm.
 For all three cases we need to identify the upper bound and lower bounds.
 Asymptotic notations:
 O-Notation (big oh notation)
 -Notation (omega notation)
 -Notation (theta notation)

BY: ABDUL WARIS 12


A SYMPTOTIC N OTATIONS
 O-Notation (big oh notation)
 The O-Notation asymptotically bounds a function from above and below.
 Big O notation, is used to describe upper bound of the time, and space usage of an
algorithm.
 For a given function g(n), we denote by O(g(n) )the set of functions:
 O(g(n) )={ f(n): there exist positive constants c and n0 such that
0  f(n)  c g(n) for all n  n0 }
 We say that g(n) is asymptotically upper bound for f(n).

BY: ABDUL WARIS 13


A SYMPTOTIC N OTATIONS
 -Notation (omega notation)
 Just as O-notation provides an asymptotic upper bound on a function, -notation
provides an asymptotic lower bound.
 For a given function g(n), we denote by (g(n) )the set of functions:
 (g(n) )={ f(n): there exist positive constants c and n0 such that

0  c g(n)  f(n) for all n  n0 }


 We say that g(n) is asymptotically lower bound for f(n).

BY: ABDUL WARIS 14


A SYMPTOTIC N OTATIONS
 -Notation (theta notation)
 For a given function g(n), we denote by (g(n) )the set of functions:
 (g(n) )={ f(n): there exist positive constants c1, c2, and n0 such that
0  c1 g(n)  f(n)  c2 g(n) for all n  n0 }
 We say that g(n) is asymptotically tight bound for f(n).

BY: ABDUL WARIS 15


N EXT…

 Insertion sort
 Introduction
 Algorithm
 Analysis
 Run time calculation

BY: ABDUL WARIS 16


T HE E ND

BY: ABDUL WARIS 17

You might also like