Asymptotic Notation - Analysis of Algorithms
Asymptotic Notation - Analysis of Algorithms
• Textbook
•Introduction to Algorithms 3rd ,Cormen,
Leiserson, Rivest and Stein, The MIT Press,
• Fundamentals of Computer Algorithms,
2nd, Sartaj Sahni, Ellis Horowitz,
Sanguthevar Rajasekaran
• Others
• Introduction to Design & Analysis Computer Algorithm 3rd,
Sara Baase, Allen Van Gelder, Adison-Wesley, 2000.
• Algorithms, Richard Johnsonbaugh, Marcus Schaefer, Prentice
Hall, 2004.
• Introduction to The Design and Analysis of Algorithms 2nd
Edition, Anany Levitin, Adison-Wesley, 2007.
Proof:
• Here, we have f (n) = n 2 + n, and g(n) = n 3
• Notice that if n ≥ 1, n ≤ n 3 is clear.
2 3
• Also, notice that if n ≥ 1, n ≤ n is clear.
a b
• Side Note: In general, if a ≤ b, then n ≤ n
whenever n ≥ 1. This fact is used often in these
types of proofs.
• Therefore,
n 2 + n ≤ n 3 + n 3 = 2n 3
CS3102 (DAA), 14
More Examples
• Show that 30n+8 is O(n).
– Show c,n0: 30n+8 cn, n>n0 .
• Let c=31, n =8.
0 Assume n>n0=8. Then
cn = 31n = 30n + n > 30n+8, so 30n+8 < cn.
Value of function →
less than 31n
everywhere.
• But it is less than
31n everywhere to
30n+8
the right of n=8.
n
O(n)
n>n0=8 →
Increasing n →
– 1000n2+1000n = O(n2):
– n = O(n ):
2 n ≤ cn 2 cn ≥ 1 c = 1 and n = 1
0
for all n ≥ 5
▪ True or false?
1. 4+3n is O(n) True
2. n+2 logn is O(log n) False
3. logn+2 is O(1) False
4. n50 is O(1.1n) True
Omega notation represents the lower bound of the running time of an algorithm.
Thus, it provides best case complexity of an algorithm.
– 100n + 5 ≠ (n2)
c, n0 such that: 0 cn2 100n + 5
100n + 5 100n + 5n ( n 1) = 105n
cn2 105n n(cn – 105) 0
Since n is positive cn – 105 0 n 105/c
contradiction: n cannot be smaller than a constant
•½n 2 - ½ n ≤ ½ n2 n ≥ 0 c2= ½
• ½ n2- ½ n ≥ ½ n2 - ½ n * ½ n ( n ≥ 2 ) = ¼ n2
c1= ¼
– n ≠ (n2): c1 n2 ≤ n ≤ c2 n2
c2 ≥ n/logn, n≥ n0 – impossible