Chapter 2 - Asymptotic Notations
Chapter 2 - Asymptotic Notations
g(n)
a logb x x logb a
3
Asymptotic Notations - Examples
• For each of the following pairs of functions, either f(n) is
O(g(n)), f(n) is Ω(g(n)), or f(n) = Θ(g(n)). Determine
which relationship is correct.
– f(n) = log n2; g(n) = log n + 5 f(n) = (g(n))
– f(n) = n; g(n) = log n2 f(n) = (g(n))
– f(n) = log log n; g(n) = log n f(n) = O(g(n))
– f(n) = n; g(n) = log2 n f(n) = (g(n))
– f(n) = n log n + n; g(n) = log nf(n) = (g(n))
– f(n) = 10; g(n) = log 10 f(n) = (g(n))
– f(n) = 2n; g(n) = 10n2 f(n) = (g(n))
– f(n) = 2n; g(n) = 3n f(n) = O(g(n))
4
Asymptotic notations
• O-notation
5
Examples
– 2n2 = O(n2n
3 2 ≤ cn3 2 ≤ cn c = 1 and n = 2
): 0
– 1000n2+1000n = O(n2):
n ≤
– n = O(n ):
2 cn 2
cn ≥ 1 c = 1 and n0= 1
6
• 2n2 = O(n3)
7
Asymptotic notations (cont.)
- notation
8
Examples
– 5n2 = (n)
cn
c, n0 such that: 0 cn 5n 2 5n2 c = 1 and n0 = 1
– 100n + 5 ≠ (n2)
c, n0 such that: 0 cn2 100n + 5
100n + 5 100n + 5n ( n 1) = 105n
cn2 105n
n(cn – 105) 0
n 105/c
Since n is positive cn – 105 0
contradiction: n cannot be smaller than a constant
10
Asymptotic notations (cont.)
-notation
11
Examples
– n2/2 –n/2 = (n2)
• ½ n2 - ½ n ≤ ½ n2 n ≥ 0 c2= ½
• ½ n2 - ½ n ≥ ½ n2 - ½ n * ½ n ( n ≥ 2 ) = ¼ n2
c1= ¼
– n ≠ (n2): c1 n2 ≤ n ≤ c2 n2
13
Examples
– 6n3 ≠ (n2): c1 n2 ≤ 6n3 ≤ c2 n2
c2 ≥ n/logn, n≥ n0 – impossible
14
• n ≠ (logn)
15