Chapter # 3 Asymptotic Analysis
Chapter # 3 Asymptotic Analysis
Analysis of Algorithm
Class Task
Group Task
Make group of 2 students
Design an algorithm
That find
Maximum value &
Minimum value
In the array of size n
Also find the time complexity
Best, Worst and Average case running time
1
4/26/2020
Chapter 3
Asymptotic Analysis
Order of Growth
We require some simplifying assumptions to ease our
analysis
We do this by
Ignoring the actual cost of each statement, and
Even the abstract costs
2
4/26/2020
Exponential
Functions are powers of a constant
i.e. f(x) = Ckn
Where k and c are constant
Examples are: f(x) = 2x, 34x etc…
3
4/26/2020
Examples
An algorithm with running time T(n) = 2n is said to be
Exponential Algorithm
An algorithm with running time T(n) = n2 is said to be
Polynomial Algorithm
4
4/26/2020
Or Next Slide
Design and Analysis of Algorithm
5
4/26/2020
Comparison of Algorithms
1000 means, 1000 instruction (or n as problem size) in 1 second and so
on
6
4/26/2020
Asymptotic Analysis
When we consider rate of growth (algorithm behavior)
We need to consider only
The Leading Term of a formula
Since lower order terms are insignificant in comparison
Consider
An Algorithm1 with running time c1n2 and
Another Algorithm2 with running time c2nlgn
Even if c2 is larger than c1
Once n is large, Algorithm1 is beaten by Algorithm2
7
4/26/2020
O-Notation (Cont...)
If f(n) is a growth function of an algorithm
And g(n) is a function such that
For some positive real constants C and for all n ≥ n0
Then
0 < f(n) ≤ Cg(n)
Then we say
f(n) = O (g(n))
Read as f(n) in Big-Oh of g(n)
The behavior of f(n) and g(n) is shown
Follows that
For n < n0, f(n) is either above or below then g(n)
Design and Analysis of Algorithm
8
4/26/2020
O-Notation (Cont...)
But for all n ≥ n0, f(n) falls consistently below Cg(n)
The function g(n) is said to be asymptotic Upper bound for
f(n)
O-Notation (Cont...)
There may be many functions for which g(n) is asymptotically
Upper bound
All such functions are said to be belonging to the group
identified by g(n)
Symbolically we can denote the relationship as
f(n) ϵ O(g(n))
9
4/26/2020
10
4/26/2020
11
4/26/2020
Ω -Notation (Cont...)
If f(n) is a growth function of an algorithm
And g(n) is a function such that
For some positive real constants C and for all n ≥ n0
Then
0 < Cg(n) ≤ f(n)
Then we say
f(n) = Ω (g(n))
Read as f(n) in Big-Omega of g(n)
The behavior of f(n) and g(n) is shown
Follows that
For n < n0, f(n) is either above or below then g(n)
Design and Analysis of Algorithm
Ω -Notation (Cont...)
But for all n ≥ n0, f(n) falls consistently above Cg(n)
The function g(n) is said to be asymptotic Lower bound for
f(n)
12
4/26/2020
Ω –Notation Example 1
n2 – 10n Є Ω (n2)
13
4/26/2020
Ω –Notation Example 2
3n2 – 25n Є Ω (n2)
14
4/26/2020
15
4/26/2020
θ-Notation (Cont...)
If f(n) is a growth function for an algorithm
And g(n) is a function such that
For all positive real constants C1, C2 and for all n ≥ n0
Then 0 < C2g(n) ≤ f(n) ≤ C1g(n)
C2g(n) is Lower bound and C1g(n) is Upper bound of f(n)
Then we say
f(n) = θ (g(n))
Read as f(n) in Theta of g(n)
The behavior of f(n) and g(n) is shown
Follows that
For n < n0, f(n) is either above or below then g(n)
Design and Analysis of Algorithm
θ-Notation (Cont...)
But for n ≥ n0, f(n) falls consistently between C1g(n) and
C2g(n)
g(n) is said to be asymptotic tight bound for f(n)
16
4/26/2020
θ-Notation (Cont...)
There may be many functions for which g(n) is asymptotically
tight bound
All such functions are said to be belonging to the group
identified by g(n)
Symbolically we can denote the relationship as
f(n) ϵ θ(g(n))
θ-Notation Example
5n2 – 6n ϵ θ (n2)
To prove that 5n2 – 6n = θ(n2), we need to show that 5n2 – 6n = O(n2)
and 5n2 – 6n = Ω(n2)
17
4/26/2020
o – Notation, Small Oh
If f(n) is a growth function for an algorithm and g(n) is
some function such that
0 ≤ f(n) ≤ C.g(n)
For all C > 0 and all n ≥ n0
Then we say
f(n) = o (g(n))
Read as f(n) in Small-Oh of g(n)
Symbolically
f(n) Є o (g(n))
18
4/26/2020
o – Notation Example
n Є o (n2)
19
4/26/2020
Symbolically
f(n) Є ω (g(n))
20
4/26/2020
21
4/26/2020
Ɵ - O - Ω Relation
o - O Relation
22
4/26/2020
ɷ - Ω Relation
Order Theorem
23
4/26/2020
24
4/26/2020
End
End of the Chapter
25