Asymptotic Notations
Asymptotic Notations
Asymptotic Notations
Asymptotic Notations
Big-‐Oh: English Definition
• If a running time is O(f(n)), then for large enough n the running time
is at most k⋅f(n) for some constant k .
b, c, d are correct
Example 1
Let . . Which of the following statements are true?
1 2
𝑛 + 3𝑛 ≤ 𝑐. 𝑛
2
1
𝑛 + 3 ≤ 𝑐 which is not possible because input n cannot be bounded
2
above by a constant (input can be of any length)
So (a) is not correct
Example 1
Let . Which of the following statements are true?
1 2
𝑛 + 3𝑛 ≥ 𝑐. 𝑛
2
1
𝑛 + 3 ≥ 𝑐 This holds for c =1/2 and 𝑛 ≥ 𝑛0 , 𝑛0 = 1
2
Example 1
Let . Which of the following statements are true?
1 2
𝑐1 𝑛 ≤ 𝑛 + 3𝑛 ≤ 𝑐2 𝑛
2
1
𝑐1 ≤ 𝑛 + 3 ≤ 𝑐2 This holds for c1 =1/2 , 𝑐2 = 4and 𝑛 ≥
2
𝑛0 , 𝑛0 = 1
Example 2
a) log2 n is Θ (log8 n)
b) log2 n is O (log8 n)
c) log2 n is Ω (log8 n)
log2 𝑛
log8 n = log2 n / log2 8 =
3
Example 2
a) log2 n is Θ (log8 n)
b) log2 n is O (log8 n)
c) log2 n is Ω (log8 n)
a, b, c are correct
Example 2
a) log2 n is Θ (log8 n)
𝑐1 log 8 𝑛 ≤ log 2 𝑛 ≤ 𝑐2 log 8 𝑛
log 2 𝑛 log 2 𝑛
𝑐1 ≤ log 2 𝑛 ≤ 𝑐2
3 3
𝑐1 𝑐2
≤1≤
3 3
It holds for c1 = 2 and c2 = 4
Example 3
a) n3log2n is Θ (3nlog8 n)
b) n3log2n is O (3nlog8 n)
c) n3log2n is Ω (3nlog8 n)
Example 3
a) n3log2n is Θ (3nlog8 n)
b) n3log2n is O (3nlog8 n)
c) n3log2n is Ω (3nlog8 n)
C is correct
Example 4
a) 8n is Θ (4n)
b) 8n is O (4n)
c) 8n is Ω (4n)
Example 4
Which of the following is correct?
a) 8n is Θ (4n)
b) 8n is O (4n)
c) 8n is Ω (4n)
(b) 8𝑛 = 23𝑛 = 22𝑛+𝑛
22𝑛+𝑛 ≤ 𝑐22𝑛
22𝑛 2𝑛 ≤ 𝑐22𝑛
2𝑛 ≤ 𝑐
Which is a contradiction
2𝑛+10 ≤ 𝑐. 2𝑛 𝑛 ≥ 𝑛0
Note 2𝑛+10 = 2𝑛 × 210 = 2𝑛 × 1024
So if we choose 𝑛0 = 1, c = 1024, claim holds
Example 6
Claim 210𝑛 ≠ 𝑂 (2𝑛 )
210𝑛 ≤ 𝑐. 2𝑛 𝑛 ≥ 𝑛0
But then cancelling 2𝑛
29𝑛 ≤ 𝑐 ∀ 𝑛 ≥ 𝑛0
Which is certainly false
Example 7
Prove T(n) = 2𝑛3 − 7𝑛 + 1 = Ω(𝑛3 )
2𝑛3 − 7𝑛 + 1 ≥ 𝑘𝑛3
2 − 7/𝑛2 + 1/𝑛3 ≥ 𝑘
The above inequality does not hold for n0 = 1 and 2 as L.H.S becomes negative and k has to be
positive
Lets try n0 = 3 and k = 1
2 − 7/9 + 1/27 ≥ 1, this is true
What happens when n gets large?
When n gets large 7/𝑛2 will become small and the L.H.S will become greater so the inequality
holds for n ≥ n0 , where n0 = 3
Example 8
Prove T(n) = 2𝑛3 − 7𝑛 + 1 = O(𝑛3 )
2𝑛3 − 7𝑛 + 1 ≤ 𝑘𝑛3
Let k = 2
2𝑛3 − 7𝑛 + 1 ≤ 2𝑛3