Professional Documents
Culture Documents
Unit - 3: Complexity Analysis
Unit - 3: Complexity Analysis
Unit - 3: Complexity Analysis
Complexity Analysis
Example: f (n) 2n 3 3n 2 n 10
f (n) 2n 3 3n 2 n 10 5n 3 n 2, C 5
f ( n) O ( n 3 )
T(n) = 15n3 + 7n2 + 35 <=57n3 , f(n) = 15n3 + 7n2 + 35 and g(n)=n3, C=57
for n>=1
•T(n) = O(n3)
•Exercise : 10n3 + 5n + 7 є O(n4)
Example: f (n) 2n 3 3n 2 n 10
f (n) 2n 3 3n 2 n 10 2n 3 n 1
f ( n) ( n 3 )
T(n)= 2n3 + 37 >=2n3 , f(n)= 2n3 + 37 and g(n)= n3. C=2 for n>=1
•T(n) = Ω(n3)
Example: f (n) 2n 3 3n 2 n 10
2n 3 2n 3 3n 2 n 10 5n 3 n 2
f ( n) ( n 3 )
i 0
but , ( g ) f
( g ) O( g ) ( g )
f ( n)
lim 0
n g ( n )
Example:
f (n) 2n 3 3n 2 n 10
2n 3 3n 2 n 10 2 3 1 10
lim 4
lim 2 3 4 0
n n n n
n n n
f ( n) o( n 4 )
g ( n)
lim 0
n f ( n)
Example:
f (n) 2n 3 3n 2
n 1 1
lim 3 lim 2 0
n 2n 3n 2 n 2n 3n
f ( n) ( n)
m
f ( n) O ( n )
Again, consider S(m)=T(2m)
m
S ( m) 2 S m
2
S ( m) O(m log m) T (n) O(log n log log n)
Again, consider S(m)=T(2m)
m
S ( m) 2 S 1
2
S ( m) O(m) T (n) O(log n)
Complexity O(1)
Complexity
n
T (n) T c T ( n) O (log n)
2