Data Structures and Algorithms-1
Data Structures and Algorithms-1
Asymptotic notations
We also tried to gain insight into the high school algorithms for
I factorization of an integer.
I finding the GCD of two integers.
Recap
Problems that we faced
Solution
Asymptotic Bounds
For example, 50 years back everybody thought that the fastest way
to reach from Mumbai to Madras was to catch a train. But now we
have airplanes.
Suppose there are two algorithms A and B which solve the same
problem. For an instance of size n
I A takes log2 n number of clock cycles.
I B takes 2100 number of clock cycles.
100
∀ inputs of size < 22 , we will observe that the algorithm A takes
less time compared to algorithm B and hence we may prematurely
conclude that A is the better algorithm, but as soon as the inputs
100
are of size greater than 22 , we may realize that sometimes B can
be better than A.
Recap
Problems that we faced
Solution
Asymptotic Bounds
f (x)
≤M
g (x)
Recap
Asymptotic upper bound
Problems that we faced
Asymptotic lower bound
Solution
Other useful notations
Asymptotic Bounds
f (x) = 3x 2 − 15x + 1
≤ 3x 2 + 15x + 1
≤ 3x 2 + 15x 2 + x 2 = 19x 2
f (x)
Thus f (x) = O(g1 (x)), because g1 (x) ≤ M = 19
Recap
Asymptotic upper bound
Problems that we faced
Asymptotic lower bound
Solution
Other useful notations
Asymptotic Bounds
Let g2 (x) = x 3
f (x) = 3x 2 − 15x + 1
≤ 3x 2 + 15x + 1
≤ 3x 3 + 15x 3 + x 3 = 19x 3
f (x)
Thus f (x) = O(g2 (x)), because g2 (x) ≤ 19
Recap
Asymptotic upper bound
Problems that we faced
Asymptotic lower bound
Solution
Other useful notations
Asymptotic Bounds
f (x) f 0 (x) 6x + 15
lim = 0 = = lim 6x 2 + 15x = undefined
x→∞ g3 (x) g (x) 1/x x→∞
There exists no real value M such that M > 6x 2 + 15x for all values
of x. Thus f (x) 6= O(g3 (x))
Recap
Asymptotic upper bound
Problems that we faced
Asymptotic lower bound
Solution
Other useful notations
Asymptotic Bounds
Valuable insights
Valuable insights
This also gives a hint that while analysing algorithms we should not
focus on smaller instances and focus on how an algorithm behaves
when the input extremely large.
Omega Notation
g (x)
≤M
f (x)
Recap
Asymptotic upper bound
Problems that we faced
Asymptotic lower bound
Solution
Other useful notations
Asymptotic Bounds
Theta Notation
For any two functions f and g , we have f (x) = Θ(g (x)) if and only
if
f (x) = O(g (x)) and
f (x) = Ω(g (x))
In layman terms, this would mean that both the functions f and g
grow in a similar fashion.
Recap
Asymptotic upper bound
Problems that we faced
Asymptotic lower bound
Solution
Other useful notations
Asymptotic Bounds
f (x)
lim =0
x→∞ g (x)
g (x)
lim =0
x→∞ f (x)