Unit - 1: Analysis of Algorithm
Unit - 1: Analysis of Algorithm
Unit - 1: Analysis of Algorithm
Analysis of Algorithm
PREPARED BY:
RACHANA R. BUCH
Aymptotic Notations
• To choose best algorithm we need to check the efficiency of each algorithm.
• Efficiency can be measured by computing complexity of each algorithm.
• Complexity can be represented by asymptotic notations.
• Using asymptotic notations we can give time complexity as “fastest possible”,
“slowest possible” or “average time”.
Continue…
• Notations which are used to represent algorithm is known as asymptotic
notations.
• There are mainly 3 notations are used:
• Big oh (O)
• Big omega (Ω / W)
• Big theta (Θ)
Big oh (O) Notation
• The “Big oh” notation is denoted by ‘O’ (Capital ‘O’).
• This is a method of representing the upper bound of an algorithm’s running
time.
• It denotes largest amount of time taken by an algorithm to complete. (worst
case)
Definition
• Let f(n) and g(n) be two non negative functions.
• Let n0 and constant C are two integers such that n0 denotes some value of input
and n0 <=n, n0 >=1.
• Similarly C is some constant such that C>0 and
• F(n)<=C*g(n), then g(n) is upper bound of f(n).
• It can be denoted as f(n)=Og(n)
Note…
•Actually g(n) is not a single function but it’s a set of
functions which always grow faster than f(n) for
every n>=n0
Examples -1
• n2 grows slowly than n3
• n2 is Big oh of n3 n3 is upper bound of n2
Example – 2 Find upper bound of running time of
constant function f(n) = 6993
• Any value of C which is greater than
6993, satisfies the given inequalities,
so all such values of C are possible.
• Here f(n) =6993 which is a constant
value, that doesn’t depend on problem
size n, so, n0=1
• F(n) = O(g(n)) = O(1)
• For C = 6993 and n0=1
Example -3 Find upper bound of running time of linear
function f(n) = 6n+3
Continue…
• Other solution using tabular
approach
• 0<=f(n)<= c*g(n)
• 0<= 6n+3 <=7n