Intuition What this page is
The parent note taught you the definition of Big-O: find a multiplier c > 0 and a threshold n 0 ≥ 0 so that 0 ≤ f ( n ) ≤ c g ( n ) for every n ≥ n 0 . This page is the drill hall . We enumerate every kind of case Big-O proofs come in, then work each one to the ground — so when an exam or a code review throws a function at you, you have already met its species.
If any symbol here feels unfamiliar, revisit the parent definition first — we do not re-derive the definition, we exercise it.
Before solving, let us name the shapes of problem that exist. Every worked example below is tagged with the cell it hits.
Cell
Case class
What makes it different
Example that covers it
A
Linear + constant
Small term absorbed into big term
Ex 1
B
Polynomial, several terms
Push every low power up to the top
Ex 2
C
Loose upper bound (true but not tight)
f grows strictly slower than g
Ex 3
D
Disproof (no c , n 0 exist)
Ratio → ∞ , contradiction
Ex 4
E
Degenerate / zero-ish input
g ( n ) = 0 somewhere, or f constant
Ex 5
F
Logarithm & log-vs-power
New tool: log n grows slower than any n ε
Ex 6
G
Exponential vs polynomial (limiting)
Growth-rate showdown at infinity
Ex 7
H
Real-world word problem
Translate code/story into f ( n )
Ex 8
I
Exam twist (sum & product rules)
Combine two bounds correctly
Ex 9
The figure above is the map we return to in Ex 3 : any curve above f is a valid Big-O ceiling. The tight ceiling (O ( n ) , chalk-blue) hugs f with a gap that stays proportional ; the loose ceiling (O ( n 2 ) , chalk-pink) sits above f with a gap that explodes . Both are true Big-O statements — that is the whole subtlety this page drills. Look at how the pink gap widens in the figure while the blue gap does not; that picture is the difference between "loose" and "tight."
6 n + 20 = O ( n )
Forecast: Guess a value of c before reading on. (Hint: it will be a little bigger than 6 .)
Goal: find c > 0 , n 0 ≥ 0 with 6 n + 20 ≤ c n for all n ≥ n 0 .
Step 1 — trap the constant term under the linear term.
Why this step? The definition lets us pick any threshold n 0 . If we insist n ≥ 20 , then 20 ≤ n , and now the annoying constant 20 is bounded by something proportional to n — which is what we need, because the right-hand side c n is also proportional to n .
6 n + 20 ≤ 6 n + n = 7 n ( n ≥ 20 ) .
Step 2 — read off the constants.
Why this step? The right side is now literally 7 ⋅ n = c g ( n ) with g ( n ) = n . We just match the pattern.
c = 7 , n 0 = 20.
Verify: Plug n = 20 : left = 6 ( 20 ) + 20 = 140 , right = 7 ( 20 ) = 140 . Equal — the bound just holds at the threshold. For n = 100 : left = 620 , right = 700 , and 620 ≤ 700 . ✓
(Other choices work too — e.g. c = 26 , n 0 = 1 gives 6 ( 1 ) + 20 = 26 ≤ 26 ( 1 ) . You only need one.)
4 n 3 + 10 n 2 + 100 = O ( n 3 )
Forecast: How big must c be? Add up all the coefficients-after-flattening and guess.
Goal: 4 n 3 + 10 n 2 + 100 ≤ c n 3 for n ≥ n 0 .
Step 1 — lift every lower power up to n 3 .
Why this step? n 3 is the tallest term. For n ≥ 5 each smaller piece is dominated by n 3 : since n 2 ≤ n 3 we get 10 n 2 ≤ 10 n 3 ; and since 100 ≤ n 3 whenever n 3 ≥ 100 , i.e. n ≥ 5 (because 5 3 = 125 ≥ 100 ), the constant is capped too.
4 n 3 + 10 n 2 + 100 ≤ 4 n 3 + 10 n 3 + n 3 = 15 n 3 ( n ≥ 5 ) .
Step 2 — read off constants.
c = 15 , n 0 = 5.
Verify: At n = 5 : left = 4 ( 125 ) + 10 ( 25 ) + 100 = 500 + 250 + 100 = 850 ; right = 15 ( 125 ) = 1875 , and 850 ≤ 1875 . ✓
Lesson (Cell B rule): a degree-d polynomial is always O ( n d ) — flatten every term onto the top power, sum the coefficients for c .
7 n + 5 = O ( n 2 ) and explain why it is loose
Forecast: Is this true ? Is it tight ? Answer both before reading.
Goal: 7 n + 5 ≤ c n 2 for n ≥ n 0 .
Step 1 — bound each term by n 2 .
Why this step? We are aiming at a bigger ceiling (n 2 , not n ), so the algebra is even easier — anything linear or constant is eventually swamped by a square. For n ≥ 1 : 7 n ≤ 7 n 2 and 5 ≤ 5 n 2 .
7 n + 5 ≤ 7 n 2 + 5 n 2 = 12 n 2 ( n ≥ 1 ) .
Step 2 — read off constants.
c = 12 , n 0 = 1.
Step 3 — why is this loose ?
Why this step? "Loose" means f grows strictly slower than the ceiling g . This is exactly the chalk-pink curve in the map figure (s01): the ratio n 2 7 n + 5 → 0 as n → ∞ — the gap between f and c g widens forever (watch the pink gap explode in that figure). A tight bound (where the ratio stays bounded away from 0 , the chalk-blue O ( n ) curve) would be the tightest honest ceiling. So 7 n + 5 = O ( n 2 ) is true but wasteful; it belongs to the "true but not tight" cell. For tight bounds you use Big-Theta notation — tight bound .
Verify: At n = 1 : left = 12 , right = 12 ( 1 ) = 12 , equal. At n = 10 : left = 75 , right = 1200 — enormous slack, exactly the looseness. ✓
n 3 = O ( n 2 )
Forecast: Do you expect this to hold? (A cube versus a square...) Decide, then prove your instinct.
Suppose (for contradiction) it held: there would exist c > 0 , n 0 with n 3 ≤ c n 2 for all n ≥ n 0 .
Step 1 — divide out the common power.
Why this step? Both sides carry n 2 . For n > 0 we can divide safely (dividing by a positive number keeps the inequality direction). This isolates the growing part.
n 3 ≤ c n 2 ⟹ n ≤ c ( n > 0 ) .
Step 2 — hit it with n → ∞ .
Why this step? c is a fixed constant, chosen once. But n is allowed to grow without bound. The instant n > c (say n = ⌈ c ⌉ + 1 ), the inequality n ≤ c is false — yet the definition demanded it hold for all n ≥ n 0 . Contradiction.
∴ n 3 = O ( n 2 ) .
Verify: Take any candidate, e.g. c = 1000 . It fails at n = 1001 : 100 1 3 = 1.003 × 1 0 9 vs 1000 ⋅ 100 1 2 = 1.002 × 1 0 9 — the cube has overtaken. No finite c survives. ✓
Disproof recipe: show g ( n ) f ( n ) → ∞ ; then no constant ceiling can exist. (Formally this is a limit argument — see Limits and infinity (Calculus) .)
Worked example Two edge cases: (a)
f ( n ) = 42 constant; (b) careful with g ( n ) that can be 0
Forecast: Is a constant function O ( 1 ) ? And can we write O ( n 2 ) if g is ever zero?
Part (a): show 42 = O ( 1 ) .
Why this matters: g ( n ) = 1 is the "flat" function — being O ( 1 ) means "cost doesn't grow at all." A constant-time algorithm lives here.
Step 1. We need 42 ≤ c ⋅ 1 for n ≥ n 0 . Choose c = 42 (or anything ≥ 42 ) and n 0 = 0 .
Why: 42 ≤ 42 holds for every n , so no threshold is even needed.
c = 42 , n 0 = 0.
Part (b): the zero-input trap.
Why this step? The definition demands 0 ≤ f ( n ) ≤ c g ( n ) . If g ( n bad ) = 0 at some point inside our allowed range while f ( n bad ) > 0 , the bound f ≤ c ⋅ 0 = 0 is impossible there. This is exactly why n 0 exists: we push the threshold past the degenerate point.
Example: is n = O ( n 2 ) ? At n = 0 , g ( 0 ) = 0 but f ( 0 ) = 0 too, so 0 ≤ 0 holds. Take c = 1 , n 0 = 1 : for n ≥ 1 , n ≤ n 2 . ✓ The one dangerous point (n = 0 ) is harmless here because f ( 0 ) = 0 as well.
Rule: if f is positive where g is zero, raise n 0 above that point — that is the degenerate-input fix.
Verify: (a) at n = 1 0 6 , 42 ≤ 42 . ✓ (b) at n = 1 : 1 ≤ 1 ; at n = 2 : 2 ≤ 4 . ✓
log 2 n = O ( n ) , and note n = O ( n log 2 n )
Forecast: Does log n grow slower or faster than n ? Picture the two curves before deciding.
Why the tool "logarithm"? A logarithm answers "how many times must I double to reach n ?" — it is the inverse of exponentiation. It shows up whenever an algorithm halves its problem each step (binary search, balanced trees). It grows, but agonisingly slowly.
Step 1 — the key fact: log 2 n ≤ n for all n ≥ 1 .
Why this step? We need a clean, provable comparison. The clean route is to prove n ≤ 2 n for all n ≥ 1 by induction , then take log 2 of both sides.
Base case n = 1 : 1 ≤ 2 1 = 2 . ✓
Inductive step: assume n ≤ 2 n . Then n + 1 ≤ 2 n + 1 ≤ 2 n + 2 n = 2 n + 1 , where the middle step uses 1 ≤ 2 n (true for n ≥ 1 ). So the claim holds for n + 1 . By induction n ≤ 2 n for all n ≥ 1 .
Now log 2 is an increasing function, so applying it to n ≤ 2 n preserves the direction:
log 2 n ≤ log 2 ( 2 n ) = n = 1 ⋅ n ( n ≥ 1 ) .
c = 1 , n 0 = 1.
Step 2 — the companion loose fact n = O ( n log 2 n ) .
Why this step? Since log 2 n ≥ 1 once n ≥ 2 , multiplying n by something ≥ 1 only makes it bigger: n ≤ n log 2 n . So c = 1 , n 0 = 2 .
Verify: log 2 16 = 4 ≤ 16 . ✓ At n = 4 : log 2 4 = 2 , so n log 2 n = 8 ≥ 4 = n . ✓
Ordering to memorise (Asymptotic growth rates ordering ): 1 ≺ log n ≺ n ≺ n log n ≺ n 2 ≺ 2 n .
2 n = O ( n 10 )
Forecast: Exponential or polynomial — which wins the race to infinity? Bet now.
Why a limit argument here? When both sides grow without bound, comparing them term-by-term is hopeless. The clean tool is the ratio at infinity : if g ( n ) f ( n ) → ∞ , then no constant ceiling c can hold f under c g forever. See Limits and infinity (Calculus) .
Step 1 — form the ratio.
Why this step? Big-O caps f / g by a constant c for large n . So we test whether f / g stays bounded.
R ( n ) = n 10 2 n .
Step 2 — show R ( n ) → ∞ .
Why this step? Exponentials beat polynomials because each + 1 in n multiplies 2 n by 2 , while it only nudges n 10 upward by a shrinking factor. Concretely, 2 n / n 10 → ∞ : for large n the numerator's doubling outruns any fixed power. (One can prove it by comparing ln R ( n ) = n ln 2 − 10 ln n ; the linear term n ln 2 dominates 10 ln n , so ln R → + ∞ , hence R → ∞ .)
Step 3 — conclude no c exists.
Since R ( n ) eventually exceeds every constant c , there is no valid pair ( c , n 0 ) .
2 n = O ( n 10 ) .
Verify: At n = 100 : 2 100 ≈ 1.27 × 1 0 30 while 10 0 10 = 1 0 20 ; the ratio is ≈ 1 0 10 , already gigantic and still climbing. ✓
Conversely n 10 = O ( 2 n ) — polynomials are Big-O of exponentials (the ceiling is huge but real).
Worked example Nested loop cost
A function scans every pair of items in a list of n items, then does 3 constant-cost checks per pair, plus a one-time setup of 50 operations. Its step count is
f ( n ) = 3 ⋅ ( 2 n ) + 50 = 2 3 n ( n − 1 ) + 50 = 1.5 n 2 − 1.5 n + 50.
Show f ( n ) = O ( n 2 ) .
Forecast: What is the shape — linear, quadratic, or worse? Guess from "every pair."
Step 1 — expand and identify the dominant term.
Why this step? "Every pair" of n items is ( 2 n ) = 2 n ( n − 1 ) — quadratic. So the tallest term is 1.5 n 2 ; the − 1.5 n actually helps (it subtracts), and + 50 is a constant.
Step 2 — bound above.
Why this step? Dropping the negative term only makes f larger, so f ( n ) ≤ 1.5 n 2 + 50 . Then we need 50 ≤ n 2 , which holds precisely for n ≥ 8 (since 8 2 = 64 ≥ 50 while 7 2 = 49 < 50 ). Use n 0 = 8 :
f ( n ) ≤ 1.5 n 2 + 50 ≤ 1.5 n 2 + n 2 = 2.5 n 2 ( n ≥ 8 ) .
c = 2.5 , n 0 = 8.
Verify: At n = 8 : f ( 8 ) = 1.5 ( 64 ) − 1.5 ( 8 ) + 50 = 96 − 12 + 50 = 134 ; ceiling = 2.5 ( 64 ) = 160 , and 134 ≤ 160 . ✓
Interpretation: doubling the list roughly quadruples the work — the signature of a nested-pair (quadratic) algorithm. This is a time-complexity statement about the code's steps.
f 1 ( n ) = O ( n 2 ) and f 2 ( n ) = O ( n log 2 n ) , bound f 1 ( n ) + f 2 ( n ) and f 1 ( n ) ⋅ f 2 ( n )
Forecast: For the sum, which term "wins"? For the product, do exponents add or multiply?
Step 1 — the sum: bigger term wins.
Why this step? The sum rule says O ( a ) + O ( b ) = O ( max ( a , b )) . Compare n 2 against n log 2 n : dividing, n log 2 n n 2 = log 2 n n → ∞ , so n 2 dominates. Hence
f 1 + f 2 = O ( n 2 ) .
Concretely: if f 1 ≤ c 1 n 2 and f 2 ≤ c 2 n log 2 n ≤ c 2 n 2 (using Ex 6's log 2 n ≤ n ), then f 1 + f 2 ≤ ( c 1 + c 2 ) n 2 .
Step 2 — the product: multiply the ceilings.
Why this step? The product rule: if f 1 = O ( g 1 ) and f 2 = O ( g 2 ) then f 1 f 2 = O ( g 1 g 2 ) . Multiply the bounds directly:
f 1 f 2 ≤ ( c 1 n 2 ) ( c 2 n log 2 n ) = c 1 c 2 n 3 log 2 n .
f 1 ⋅ f 2 = O ( n 3 log 2 n ) .
Verify (numeric sanity, using f 1 = n 2 , f 2 = n log 2 n ): at n = 4 : f 1 = 16 , f 2 = 4 ⋅ 2 = 8 . Sum = 24 ≤ c ⋅ 16 with c = 2 (= 32 ). ✓ Product = 128 , and n 3 log 2 n = 64 ⋅ 2 = 128 , so 128 ≤ 1 ⋅ 128 . ✓
Recall Which cell needs a
raised n 0 and why?
Cell E (degenerate). If f ( n ) > 0 where g ( n ) = 0 , the bound f ≤ c ⋅ 0 is impossible there, so push n 0 past that point. ::: Raise the threshold above any degenerate input.
Recall Disproof recipe in one line
Show the ratio f ( n ) / g ( n ) → ∞ ; then no constant c can cap f under c g . ::: Ratio diverges ⇒ not Big-O.
Recall Sum rule vs product rule
For the sum, keep the maximum term (O ( n 2 ) + O ( n log n ) = O ( n 2 ) ). For the product, multiply the two ceilings (O ( n 2 ) ⋅ O ( n log n ) = O ( n 3 log n ) ). ::: Max for sums, multiply for products.
"Flatten up, or race to infinity." Proving a bound? Flatten every lower term onto the top power. Disproving? Race the ratio to ∞ .
Parent: Big-O — formal definition (mathematical)
Big-Omega notation — lower bound
Big-Theta notation — tight bound
Little-o and little-omega
Asymptotic growth rates ordering
Time Complexity vs Space Complexity
Master Theorem
Limits and infinity (Calculus)
Flatten lower terms onto top power
Product rule multiply ceilings