Growth of Function DAA Lecture2.2
Growth of Function DAA Lecture2.2
Lecture # 2
Limitations
not always useful for analysis on fixed-size inputs.
On a graph, as
you go to the
right, a faster
growing
function fA(n)=30n+8
Value of function
eventually
becomes
larger...
fB(n)=n2+1
Increasing n
f(n) O(g(n))
Proof:
Assume that f(n) = n2 , and g(n) = n2
Now we have to show that f(n) O(g(n))
Since
f(n) ≤ c.g(n) n2 ≤ c.n2 1 ≤ c, take, c = 1, n0= 1
Then
n2 ≤ c.n2 for c = 1 and n 1
Hence, 2n2 O(n2), where c = 1 and n0= 1
if (i<j)
for ( i=0; i<N; i++ )
O(N)
X = X+i;
else
X=0; O(1)
Intuitively:
Set of all functions whose rate of growth is the same as or higher
than that of g(n).
Advance Analysis of Algorithms
by: ASIF Mahmood 03/02/25
Big-Omega Notation () 23
f(n) (g(n))
Intuitively: Set of all functions that have same rate of growth as g(n).
Advance Analysis of Algorithms
03/02/25 by: ASIF Mahmood 03/02/25
Theta Notation () 28
f(n) (g(n))
1. statement;
is constant. The running time of the statement
will not change i.e. O(1)
Algorithm 3 Cost
sum = 0; c1
for(i=0; i<N; i++) c2
for(j=0; j<N; j++) c2
sum += arr[i][j]; c3
------------
c1 + c2 x (N+1) + c2 x N x (N+1) + c3 x N2 = O(N2)
Binary logarithm
lg n log2 n log x y y log x
Natural logarithm ln n loge n log xy log x log y
x
lg k n (lg n ) k log log x log y
y
lg lg n lg(lg n ) log a
a logb x x b
log b x log a x
log a b
n
n( n 1)
Arithmetic series: k 1 2 ... n
k 1 2
n
x n 1 1
Geometric series: k 2
x 1 x x ... x n
x 1
k 0 x 1
◦ Special case: |x| < 1:
1
x k
k 0 1 x
Harmonic series: n
1 1 1
k 1 k
1
2
...
n
ln n
Other important n
lg k n lg n
formulas: k 1
n
1
k p 1p 2 p ... n p
k 1 p 1
n p 1
Since
f(n) < c.g(n) n2 < c.n2 1 ≤ c,