This is the drill room for the parent topic . The parent gave you the definitions ; here we run them through every kind of situation a problem can throw at you , one worked case per cell, so you never meet an unfamiliar shape in an exam.
Before we start, one reminder of the three definitions we are going to apply (never assume — always earn):
Definition The three tools, in one place
f = O ( g ) : eventually 0 ≤ f ( n ) ≤ c g ( n ) — a ceiling (≤).
f = Ω ( g ) : eventually 0 ≤ c g ( n ) ≤ f ( n ) — a floor (≥).
f = Θ ( g ) : eventually 0 ≤ c 1 g ( n ) ≤ f ( n ) ≤ c 2 g ( n ) — both , so the growth is pinned (=).
"Eventually" means for all n ≥ n 0 . The constant c (or c 1 , c 2 ) hides the multiplication factor; n 0 hides small-n noise.
Every complexity-bound problem you will ever be asked is one of these cells . The examples below are labelled with the cell they close.
Cell
What it tests
Example
A. Polynomial + junk
Drop lower-order terms, keep the top
Ex 1
B. Ceiling holds, floor fails
O yes, Ω no → strictly smaller (o )
Ex 2
C. Floor holds, ceiling fails
Ω yes, O no → strictly larger (ω )
Ex 3
D. Log / non-polynomial shapes
log n , n log n ranking
Ex 4
E. The limit shortcut (all 3 outcomes: 0 , finite, ∞ )
L'Hôpital-style test
Ex 5
F. Degenerate / zero-ish input
constant f , g = 1 , or f ≡ 0
Ex 6
G. No single Θ exists
best ≠ worst in order
Ex 7
H. Word problem (real algorithm)
translate code → T ( n ) → bound
Ex 8
I. Exam twist (sum of unlike terms)
2 n vs n 100 , dominance
Ex 9
We cover all nine. Signs never go negative here (running times are ≥ 0 ), so our "quadrant" analogue is instead which term dominates and which of { 0 , finite , ∞ } the ratio lands on — those are the branches we must exhaust.
Worked example Ex 1 · Show
4 n 3 + 100 n 2 + 9 = Θ ( n 3 )
Forecast: guess the answer before reading. Which power wins as n → ∞ ? Write down c 1 , c 2 , n 0 in your head.
Upper (ceiling). For n ≥ 1 : 100 n 2 ≤ 100 n 3 and 9 ≤ 9 n 3 , so
4 n 3 + 100 n 2 + 9 ≤ 4 n 3 + 100 n 3 + 9 n 3 = 113 n 3 .
Why this step? Replacing each small term by an n 3 -sized term only makes the right side bigger , so the ≤ is guaranteed. This gives c 2 = 113 .
Lower (floor). All added terms are positive, so
4 n 3 + 100 n 2 + 9 ≥ 4 n 3 ( n ≥ 0 ) .
Why this step? Dropping positive stuff only shrinks the value, giving a clean floor. This gives c 1 = 4 .
Combine. 4 n 3 ≤ f ( n ) ≤ 113 n 3 for n ≥ 1 , which is exactly the Θ sandwich.
Verify: at n = 10 , f = 4000 + 10000 + 9 = 14009 ; check 4 ⋅ 1 0 3 = 4000 ≤ 14009 ≤ 113 ⋅ 1 0 3 = 113000 . ✓ Both sides straddle it, so f = Θ ( n 3 ) with c 1 = 4 , c 2 = 113 , n 0 = 1 . ∎
Worked example Ex 2 · Show
n log 2 n = O ( n 2 ) but not Ω ( n 2 )
Forecast: does n log n eventually stay under a scaled n 2 ? And could a floor c n 2 ever sit under n log n forever?
Ceiling. For n ≥ 2 , log 2 n ≤ n , so n log 2 n ≤ n ⋅ n = n 2 . Take c = 1 : this is O ( n 2 ) .
Why this step? log 2 n grows slower than n , so multiplying by n keeps us under n 2 .
Floor attempt. Suppose c n 2 ≤ n log 2 n for all large n . Divide by n > 0 : c n ≤ log 2 n .
Why this step? We isolate the shapes: the left grows linearly , the right logarithmically . A line eventually beats any log, so no fixed c > 0 survives.
Conclude. Ceiling yes, floor no ⇒ strictly smaller order : n log 2 n = o ( n 2 ) .
Verify: the limit lim n → ∞ n 2 n log 2 n = lim n log 2 n = 0 , confirming O not Ω . Sanity at n = 1024 : n log 2 n = 1024 ⋅ 10 = 10240 vs n 2 ≈ 1.05 × 1 0 6 — tiny in comparison. ✓ ∎
Look at the ratio curve in the figure: it slides toward 0 , never levelling off.
Worked example Ex 3 · Show
2 n = Ω ( n 10 ) but not O ( n 10 )
Forecast: exponential vs a big polynomial — who wins? (This is the classic exam trap: n 10 looks huge for small n .)
Small-n warning. At n = 10 : 2 10 = 1024 but 1 0 10 = 10 , 000 , 000 , 000 . The polynomial is way ahead here! Why mention this? It shows why n 0 matters — the true trend only appears later .
Floor. Eventually 2 n overtakes and stays above any constant times n 10 ; that crossover is our n 0 . So 2 n = Ω ( n 10 ) .
Ceiling fails. No constant c gives 2 n ≤ c n 10 for all large n , because the ratio n 10 2 n → ∞ . So not O .
Conclude: strictly larger order — 2 n = ω ( n 10 ) .
Verify: find the crossover n 0 where 2 n > n 10 first holds. Numerically it flips near n ≈ 59 (2 59 ≈ 5.76 × 1 0 17 vs 5 9 10 ≈ 5.11 × 1 0 17 ). At n = 59 the exponential has just won and never loses again. ✓ ∎
The figure shows the polynomial ahead early, then the exponential blasting past.
Worked example Ex 4 · Show
log 2 n = Θ ( log 10 n ) (base doesn't matter!)
Forecast: guess whether changing the log base changes the growth class .
Change-of-base. log 2 n = log 10 2 log 10 n .
Why this step? The change-of-base identity turns one log into a constant multiple of the other.
Read off the constant. l o g 10 2 1 ≈ 3.3219 . So log 2 n = 3.3219 ⋅ log 10 n — a pure constant factor.
Conclude. A constant factor is exactly what Θ ignores, so log 2 n = Θ ( log 10 n ) . This is why we write O ( log n ) with no base — every base is the same class.
Verify: log 2 1000 = 9.9658 and log 10 1000 = 3 ; ratio = 9.9658/3 = 3.3219 = 1/ log 10 2 . ✓ Constant, independent of n . ∎
Worked example Ex 5 · Classify each pair using
L = lim n → ∞ f / g
Forecast: for each row, predict whether L is 0 , finite-nonzero, or ∞ — then read the verdict.
Recall the rule from the parent (see Limits and L'Hôpital's rule ):
L = 0 ⇒ O not Ω (f = o ( g ) ),
0 < L < ∞ ⇒ Θ ,
L = ∞ ⇒ Ω not O (f = ω ( g ) ).
f = 3 n 2 + n , g = n 2 . L = lim n 2 3 n 2 + n = lim ( 3 + n 1 ) = 3 . Finite nonzero ⇒ Θ ( n 2 ) .
Why this step? Divide top and bottom by the dominant n 2 ; leftover n 1 → 0 .
f = n , g = n 2 . L = lim n 2 n = lim n 1 = 0 ⇒ n = o ( n 2 ) (ceiling only).
f = n 2 , g = n . L = lim n n 2 = lim n = ∞ ⇒ n 2 = ω ( n ) (floor only).
Verify: the three limits are 3 , 0 , and ∞ respectively — one from each branch, so we've exhausted the trichotomy. ✓ ∎
Worked example Ex 6 · The constant-cost and zero-cost edge cases
Forecast: what is the growth class of an algorithm that always does exactly 7 steps? And of one whose cost is literally 0 ?
Constant cost f ( n ) = 7 . Compare with g ( n ) = 1 . Floor: 7 ≥ 1 ⋅ 1 . Ceiling: 7 ≤ 7 ⋅ 1 . So c 1 = 1 , c 2 = 7 , and 7 = Θ ( 1 ) .
Why this step? Θ ( 1 ) is the formal way to say "constant time" — the reference g = 1 is the flat function.
Is 7 = Θ ( n ) ? No: the ratio n 7 → 0 , so 7 = o ( n ) (a constant is strictly smaller than any growing function).
Zero cost f ( n ) ≡ 0 . The definitions demand c g ( n ) ≤ f ( n ) i.e. c g ( n ) ≤ 0 . For a positive g and c > 0 this fails, so 0 is O ( g ) for any g but not Ω ( g ) unless g ≡ 0 .
Why this step? The "0 ≤ " guard in the definition is doing real work here — a genuinely zero function has no positive floor.
Verify: ratio 7/1 = 7 (finite nonzero → Θ ( 1 ) ✓); ratio 7/ n at n = 1000 is 0.007 → 0 (so o ( n ) ✓). ∎
Worked example Ex 7 · Insertion sort's whole runtime has no single
Θ
Forecast: best case is Θ ( n ) (already-sorted), worst is Θ ( n 2 ) (reverse-sorted). Can one Θ cover the whole runtime?
Best case. Already sorted: each element checks its left neighbour once — n − 1 comparisons = Θ ( n ) .
Worst case. Reverse sorted: element i shifts past all i predecessors — ∑ i = 1 n − 1 i = 2 n ( n − 1 ) = Θ ( n 2 ) .
Why this step? The triangular sum 2 n ( n − 1 ) is a degree-2 polynomial, hence Θ ( n 2 ) by Cell A logic.
Conclude. The runtime function ranges over an order gap (n up to n 2 ), so no single g pins it from both sides. We can only say the whole runtime is O ( n 2 ) and Ω ( n ) — not Θ of anything single. (See Best, worst, and average case analysis .)
Verify: worst-case comparisons at n = 5 : 2 5 ⋅ 4 = 10 ; best-case at n = 5 : n − 1 = 4 . Since 10 = c ⋅ 4 for a fixed c across all n (their ratio n − 1 n ( n − 1 ) /2 = 2 n → ∞ ), the two cases live in different orders. ✓ ∎
Worked example Ex 8 · Nested-loop counting
A function runs the inner line once for every pair ( i , j ) with 1 ≤ j ≤ i ≤ n :
for i in 1..n:
for j in 1..i:
work() # 1 unit
Forecast: guess the total number of work() calls as a function of n , and its Θ class.
Count exactly. Inner loop runs i times, so total T ( n ) = ∑ i = 1 n i = 2 n ( n + 1 ) .
Why this step? Sum of the first n integers — the same triangular formula, giving the exact call count.
Expand. 2 n ( n + 1 ) = 2 n 2 + 2 n . Top term is 2 1 n 2 .
Bound. Floor: 2 n 2 ≤ T ( n ) . Ceiling: T ( n ) ≤ 2 n 2 + 2 n 2 = n 2 for n ≥ 1 . So c 1 = 2 1 , c 2 = 1 .
Conclude: T ( n ) = Θ ( n 2 ) .
Verify (units + plug-back): work() calls are dimensionless counts. At n = 4 : T = 2 4 ⋅ 5 = 10 , and 2 16 = 8 ≤ 10 ≤ 16 = n 2 . ✓ ∎
Worked example Ex 9 · Show
n 100 + 2 n = Θ ( 2 n )
Forecast: a polynomial of degree 100 plus an exponential. Which one is the "shape," and which is junk?
Identify the dominant term. From Ex 3, 2 n = ω ( n k ) for any fixed k — including k = 100 . So 2 n dominates.
Why this step? Exponential beats every polynomial eventually; the huge degree 100 only delays n 0 , it never changes the class.
Floor. n 100 + 2 n ≥ 2 n (extra term positive), so c 1 = 1 .
Ceiling. For n ≥ n 0 where n 100 ≤ 2 n : n 100 + 2 n ≤ 2 n + 2 n = 2 ⋅ 2 n , so c 2 = 2 .
Why this step? Once the poly is below the exponential, the whole sum is under twice the exponential.
Conclude: 2 n ≤ f ( n ) ≤ 2 ⋅ 2 n ⇒ f = Θ ( 2 n ) .
Verify: find where n 100 ≤ 2 n takes hold — near n ≈ 1000 (since 100 log 2 n ≤ n requires n large). At n = 1000 : log 2 check 100 ⋅ log 2 1000 = 996.6 ≤ 1000 . ✓ So for n ≥ 1000 , 2 n ≤ f ≤ 2 ⋅ 2 n . ∎
Common mistake The trap in Cells C and I
"n 100 is bigger, so it's the dominant term." It feels right because 100 is enormous. The truth: dominance is about the limit of the ratio as n → ∞ , not about which is larger at n = 10 . 2 n n 100 → 0 , so the exponential wins in the end. Fix: always test the ratio's limit, never a single small n .
Recall Quick self-test — cover the answers
Which cell: 5 n 2 + 3 = Θ ( ?) ::: Θ ( n 2 ) (Cell A).
Which cell: lim f / g = ∞ tells you? ::: f = Ω ( g ) not O ( g ) , i.e. ω ( g ) (Cell C/E).
Does insertion sort have one Θ for its full runtime? ::: No — best Θ ( n ) , worst Θ ( n 2 ) (Cell G).
Class of a function that always costs 7 steps? ::: Θ ( 1 ) (Cell F).
Does the log base change the class? ::: No, log a n = Θ ( log b n ) (Cell D).