Asymptotic Notations

Download as pdf or txt
Download as pdf or txt
You are on page 1of 37

Lecture 2

Asymptotic Notations
Big-‐Oh: English Definition

• Let T(n) = function on n = 1,2,3,…


[usually, the worst-‐case running time of an algorithm]

Q : When is T(n) = O(f(n)) ?


A : if eventually (for all sufficiently large n), T(n) is bounded
above by a constant multiple of f(n)
Big O Notation
• The running time grows at most this much, but it could grow more
slowly

• 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 .

• We use big-O notation for asymptotic upper bounds, since it bounds


the growth of the running time from above for large enough input
sizes.
Big O Notation
T(n) = O(f(n)) if an only if there exist constants
k and n0 such that T(n) < k.f(n) for all
n > n0
• Chicken grows slower than turkey,
or chicken size is in O(turkey size).
What it really means:
• Baby chicken might be larger than
baby turkey at the beginning.
• But after certain “breakpoint”, the
chicken size will be surpassed by
the turkey size.
• From the breakpoint on, the
chicken size will always be
smaller than the turkey size.
Big O Example
Big-Ω (Big-Omega) notation
T(n) = Ω(f(n)) if an only if there exist constants
k and n0 such that T(n) ≥ k.f(n) for all
n > n0
Big-Ω Example
Big-Ω Example
Theta Notation Θ(n)
• Once n gets large enough, the running time is at least k1.n and at
most k2⋅n for some constants k1 and k2
Theta Notation Θ(n)
T(n) = Θ (f(n)) if an only if there exist constants
k1, k2 and n0 such that k1.f(n) ≤T(n) ≤ k2.f(n) for all
n > n0
Theta Notation Θ(n)
Θ (Theta) Example
Theta Notation Θ(n)

• asymptotically tight bound on the running time.


• "Asymptotically" because it matters for only large values of n
• "Tight bound" because we've nailed the running time to within a
constant factor above and below.
Asymptotic Notations
• Big-Oh, Big-Omega, Big-Theta4
• O( f(n) ): The set of functions that grows no faster than f(n)
• asymptotic upper-bound on growth rate
• Ω( f(n) ): The set of functions that grows no slower than f(n)
• asymptotic lower-bound on growth rate
• Θ( f(n) ): The set of functions that grows no faster and no slower
than f(n)
• asymptotic tight-bound on growth rate
Asymptotic Notations

• All three (Omega, O, Theta) give only asymptotic information ("for


large input"):
• Big O gives upper bound
• Big Omega gives lower bound and
• Big Theta gives both lower and upper bounds
• Note that this notation is not related to the best, worst and average
cases analysis of algorithms. Each one of these can be applied to each
analysis.
Asymptotic Analysis
Big-‐Oh: Basic Examples
Example 1
Let . Which of the following statements are true?
Check all that apply.
a) T(n) = O(n)
b) T(n) = Ω (n)
c) T(n) = Θ (n2)
d) T(n) = O (n3)
Example 1
Let . . Which of the following statements are true?
Check all that apply.
a) T(n) = O(n)
b) T(n) = Ω (n) , [ n0 = 1 , c = 1/2 ]
c) T(n) = Θ (n2) , [ n0 = 1 , c1 = 1/2 , c2 = 4]
d) T(n) = O (n3) , [ n0 = 1 , c = 4 ]

b, c, d are correct
Example 1
Let . . Which of the following statements are true?

(a) T(n) = O(n)

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?

(b) T(n) = Ω (n)

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?

(c) T(n) = Θ (n2)

1 2
𝑐1 𝑛 ≤ 𝑛 + 3𝑛 ≤ 𝑐2 𝑛
2
1
𝑐1 ≤ 𝑛 + 3 ≤ 𝑐2 This holds for c1 =1/2 , 𝑐2 = 4and 𝑛 ≥
2
𝑛0 , 𝑛0 = 1
Example 2

Which of the following is correct?

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

Which of the following is correct?

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

Which of the following is correct?

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

Which of the following is correct?

a) n3log2n is Θ (3nlog8 n)
b) n3log2n is O (3nlog8 n)
c) n3log2n is Ω (3nlog8 n)
Example 3

Which of the following is correct?

a) n3log2n is Θ (3nlog8 n)
b) n3log2n is O (3nlog8 n)
c) n3log2n is Ω (3nlog8 n)

C is correct
Example 4

Which of the following is correct?

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

Option c is correct for constant c = 1 and n0 =1


2𝑛 ≥ 𝑐
Example 5
𝑛+10 𝑛
Claim 2 =𝑂 2 Is it True or False?
Example 5
𝑛+10 𝑛
Claim 2 = 𝑂 (2 )

Proof: we need to pick constants 𝑐, 𝑛0 such that

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𝑛 )

Proof: By contradiction. If 210𝑛 = 𝑂 (2𝑛 ) then there exist constants 𝑐, 𝑛0 >


0 such that

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

𝑛0 = 1, 𝑘 = 2 since 1-7n will be negative for n ≥ 1

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy