You are on page 1of 22

Asymptotic Notations

A LG O R I T H M D E I G N A N D A N A LY S I S

PREAPARED BY: ABDUL JALIL NIAZAI


Asymptotic Notations
 As, we already know that the running time of an algorithm is represented in the form
function.
 Asymptotic notations are used to represent the upper and lower bound of the given
function.
 Or showing the class of a function.

 We have three types of notations:

 Big-O notation: Represent the upper bound.


 Omega Notation: Represent the lower bound.
 Theta: Represent the average bound.

PREAPARED BY: ABDUL JALIL NIAZAI


Asymptotic Notations
Big-O Notation (Upper Bounding Function)
 This notation gives the tight upper bound of the
given function. Generally, it is represented as
f(n) = O(g(n)).
 That means, at larger values of n, the upper
bound of f(n) is g(n).

 For example, if f(n) = n4 + 100n2 + 10n + 50 is


the given algorithm, then n4 is g(n). That means
g(n) gives the maximum rate of growth for f(n)
at larger values of n.

PREAPARED BY: ABDUL JALIL NIAZAI


Asymptotic Notations
Big-O Notation (Upper Bounding Function)
 Let us see the O–notation with a little more detail.

O–notation defined as function of f(n) = O(g(n)) iff ꓱ +ve constant C and n0


such that f(n)<= C * g(n) ꓯ n >= n0

PREAPARED BY: ABDUL JALIL NIAZAI


Asymptotic Notations
Big-O Examples:
Example-1 Find upper bound for f(n) = 3n + 8
Solution: 3n + 8 ≤ 4n, for all n ≥ 8
∴ 3n + 8 = O(n) with c = 4 and n0 = 8

Example-2 Find upper bound for f(n) = n2 + 1


Solution: n2 + 1 ≤ 2n2, for all n ≥ 1
∴ n2 + 1 = O(n2) with c = 2 and n0 = 1

PREAPARED BY: ABDUL JALIL NIAZAI


Asymptotic Notations
Big-O Examples:
Example-3 Find upper bound for f(n) = n4 + 100n2 + 50
Solution: n4 + 100n2 + 50 ≤ 2n4, for all n ≥ 11
∴ n4 + 100n2 + 50 = O(n4 ) with c = 2 and n0 = 11
Example-4 Find upper bound for f(n) = 2n3 – 2n2
Solution: 2n3 – 2n2 ≤ 2n3, for all n > 1
∴ 2n3 – 2n2 = O(n3 ) with c = 2 and n0 = 1

PREAPARED BY: ABDUL JALIL NIAZAI


Asymptotic Notations
No Uniqueness?
 There is no unique set of values for n0 and c in proving the asymptotic
bounds. Let us consider, 100n + 5 = O(n).
 For this function there are multiple n0 and c values possible.

Solution1: 100n + 5 ≤ 100n + n = 101n ≤ 101n, for all n ≥ 5, n0 = 5 and c = 101 is a


solution.
Solution2: 100n + 5 ≤ 100n + 5n = 105n ≤ 105n, for all n > 1, n0 = 1 and c = 105 is also
a solution.

PREAPARED BY: ABDUL JALIL NIAZAI


Asymptotic Notations
Omega-Ω Notation [Lower Bounding Function]
 Omega notation Similar to the O discussion, this notation gives the tighter
lower bound of the given algorithm and we represent it as f(n) = Ω(g(n)).
 That means, at larger values of n, the tighter lower bound of f(n) is g(n).
 For example, if f(n) = 100n2 + 10n + 50, g(n) is Ω(n2).

PREAPARED BY: ABDUL JALIL NIAZAI


Asymptotic Notations
Omega-Ω Notation [Lower Bounding Function]

PREAPARED BY: ABDUL JALIL NIAZAI


Asymptotic Notations
Omega-Ω Notation [Lower Bounding Function]

Ω–notation can be defined as function of f(n) = Ω(g(n)) iff ꓱ +ve constant C


and n0 such that f(n) >= C * g(n) ꓯ n >= n0

 g(n) is an asymptotic tight lower bound for f(n). Our objective is to give
the largest rate of growth g(n) which is less than or equal to the given
algorithm’s rate of growth f(n).

PREAPARED BY: ABDUL JALIL NIAZAI


Asymptotic Notations
Omega- Ω Examples:
Example-1 Find lower bound for f(n) = 5n2.
Solution: ∃ c, n0 Such that: 0 ≤ cn2≤ 5n2 ⇒ cn2 ≤ 5n2 ⇒ c = 5 and n0 = 1
∴ 5n2 = Ω(n2) with c = 5 and n0 = 1

PREAPARED BY: ABDUL JALIL NIAZAI


Asymptotic Notations
Omega- Ω Examples:
Example-2 Prove f(n) = 100n + 5 ≠ Ω(n2).
Solution: ∃ c, n0 Such that: 0 ≤ cn2 ≤ 100n + 5
100n + 5 ≤ 100n + 5n(∀ n ≥ 1) = 105n
cn2 ≤ 105n ⇒ n(cn - 105) ≤ 0
Since n is positive ⇒cn - 105 ≤0 ⇒ n ≤105/c
⇒ Contradiction: n cannot be smaller than a constant

PREAPARED BY: ABDUL JALIL NIAZAI


Asymptotic Notations
Omega- Ω Examples:
Example-3 Prove 5n2 + 3n +1 = Ω(n2)
Solution: Let f(n) = 5n2 + 3n +1
When n>1 , 5n2 + 3n +1 > 5n2
f(n) >= 5 g(n)
So from definition:
0 ≤ c g(n) ≤ f(n) for n ≥1
Here, c = 5 , n0 =1
and g(n) = n2
Hence, 5n2 + 3n +1 = Ω(n2)

PREAPARED BY: ABDUL JALIL NIAZAI


Asymptotic Notations
Theta-Θ Notation [Average Bounding Function]
 This notation decides whether the
upper and lower bounds of a given
function (algorithm) are the same.
 The average running time of an
algorithm is always between the lower
bound and the upper bound.
 If the upper bound (O) and lower
bound (Ω) give the same result, then
the Θ notation will also have the same
rate of growth.

PREAPARED BY: ABDUL JALIL NIAZAI


Asymptotic Notations
Theta-Θ Notation [Average Bounding Function]

Θ–notation can be defined as function of f(n) = Θ(g(n)) iff ꓱ +ve constant


C1,C2 and n0 such that
c1*g(n) ≤ f(n) ≤ c2*g(n) ꓯ n >= n0

Example 1:
Therefore:
f(n) = 2n + 3 f(n) : Θ(n)
1*n ≤ 2n+ 3 ≤ 5*n

C1 g(n) f(n) C2 g(n)

PREAPARED BY: ABDUL JALIL NIAZAI


Asymptotic Notations
Theta-Θ Notation [Average Bounding Function]

Example 2

PREAPARED BY: ABDUL JALIL NIAZAI


Type of Analysis
 Analysis of algorithm is the process of analyzing the problem-solving capability of
the algorithm in terms of the time and size required (the size of memory for
storage while implementation).
 However, the main concern of analysis of algorithms is the required time or
performance.
 Generally, we perform the following types of analysis:

 Best Case
 Worst Case
 Average Case

PREAPARED BY: ABDUL JALIL NIAZAI


Type of Analysis
 To perform these three types of analysis, we consider the following algorithm as
examples.

• Linear Searching Algorithm


• Binary Searching Algorithm

PREAPARED BY: ABDUL JALIL NIAZAI


Type of Analysis
Best Case Analysis
Best case is the function which performs the minimum number of steps on input data of n elements.

Linear Search A 9 12 8 5 17 7 13 4 14 15

Best Case: Searching key element present at first index.


Best Case Time: 1  O(1)
Or B(n)  O(1)

PREAPARED BY: ABDUL JALIL NIAZAI


Type of Analysis
Worst Case Analysis
Worst case is the function which performs the maximum number of steps on input data of size n.

Linear Search A 9 12 8 5 17 7 13 4 14 15

Worst Case: Searching key element present at last index.


Worst Case Time: n  O(n)
Or w(n)  O(n)

PREAPARED BY: ABDUL JALIL NIAZAI


Type of Analysis
Average Case Analysis
Average case is the function which performs an average number of steps on input data of n elements.

Linear Search A 9 12 8 5 17 7 13 4 14 15

All possible case time


Average Case:
number of cases

Need Some Description

PREAPARED BY: ABDUL JALIL NIAZAI


Type of Analysis
Discussion
Average case is the function which performs an average number of steps on input data of n elements.

B(n) = 1 W(n) = n
B(n) = O(1) W(n) = O(n)
B(n) = Ω(1) W(n) = Ω(n)
B(n) = Θ(1) W(n) = Θ(n)

PREAPARED BY: ABDUL JALIL NIAZAI

You might also like