Growth of Functions Lecture2.3 DAA
Growth of Functions Lecture2.3 DAA
Lecture # 2
03/02/25
Contents 2
03/02/25
Analyzing Running Time 3
03/02/25
Asymptotic analysis 4
03/02/25
5
Limitations
not always useful for analysis on fixed-size inputs.
03/02/25
Asymptotic analysis 6
03/02/25
7
03/02/25
8
03/02/25
9
03/02/25
10
03/02/25
11
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
03/02/25
Classification of Growth 12
03/02/25 03/02/25
Asymptotic Upper Bound (Big Oh )
13
f(n) O(g(n))
03/02/25
Examples 16
03/02/25
Examples 17
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
03/02/25
Examples 18
03/02/25
Properties of Big-Oh 19
03/02/25
Big-O Visualization 20
03/02/25
Properties of Big-Oh 21
if (i<j)
for ( i=0; i<N; i++ )
O(N)
X = X+i;
else
X=0; O(1)
03/02/25
Big-Omega Notation () 22
Intuitively:
Set of all functions whose rate of growth is the same as or higher
than that of g(n).
03/02/25
Big-Omega Notation () 23
03/02/25
Big-Omega Notation 24
f(n) (g(n))
03/02/25
Examples 26
03/02/25
Theta Notation () 27
Intuitively: Set of all functions that have same rate of growth as g(n).
03/02/25 03/02/25
Theta Notation () 28
f(n) (g(n))
03/02/25
Common growth rates(Big O) 31
03/02/25
Common growth rates 32
03/02/25
Number of comparisons for common Big O notations.
33
03/02/25
Examples 35
1. statement;
is constant. The running time of the statement
will not change i.e. O(1)
03/02/25
Examples 36
03/02/25
Examples 37
03/02/25
Examples (Another Way) 38
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)
03/02/25
Conclusion 39
03/02/25
Logarithms and properties 40
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
03/02/25
Common Summations 41
n
n( n 1)
Arithmetic series: k 1 2 ... n
k 1 2
n
x n 1 1
Geometric series: k 2 n
x 1 x x ... x 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
03/02/25
Self Practice 42
03/02/25
Practice Examples(Big O) 43
03/02/25
Practice Examples(Big O) 44
03/02/25
Practice Examples(Big O) 45
03/02/25
Practice Examples(Big O) 46
03/02/25
Practice Examples(Big O) 47
03/02/25
Practice Examples(Big Omega) 48
03/02/25
Little-Oh Notation 49
03/02/25
Examples 51
Since
f(n) < c.g(n) n2 < c.n2 1 ≤ c,
03/02/25
Examples 52
03/02/25
Little-Omega Notation 53
03/02/25
Examples 55
03/02/25
Examples 56
03/02/25