Algorithm Ch 1 Lec 2
Algorithm Ch 1 Lec 2
1. Big oh (O)notation
2. Big omega (Ω) notation
3. Theta(Θ) notation
1.Big oh (O)notation
1. Big oh (O)notation : Asymptotic “less than”(slower rate).This
notation mainly represent upper bound of algorithm run time.
Big oh (O)notation is useful to calculate maximum amount of time of
execution.
By using Big-oh notation we have to calculate worst case time complexity.
Formula : f(n)<=c g(n) n>=n0 , c>0 ,n0 >=1
Definition: Let f(n) ,g(n) be two non negative (positive) function. The
function f(n)=O(g(n)) if and only if there exist two positive constant c, n0
such that f(n)<= c. g(n) for all value of n > 0 & c>0
We use O-notation to give an asymptotic upper bound of a function, to
within a constant factor.
means that there existes some constant c s.t. is
always for large enough n.
Examples
Example : f(n)=3n +2 & g(n)= n
Formula : f(n)<=c g(n) n>=n0 , c>0 ,n0 >=1
Now 3n+2 <= c.n
3n+2 <= 4.n
Put the value of n =1
5<=4 false
n = 2 8<=8 true
Now 3n+2<=4n is true for all values of n >=2 and c=4
Therfore , f(n)<= c.g(n)
Above condition is satisfied . And this notation takes maximum amount of time
to execute . So that it is called worst case complexity.
Examples
8/31/2024
Theorem
8/31/2024
2.Ω-Omega notation
Ω-Omega notation : It represent Lower bound of algorithm run
time.
8/31/2024
3. -Theta notation
Theta (Θ) notation : Asymptotic “Equality”(same rate).
It represent average bond of algorithm running time.
8/31/2024
Example of asymptotic notation
Problem:-Find upper bond ,lower bond & tight bond range for
functions: f(n)= 2n+5
Solution:-Let us given that f(n)= 2n+5 , now g(n)= n
lower bond=2n, upper bond =3n, tight bond=2n
1. For Big –oh notation(O):- according to definition
f(n)<=cg(n) for Big oh we use upper bond 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
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)=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.
Since the output of any randomizer might differ in an unpredictable way from run
to run, the output of a randomized algorithm could also differ from run to run for
the same input.
The algorithm typically uses uniformly random bits as an auxiliary input to guide
its behavior, in the hope of achieving good performance in the "average case" over
all possible choices of random bits.
An algorithm that uses random numbers to decide what to do next anywhere in its
logic is called Randomized Algorithm..
8/31/2024
Monte Carlo Algorithm (Cont.)
Example : Problems where there are only two possible
answers: Yes and No. If a Monte Carlo algorithm is
employed to solve such a problem, then the algorithm
might give incorrect answers depending on the output of
the randomizer. We require that the probability of an
incorrect answer from a Monte Carlo algorithm be low.
8/31/2024