Lecture 03 Asymptotic Analysis
Lecture 03 Asymptotic Analysis
Asymptotic Notations
7
A Posterior Analysis
• This is an empirical analysis of an algorithm.
• The selected algorithm is implemented using
programming language.
• This is then executed on target computer machine.
• In this analysis, actual statistics like running time
and space required, are collected.
• Dependent on particular hardware.
• It gives exact value.
8
Execution Time Cases
• An algorithm may not have the same performance
for different types of inputs.
• With the increase in the input size, the performance will
change.
• Cases which are usually used to compare various
data structure's execution time in a relative
manner.
• Worst Case
• Average Case
• Best Case
Analysis of Time
Complexity
• Running time depends on many factors but we
compute it based on input size.
• Thus we need to calculate rate of increase in time
w.r.t input.
• Assumption:
• All arithmetical & logical operations take = 1 unit of time
• All return statements also take = 1 unit of time
Analysis of Time
Complexity
• Example of Constant Time
4n + 5 f(n)
f(n) = 4n + 5
g(n) = n , O(n)
f (n) <= c. g(n)
c. g(n) = 9n
n0 = 1
n>= n0
Big oh Notation (Ο)
5n2+2n+1 f(n)
f(n) = 5n2+2n+1
g(n) = n2 , O(n2)
f (n) <= c. g(n)
c. g(n) = 8n2
n0 = 1
n>= n0
Omega Notation (Ω-
notation)
• Omega notation represents the lower
bound of the running time of an
algorithm.
• It provides the best case complexity of an
algorithm.
Omega Notation
5n2+2n+1 f(n)
f(n) = 5n2+2+1
g(n) = n2 , O(n2)
f (n) >= c. g(n)
c. g(n) = 5n2
n0 = 1
n>= n0
Ω(g(n)) = { f(n): there exist positive constants c and n such that 0 ≤ cg(n)
0
≤ f(n)
for all n ≥ n }
Theta Notation (θ-
notation)
• Theta notation encloses the function from
above and below.
• It represents the upper and the lower
bound of the running time of an
algorithm.
• It is used for analyzing the average-case
complexity of an algorithm.
Theta Notation
(g(n)) = { f(n): there exist positive constants c1, c2 and n0 such that 0 ≤ c1g(n) ≤ f(n) ≤ c2g(n
for all n ≥ n0 }