Session 3
Session 3
Session -3
Asymptotic notations
1
Asymptotic efficiency
• To compare two algorithms with running times f(n) and g(n), we need a
rough measure that characterizes how fast each function grows as n
grows.
i.e., we say that n2 + 100n + log10n + 1000 and n2 have the same rate of growth
– f(n) = 10n2+4n+2
• 10n2+4n+2 <= 11n2, for all n >= 5, 10n2+4n+2 = (n2)
• Although n3 is an upper bound for 10n2+4n+2, it is not a tight upper bound; we can
find a smaller function (n2) that satisfies big oh relation.
• But, we can not write 10n2+4n+2 =O(n), since it does not satisfy the big oh relation
for sufficiently large input.
• Omega () notation:
– The omega notation describes a lower bound on the asymptotic growth
rate of the function f.
Definition: [Omega]
– f(n) = (g(n)) (read as “f of n is omega of g of
n”) iff there exist positive constants c and n0
such that f(n) cg(n) for all n,
n n0.
• The definition states that the function f(n) is at least c times the function g(n) except when n is
smaller than n0.
• In other words,f(n) grows faster than or same rate as” g(n).
• Examples
– f(n) = 3n+2
• 3n + 2 >= 3n, for all n >= 1, 3n + 2 = (n)
– f(n) = 10n2+4n+2
• 10n2+4n+2 >= n2, for all n >= 1, 10n2+4n+2 = (n2)
• It also possible to write 10n2+4n+2 = (n) since 10n2+4n+2 >=n for n>=0
• Although n is a lower bound for 10n2+4n+2, it is not a tight lower bound; we can find a larger
function (n2) that satisfies omega relation.
• But, we can not write 10n2+4n+2 = (n3), since it does not satisfy the omega relation for sufficiently
large input.
• Theta () notation:
– The Theta notation describes a tight bound on the asymptotic
growth rate of the function f.
Definition: [Theta]
– f(n) = (g(n)) (read as “f of n is theta of g of n”) iff there
exist positive constants c1, c2, and n0 such that c1g(n) f(n)
c2g(n) for all n, n n0.
• The definition states that the function f(n) lies between c1 times the function g(n) and c2 times the
function g(n) except when n is smaller than n0.
• In other words,f(n) grows same rate as” g(n).
• Examples:-
– f(n) = 3n+2
• 3n <= 3n + 2 <= 4n, for all n >= 2, 3n + 2 = (n)
– f(n) = 10n2+4n+2
• n2<= 10n2+4n+2 <= 11n2, for all n >= 5, 10n2+4n+2 = (n2)
• But, we can not write either 10n2+4n+2= (n) or 10n2+4n+2= (n3), since neither of these will satisfy
the theta relation.
Big-Oh, Theta, Omega
Tips :
• Think of O(g(n)) as “less than or equal to” g(n)
– Upper bound: “grows slower than or same rate as” g(n)
20