Big-O is the most widely used asymptotic notation. This page gives its precise definition, a reliable method for proving f(n)=O(g(n)) by finding constants, the method for proving that a function is notO(g(n)), and fully worked answers to the Big-O parts of Check Your Progress 2.
Definition
O(g(n)) is really a set of functions — all functions that grow at most as fast as g, up to a constant factor — and "f(n)=O(g(n))" means ”f(n) belongs to that set”. The "=" here is one-way: n=O(n2) is true but "O(n2)=n" is not a sensible statement.
Proving f(n)=O(g(n))
A method that always works for polynomials:
Write the inequality f(n)≤c⋅g(n) you need.
Drop negative terms of f(n) (this only makes the left side bigger).
Raise each remaining lower power to the power of g, using nj≤nm for n≥1 and j≤m.
Add the coefficients to get c; take n0=1.
Proving f(n)=O(g(n))
Assume the opposite — that some c and n0 exist — and show the inequality fails for some large n. That is a contradiction.
Check Your Progress 2: the Big-O parts
(a) 4n2+7n+12=O(n2) — true. For n≥1: 4n2+7n+12≤4n2+7n2+12n2=23n2. So c=23, n0=1. With the smaller constant c=5 we need n2−7n−12≥0, i.e. n≥27+97≈8.42, so n0=9.
Python · find_n0.py
def smallest_n0(f, g, c, limit=100000): """Smallest n0 such that f(n) <= c*g(n) for every n from n0 to limit.""" n0 = None for n in range(limit, 0, -1): if f(n) <= c * g(n): n0 = n else: break return n0sq = lambda n: n * nprint("4n^2+7n+12 <= 5n^2 from n0 =", smallest_n0(lambda n: 4*n*n + 7*n + 12, sq, 5))print("4n^2+7n+12 <= 23n^2 from n0 =", smallest_n0(lambda n: 4*n*n + 7*n + 12, sq, 23))print("3n^2+4n-2 <= 5n^2 from n0 =", smallest_n0(lambda n: 3*n*n + 4*n - 2, sq, 5))print("3n^2+4n-2 <= 7n^2 from n0 =", smallest_n0(lambda n: 3*n*n + 4*n - 2, sq, 7))
Output
4n^2+7n+12 <= 5n^2 from n0 = 94n^2+7n+12 <= 23n^2 from n0 = 13n^2+4n-2 <= 5n^2 from n0 = 13n^2+4n-2 <= 7n^2 from n0 = 1
(b) logn+log(logn)=O(logn) — true. Use base 2. For n≥2, log2n≥1, and since log2x≤x for all x≥1, we get log2(log2n)≤log2n. Hence log2n+log2log2n≤2log2n for all n≥2: c=2, n0=2.
(d) 2n+1=O(2n) — true.2n+1=2⋅2n, so c=2, n0=1 (equality holds).
(e) 22n=O(2n) — false.22n=4n. If 4n≤c⋅2n for all n≥n0, dividing by 2n gives 2n≤c for all large n, which is impossible because 2n grows without bound.
(f) f(n)=O(g(n)) implies g(n)=O(f(n)) — false. Counterexample: n=O(n2), but n2=O(n) (same argument as n3=O(n2)).
(h) f(n)=O(g(n)) implies 2f(n)=O(2g(n)) — false. Counterexample: f(n)=2n, g(n)=n. Then 2n=O(n), but 22n=4n=O(2n) by (e).
Key takeaways
f(n)=O(g(n)) iff there are c>0, n0 with 0≤f(n)≤cg(n) for all n≥n0.
For polynomials: drop negative terms, raise lower powers, add coefficients.
To disprove, show that f(n)/g(n) cannot stay below any constant.
Big-O is an upper bound on a function, not a synonym for “worst case”.
Practice questions
Answer on paper first, then check. The explanation matters more than the letter you chose.
Question 6 · short answer
Prove that n2=O(n).
Show worked answer
Suppose there are constants c > 0 and n₀ with n² ≤ c·n for all n ≥ n₀. Dividing by n > 0 gives n ≤ c for all n ≥ n₀. Take n = max(n₀, ⌈c⌉ + 1): then n ≥ n₀ and n > c, a contradiction. Hence no such constants exist and n² ≠ O(n).
MCA Online notes are made for reading on screen. Open https://mcastudy.online/mcs-211/some-pre-requisites-and-asymptotic-bounds/big-o-notation-upper-bounds/ to read this page.