Unit - 1: Analysis of Algorithm

Download as pdf or txt
Download as pdf or txt
You are on page 1of 16

Unit – 1

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

• Now let’s manually find out the


proper no such that
• f(n) <= C*g(n)
Example – 3 Find upper bound of running time of
quadratic function f(n)=3n2+2n+4

So, C=4, g(n)=n2 and n0=1


Example – 4 Find upper bound of running time of
quadratic function f(n)=6n2+135
n+1 n
Example – 5 Is 2 = O(2 )? Explain
Example – 6 f(n)=3n+2 and g(n)=n
Find upper bound of running time of f(n). Can f(n) be bounded by g(n) though upper bound?
Or Can f(n)=O(g(n))?
Or Can f(n) is big oh of g(n)?

So, g(n) is bounding f(n) such that f(n)<=C*g(n)


Thank
You

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy