MCS-208 · Unit 1

Analysis of Algorithms

Section 2 of 8

Block 1 · Unit 1Analysis of Algorithms13 min · Section 2 of 8

1.2Asymptotic Notation: Big-O, Omega and Theta

Covers IGNOU MCS-208 §1.2

To compare growth rates we need a precise language. Big-O, Omega (Ω) and Theta (Θ) let us say “this function grows no faster than”, “no slower than” or “at the same rate as” another function, while ignoring constant factors and small inputs.

Big-O: an upper bound

In words: from n0n_0 onwards, ff never rises above cc times gg. The upper bound gg may be loose: 3n+43n + 4 is O(n)O(n), but also O(n2)O(n^2) and O(n3)O(n^3). We normally give the smallest (tightest) one.

Omega: a lower bound

In words: from n0n_0 onwards, ff never falls below cc times gg. This is a lower bound. For example, 3n+4≥3n3n + 4 \ge 3n for all n≥1n \ge 1, so 3n+4=Ω(n)3n + 4 = \Omega(n) with c=3c = 3, n0=1n_0 = 1.

Theta: a tight bound

Θ\Theta “sandwiches” ff between two multiples of gg. Then gg is called an asymptotically tight bound for ff: ff and gg grow at the same rate.

Graphs of Big-O, Omega and Theta bounds

Big-OOmega (Ω)Theta (Θ)
Kind of boundUpperLowerTight (both)
Inequality after n0n_0f≤c gf \le c\,gf≥c gf \ge c\,gc1g≤f≤c2gc_1 g \le f \le c_2 g
Rough analogyff ”≤” ggff ”≥” ggff ”=” gg
3n+43n + 4 is …O(n)O(n), O(n2)O(n^2), …Ω(n)\Omega(n), Ω(1)\Omega(1), …only Θ(n)\Theta(n)

Showing that a bound is false

To show f(n)≠O(g(n))f(n) \ne O(g(n)), assume constants exist and reach a contradiction.

O, Ω, Θ and the cases of an algorithm

Key takeaways

  • f=O(g)f = O(g): f≤c gf \le c\,g for all n≥n0n \ge n_0 (upper bound).
  • f=Ω(g)f = \Omega(g): f≥c gf \ge c\,g for all n≥n0n \ge n_0 (lower bound), with c>0c > 0.
  • f=Θ(g)f = \Theta(g): both at once; gg is a tight bound.
  • To prove a bound, find constants; to disprove it, show any constants lead to a contradiction.
  • The notations describe functions; worst, best and average case are separate functions.

Practice questions

Answer on paper first, then check. The explanation matters more than the letter you chose.

Question 1 · multiple choice

To prove 5n+20=O(n)5n + 20 = O(n) with c=6c = 6, what is the smallest valid n0n_0?

Show answer

Answer: D. 20

5n+20≤6n5n + 20 \le 6n means 20≤n20 \le n, so n0=20n_0 = 20. With n0=4n_0 = 4 the check fails, e.g. 5(4)+20=40>245(4) + 20 = 40 > 24.

Question 2 · multiple choice

Which statement is false?

Show answer

Answer: B. n2=O(n)n^2 = O(n)

n2≤c nn^2 \le c\,n would mean n≤cn \le c for all large nn, which is impossible. n=O(n2)n = O(n^2) is true because Big-O may be a loose upper bound.

Question 3 · multiple choice

Which function is in Ω(n2)\Omega(n^2)?

Show answer

Answer: C. n3n^3

n3≥1⋅n2n^3 \ge 1 \cdot n^2 for all n≥1n \ge 1, so n3=Ω(n2)n^3 = \Omega(n^2). 100n100n is smaller than n2n^2 once n>100n > 100, so it is not Ω(n2)\Omega(n^2).

Question 4 · multiple choice

If f(n)=O(n2)f(n) = O(n^2) and f(n)=Ω(n2)f(n) = \Omega(n^2), then:

Show answer

Answer: A. f(n)=Θ(n2)f(n) = \Theta(n^2)

By the theorem, Big-O and Omega with the same gg together give Theta.

Question 5 · multiple choice

The worst-case running time of insertion sort is Θ(n2)\Theta(n^2). Which statement is correct?

Show answer

Answer: C. Its worst case is both O(n2)O(n^2) and Ω(n2)\Omega(n^2).

Θ means both bounds hold. The notations describe any function, including the worst-case function. Ω(n3)\Omega(n^3) is false because n2n^2 is eventually smaller than c n3c\,n^3.

Question 6 · short answer

Prove that 2n2+3n=Θ(n2)2n^2 + 3n = \Theta(n^2) by finding c1c_1, c2c_2 and n0n_0.

Show worked answer

Lower bound: 2n2≤2n2+3n2n^2 \le 2n^2 + 3n for all n≥1n \ge 1, so c1=2c_1 = 2. Upper bound: 3n≤3n23n \le 3n^2 for n≥1n \ge 1, so 2n2+3n≤2n2+3n2=5n22n^2 + 3n \le 2n^2 + 3n^2 = 5n^2, giving c2=5c_2 = 5. Hence 2n2≤2n2+3n≤5n22n^2 \le 2n^2 + 3n \le 5n^2 for all n≥1n \ge 1, so 2n2+3n=Θ(n2)2n^2 + 3n = \Theta(n^2) with c1=2c_1 = 2, c2=5c_2 = 5, n0=1n_0 = 1.

↑ ↓ move↵ openTab switch type