Assignment No 1......
Assignment No 1......
Submitted to :
Myym Sidra
Submitted by :
Ayesha Tahir
Roll no :
2293
Subject :
Data Structure and Algorithm
Topic:
Asymptatic Notations cases and types
Section:
Morning B
Session :
2022-2026
1
Asymptotic Notations
Asymptotic notations give us an idea about how good a given algorithim is
compared to some other algorithim.
1. Big oh notations
2. Big omega notations
3. Big theta notations
4. Little oh
5. Small omega
Big oh notations :
Big oh notations is used to describe asymptotic notations upper
bound
2
Graphic examples for Big oh (o)
3
Graphic example of Big omega
0 ≤ c(gn) ≤ f(n)
0 ≤ f(n)≤ c(gn)
Merging both the equation we get
4
Graphic examples of big theta
Little o Notations
There are some other notations present except the Big-Oh,
Big-Omega and Big-Theta notations. The little o notation is one
of them.
Let f(n) and g(n) are the functions that map positive real
numbers. We can say that the function f(n) is o(g(n)) if for any
real positive constant c, there exists an integer constant n0 ≤ 1
such that f(n) > 0.
5
Little ω asymptotic notation
Definition : Let f(n) and g(n) be functions that map positive integers to
positive real numbers. We say that f(n) is ω(g(n)) (or f(n) ∈ ω(g(n))) if for any
real constant c > 0, there exists an integer constant n0 ≥ 1 such that f(n) > c *
g(n) ≥ 0 for every integer n ≥ n0.
f(n) has a higher growth rate than g(n) so main difference between Big Omega
(Ω) and little omega (ω) lies in their definitions.In the case of Big Omega
f(n)=Ω(g(n)) and the bound is 0<=cg(n)<=f(n), but in case of little omega, it is
true for 0<=c*g(n)<f(n).
The relationship between Big Omega (Ω) and Little Omega (ω) is similar to
that of Big-Ο and Little o except that now we are looking at the lower bounds.
Little Omega (ω) is a rough estimate of the order of the growth whereas Big
Omega (Ω) may represent exact order of growth. We use ω notation to denote
a lower bound that is not asymptotically tight. And, f(n) ∈ ω(g(n)) if and only
if g(n) ∈ ο((f(n))
In mathematical relation,
lim f(n)/g(n) = ∞
n→∞
Example:
6
Prove that 4n + 6 ∈ ω(1);
the little omega(ο) running time can be proven by applying limit formula
given below.
n→∞
Cases
1. Best Case
2. Worst Case
3. Average Case
Sometimes we get lucky in life Exams cancelled when you were not
prepared, surprise test when prepared et → Best case you Same
times we get unlucky. Questions you never prepared asked in exams,
vain during sports period etc. But overall the life remains balance
with the mixture of lucky and unlucky times. => Analysis of a search
algorithm Expected Case
Consider
17 18 1 28 25 280
We have to search a given nurder in this array and report whether its present
array in the or not
7
Algo 1 → Start from first element until an element greater than or equal to the
number to be searched is found.
Algo 2 → Check whether the first or the last element is equal to the number. If
not find the number Between these two elements (center of the array) If the
center element is greater than the number to be searched, repeat the process
fork first half else repeat for second half until the number is found.
Analyzing Algo 1 If we really get lucky, the first element of the array
might turn out to be the clement we are searching for Hence we
made just one Comparison
Analyzing Algo 2 If we get really lucky, the first element will be the
only one which gets compared
we get unlucky we will have to keep durding the array into halves
until we get a singe element (the array gets finished)
8
What log(n)? What is that
1 + 1 + 1
1 + 1
Logn simply means how many time I need to divide In units such that ur cannot
divide them (into. halves) anymor
Space Complexity
Time is not the only thing we worry about while analyzing algorithms Space is
equally important