Professional Documents
Culture Documents
Asymptotic Analysis
01 • Definition
• Types of Time Requirements
Asymptotic Notations
02 • Big Oh Notation, Ο
• Omega Notation, Ω
• Theta Notation, θ
• Common Asymptotic Notations
Recap
Data Structure
• An ideal data structure could be the one that takes the least possible time for
all its operations and consumes the least memory space.
Recap
Question
Answer
On the basis of operations performed on them
.
Example
arr 1 2 5 7 9 11 15
arr 1 2 5 7 9 11 15
33
Target: Add data at the beginning of the list
Example
arr 1 2 5 7 9 11 15
33
Target: Add data at the beginning of the list
3 1 2 5 7 9 11 15
Example
arr 3 1 2 5 7 9 11 15
Linked List
4 Null
4000
Example
arr 3 1 2 5 7 9 11 15
Linked List
Head 4 1000
4000
Example
arr 3 1 2 5 7 9 11 15
Linked List
Run the operation in the machine and check the running time.
Run the operation for different inputs on the data structures you want
to compare one by one.
arr 1 2 5 7 9 11 15
This clearly shows that the running time generally depends on the size
of the input
Points to be noted:
Therefore, if the size of the input is n, then f(n) is a function of n denotes the
time complexity.
In other words, f(n) represents the number of instructions executed for the
input value of n
For example:
Therefore, f(n) = n
But, how to find f(n)?
f(n) = 5n2 + 6n + 12
for n = 1
f(n) = 5n2 + 6n + 12
n 5n2 6n 12
1 21.74% 26.09% 52.17%
10 87.41% 10.49% 2.09%
100 98.79% 1.19% 0.02%
1000 99.88% 0.12% 0.0002%
f(n) = 5n2 + 6n + 12
n 5n2 6n 12
1 21.74% 26.09% 52.17%
10 87.41% 10.49% 2.09%
100 98.79% 1.19% 0.02%
1000 99.88% 0.12% 0.0002%
So, there is no harm if we can eliminate the rest of the terms as they
are not contributing much to the time.
Asymptotic Complexity
f(n) = 5n2
We are getting the approximate time complexity and we are satisfied with this
result because this approximate result is very near to the actual result.
g(n)
n log2n n nlog2n n2 n3 2n
1 0 1 0 1 1 2
2 1 2 2 4 8 4
4 2 4 8 16 64 16
8 3 8 24 64 512 256
16 4 16 64 256 4096 65536
32 5 32 100 1024 32768 429x107
Big O Notation
It gives the upper bound on a function by which we can make sure that the
function will never grow faster than this upper bound.
Definition
Big Oh Notation, Ο
Omega Notation, Ω
Theta Notation, θ
θ(f(n)) = { g(n) if and only if g(n) = Ο(f(n)) and g(n) = Ω(f(n)) for all n > n0. }
Asymptotic Notations