0% found this document useful (0 votes)
29 views21 pages

Lec-4&5 Asymptotic Notations

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views21 pages

Lec-4&5 Asymptotic Notations

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 21

Design & Analysis of Algorithms

(BCAE0106)

Lec-4&5 : Asymptotic Notations

Presented by:
Akanksha
Assistant Professor
Dept. of Computer Engineering & Applications, IET,
GLA University, Mathura
Outline
 Need of Asymptotic Notations
 Asymptotic Notations
 Big O Notation
 Omega Notation
 Theta Notation
 Little O Notation
 Little Omega Notation
 Conclusion
Need of Asymptotic Notations:
Asymptotic Notations are abstract notations for
describing the behaviour of the algorithm and
determine the rate of growth of a function.

3
Asymptotic Notation
 Asymptotic Notations are mathematical tools
to represent the time complexity of algorithms
for asymptotic analysis.

 Themain idea of asymptotic analysis is to have


a measure of efficiency of algorithms that does
not depend on machine specific constants and
does not require algorithms to be implemented
and time taken by the programs to be
compared.
Asymptotic Notation…
 Big Omega Ω :
 Best case
 Never achieve better than this
 Big Theta Θ :
 Average case
 Big O :
 Worst case
 Upper bound
 Time must not exceed
 Little O:
 Little Omega:
Asymptotic Notation…
10 12 35 11 40 52 22 21 25 50
0……………………………………………………………….n-1
If element=10 , then best case Ω(1)

If element=40, then average case Θ(n/2)

If element=50, then worst case O(n)


The Big-Oh (O) Notation

 Big O natation defines an least upper bound of


an algorithm.

Big O notation is useful when we only have upper


bound (at most) on time complexity of an
algorithm.

Big O Notation is used for worst case analysis.


The Big-Oh (O) Notation

 f(n)=O(g(n)) , if there exists

Running time
constants c > 0 and n0 ≥ 1 ,
s.t. 0 ≤ f(n) ≤ c g(n) for n ≥ n0

 f(n) and g(n) are functions


over non-negative integers.
Input size
Examples on Big Oh Notation:

Example 1: Given f(n)=3n+5, then prove that f(n)=O(n)


Solution 1:
As per definition: f(n) <= C g(n), for every n >= n0
From given problem statement,
f(n)=3n+5 & g(n)=n
Now there exists a constant such that value of c>0 and n 1
So, let’s write the equation as 3n+5 <= C. n
On solving the in-equality we get C=4 & then checking for different values of n

n=1 n=2 n=3 n=4 n=5


8<=4 11<=8 14<=12 17<=16 20<=20
False False False False True

So, from case 5, f(n)=O(n) for every n >= 5

10
Examples on Big Oh Notation:
 Example 2:
 Given f(n) = 2n2+n , then prove that
f(n)=O(n2)
The Big-Omega (Ω) Notation

 BigOmega notation provides an asymptotic


lower bound of algorithmic problem.

 BigOmega can be useful when we have lower


bound (at least) on time complexity of an
algorithm.

 Big Omega Notation is used for best case


analysis.
The Big-Omega (Ω) Notation
 f(n)= Ω(g(n)) , if there exists

Running time
constants c > 0 and n0 ≥ 1 ,
s.t. 0 ≤ c g(n) ≤ f(n) for n ≥ n0

 f(n) and g(n) are functions


over non-negative integers.
Input size
Examples of Big Omega Notation:
Example 1: Given f(n)=3n+5, then prove that f(n)=Ω(n)

Solution 1: As per def.:

For the given problem statement, f(n)=3n+5, g(n)=n

Now there exists a constants such that value of c>0 and n 1

As per Big-Omega theory, C.g(n)f(n)

So let’s write the equation as C. n 3n+5

On solving the inequality we find that when Case 1:C=1 and n=1 i.e.

1(1) 3(1) +5

1 8 (True)

So from case 1 f(n)=Ω (n) n 1


14
The Big-Theta (Θ) Notation
 The theta function bounds a function from
above and below, so it defines exact
asymptotic behavior.

 Big Theta Notation is used for average case


analysis.

 It gives exact time.


The Big-Theta (Θ) Notation
 f(n)= Θ(g(n)) , if there exists
constants c1 & c2 and n0 , s.t.
0 ≤ c1. g(n) ≤ f(n) ≤ c2. g(n)

Running time
for n ≥ n0
 The above definition means,
if f(n) is theta of g(n),then the
value of f(n) is always between
c1.g(n) and c2.g(n) for large values
of n (n>= n0)
f(n) and g(n) are functions
over non-negative integers. Input size
Examples of Theta Notation:
Example 1: f(n)= n2 +3n+7, then prove that f(n)= Θ( n2 )
Solution 1. As per def.: C1.g (n) f (n) C2.g (n)
For the given problem statement, f(n)= n2 +3n+7, g(n)=n2
Now there exists a constants such that value of c>0 and n 1
As per Big-Theta theory C1.g (n) f(n) C2.g(n)
C1. n2 n2 +3n+7 C2. n2
If C1=1 & C2=2 then n>=5
Hence,
17
Asymptotic Notation
 The Little-oh (o) Notation
 Asymptotic upper bound

Running time
 f(n)=o(g(n)) , if there exists
constants c > 0 and n0 ≥ 1 ,
s.t. 0 ≤ f(n) < c g(n) for n ≥ n0
 f(n) and g(n) are functions
over non-negative integers.

Input size
Asymptotic Notation
 The Little-omega (Ω) Notation
 Asymptotic lower bound

Running time
 f(n)= Ω(g(n)) , if there exists
constants c > 0 and n0 ≥ 1 ,
s.t. f(n) > c g(n) ≥ 0 for n ≥ n0
 f(n) and g(n) are functions
over non-negative integers.

Input size
Analogy of Asymptotic Notations with
real numbers
 f(n) is O((g(n)) a <= b
 f(n) is Ω((g(n)) a >= b
 f(n) is Θ((g(n)) a=b
 f(n) is o((g(n)) a<b
 f(n) is ω((g(n)) a>b
Conclusion
 Most useful notation is Theta, followed by Big
O.

 Omega notation is the least used notation


among all three.

You might also like