Asymtotic Notations 1
Asymtotic Notations 1
Introductory Examples
Dr. Sania Bhatti
Sequential Search Algorithm
• Suppose we have an array of n elements [1: ], and a key element,
KEY.
Analysis
12
ASYMPTOTIC NOTATION
13
They are 3 asymptotic notations are mostly used to
represent time complexity of algorithm.
1.Big oh (O)notation
2.Big omega (Ω) notation
3.Theta(Θ) notation
4.Little oh notation
5.Little omega(Ω) notation
14
1.Big oh (O)notation
1.Big oh (O)notation (Asymptotic Upper Bound):
This notation mainly represents upper bound of the
algorithm run time.
Big oh (O)notation is useful to calculate the maximum
amount of time of execution.
By using Big-oh notation we have to calculate worst-
case time complexity.
15
1.Big oh (O)notation
16
17
Example
Example : f(n)=2n +3 & g(n)= n
Formula : f(n) ≤ c g(n) n ≥ n0 , c>0 ,n0 ≥ 1
f(n)=2n+3 & g(n)=n
Now 2n+3 ≤ c.n Let c=4
2n+3 ≤ 4.n
Put the value of n =1
5 ≤ 4 false
Put n=2 7 ≤ 8 true now n0>2 For all value of n>2 & c=4
now f(n) ≤ c.g(n)
2n+3 ≤ 4n for all values of n>2 The above condition is satisfied this notation
takes a maximum amount of time to execute.
It means that f(n)= Og(n). So that it is called worst-case complexity.
18
Example
19
1.Big oh (O)notation
Common Rules
The following two rules help simplify finding asymptotic upper bounds
20
2.Ω-Omega notation
Ω-Omega notation Asymptotic Lower Bound:
It represents the Lower bound of the algorithm run
time.
By using Big Omega notation we can calculate
minimum amount of time. We can say that it is best
case time complexity.
22
23
Examples
Example : f(n)=2n +3
Formula : f(n) ≥ c g(n) n>=n0 , c>0 ,n0 >=1
f(n)=2n+3
2n+3 ≥ 1*n, c=1 put the value of n=1
5 ≥ 1 true n0 ≥ 1 for all value of n
It means that f(n)= Ω g(n).
24
Example
3. -Theta notation
Theta (Θ) notation Tight Bound:
where c is constant
Average bound
26
Theta notation
For a given function f (n) , we denote by ( g (n)) the set
of functions
27
28
Example
Example : f(n)=2n+3
Formula : c1 g(n) ≤ f(n) ≤ c2 g(n)
f(n)=2n+3
1*n ≤ 2n+3 ≤ 4*n now put the value of n=1
we get 1 ≤ 5 ≤ 4 false
n=2 we get 2 ≤ 7 ≤ 8 true
n=3 we get 3 ≤ 9 ≤ 12 true
It means that f(n)= g(n).
Now all values of n ≥ 2 it is true above condition is satisfied.
29
Example
)
+….+1=n
We proved 2 /2 2 2
A nested loop analysis
4.Little oh notation
35
Examples
36
Examples
Sol:
37
Examples
38
5.Little omega(ω) notation
•Another asymptotic notation is little omega notation. it is denoted
by (ω).
•Little omega (ω) notation is used to describe a loose lower bound
of f(n).
•Faster growth rate
•F(n) grows faster than g(n)
•The relation f(n)=ωg(n) implies if
39
Example
40
Example of asymptotic notation
Problem:-Find upper bound ,lower bound & tight bound range for
functions: f(n)= 2n+5
Solution:-Let us given that f(n)= 2n+5 , now g(n)= n
lower bound=2n, upper bound =3n, tight bound=2n
For Big –oh notation(O):- according to definition
f(n) ≤ cg(n) for Big oh we use upper bound so
f(n)=2n+5, g(n)=n and c=3 according to definition
2n+5 ≤ 3n
Put n=1 7 ≤ 3 false Put n=2 9 ≤ 6 false Put n=3 14 ≤ 9 false Put
n=4 13 ≤ 12 false Put n=5 15 ≤ 15 true
now for all value of n ≥ 5 above condition is satisfied. C=3 n ≥ 5
41
2. Big - omega notation :- f(n) ≥ c.g(n) we know that
this
Notation is lower bond notation so c=2
Let f(n)=2n+5 & g(n)=2.n
Now 2n+5 ≥ c.g(n);
2n+5 ≥ 2n put n=1
We get 7 ≥ 2 true for all value of n ≥ 1,c=2 condition is
satisfied.
3. Theta notation :- according to definition
c1.g(n) ≤ f(n) ≤ c2.g(n) 42
Common Asymptotic notations
43
Apriori Analysis
44
Apostiari Analysis
• Apostiari analysis of an algorithm means we perform analysis of
an algorithm only after running it on a system. It directly
depends on the system and changes from system to system.
• In an industry, we cannot perform Apostiari analysis as the
software is generally made for an anonymous user, which runs it
on a system different from those present in the industry.
• In Apriori, it is the reason that we use asymptotic notations to
determine time and space complexity as they change from
computer to computer; however, asymptotically they are the
same.
45