Discrete MathematicsAlgorithms and Growth of Functions1 of 4
Algorithms and Growth of Functions · 1
Big O, Big Omega and Big Theta
We need a way to compare how fast functions grow when the input n gets large, without getting distracted by small inputs or minor terms.
Long-Term Growth of Functions
For small inputs like n=1 or n=2,f(n)=3n2+10n+50 is larger than g(n)=n3, but by n=1,000,n3 is hundreds of times larger:
leading shape n23n2+minor terms10n+50vs.n3
To compare the long-term growth shapes of functions rather than single values, we use three comparisons: Big O(≤, a ceiling), Big Omega(≥, a floor), and Big Theta(=, a matching floor and ceiling).
1
Big O and Witnesses
Big O puts a ceiling on a function's long-term growth: f(n) is O(g(n)) when some positive constant multiple C⋅g(n) stays at or above f(n) from some starting point n=k onward.
f(n) is O(g(n))means∃witnessesC>0,k>0∀n≥k,f(n)≤ceilingC⋅g(n)
To prove that f(n)=3n2+10n+50 is O(n2), we need to find a working pair of witnesses C and k.
Big O and Witnesses
Text solution
Trade smaller powers up to n2For all n≥1, multiplying a positive term by n or n2 never makes it smaller, so 10n≤10n2 and 50≤50n2.
Read off the witnessesSince 3n2+10n+50≤63n2 for all n≥1,f(n) is O(n2) with witnesses C=63 and k=1.
Witnesses are never unique. Any multiplier C>3 makes C⋅n2 overtake 3n2+10n+50: a larger multiplier C crosses above the curve at a smaller starting point k, and a multiplier closer to 3 pushes the crossing point k further to the right.
Any steeper parabola eventually rises above the curve and stays on top, and making it flatter only pushes that crossing point further to the right.
2
Loose Ceilings and Disproving Big O
Because Big O only requires a ceiling (≤), any faster-growing shape is also a valid upper bound for 3n2+10n+50, whereas a slower-growing shape like n2 can never stay above n3.
Loose Ceilings and Disproving Big O
3n2+10n+50n3isO(n3)?isO(n2)?
Since n2≤n3 for all n≥1, our 63n2 ceiling sits underneath 63n3, making n3 a loose ceiling for 3n2+10n+50:
3n2+10n+50≤63n2≤63n3(for n≥1)
Going the other way fails: to prove that n3 is notO(n2), we negate the definition and show that n3 grows past every proposed ceiling C⋅n2.
Text solution
Negate the Big O definitionWe must show that for every C>0 and every k>0, there is some n≥k where n3>C⋅n2.
Cancel the shared n2 factorFor n>0, dividing both sides by n2 simplifies the inequality to n>C.
n⋅n2n>C⋅n2>C
Pick n past both k and CGiven any C>0 and k>0, choose n=max(k,C)+1; then n≥k and n>C, so n3>C⋅n2.
No matter how high the multiplier C stretches the parabola C⋅n2, it only delays the crossing point to n=C, where n3 catches up and stays above C⋅n2 for all larger n.
Stretching a quadratic ceiling higher only delays the crossing point, because the cubic curve always catches up and stays above it forever.
3
Big Omega and Big Theta
Big Omega (Ω) puts a floor underneath a function to say it grows at least as fast as g(n), and Big Theta (Θ) traps a function between a floor and a ceiling of the same shape g(n).
f(n) is Ω(g(n))means∃C>0,k>0∀n≥k,f(n)≥floorC⋅g(n)f(n) is Θ(g(n))meansf(n) is both Ω(g(n)) and O(g(n))
Let's find a Big Ω(n2) floor first when the lower-order terms are added, and then when a lower-order term is subtracted, as in 3n2−10n.
Big Omega and Big Theta
Big OBig Ω≤≥ceilingfloor
3n2+10n+50 is Ω(n2)?
For 3n2+10n+50, the extra terms +10n+50 are positive for all n≥1, so dropping them immediately gives a floor:
3n2+10n+50≥3n2(for n≥1, so C=3,k=1)
When a lower-order term is subtracted, as in 3n2−10n, dropping −10n would make the expression larger instead of smaller, so we replace −10n with −n2 once n is large enough that n2≥10n.
Text solution
Find where n2≥10nComparing n⋅n with 10n shows that n2≥10n, or −10n≥−n2, for all n≥10.
Replace −10n with −n2Subtracting n2 instead of 10n can't make the expression larger for n≥10, and it leaves like terms.
3n2−10n≥3n2−n2(for n≥10)=2n2
Read off the witnessesSince 3n2−10n≥2n2 for all n≥10,3n2−10n is Ω(n2) with witnesses C=2 and k=10.
Combining the floor and ceiling for 3n2+10n+50 traps it between two n2 parabolas from n=1 onward, proving it is Θ(n2):
3n2≤3n2+10n+50≤63n2(for n≥1)
4
The Ladder of Growth
When logarithms, polynomials, exponentials, and factorials appear in the same function, the ladder of growth shapes tells us which term dominates as n grows.
The Ladder of Growth
Ordered from slowest growth at the bottom to fastest growth at the top, each rung eventually overtakes every rung below it:
All logarithms share a single rung because changing the base only multiplies the function by a fixed constant:
log2n=log102log10n=≈3.32 (constant)(log1021)⋅log10n⟹log2n is Θ(log10n)
Exponentials with different bases sit on different rungs because factoring 2n out of 3n leaves a factor that grows to infinity rather than staying below a constant C:
3n=(1.5×2)n=→∞(1.5)n⋅2n⟹3n is not O(2n)
Multiplying log10n by C=log1021≈3.32 makes it match log2n everywhere, whereas 3n always grows faster and pulls away from C⋅2n no matter how large C is.
A simple vertical stretch makes one log curve match another everywhere, while the steeper exponential always breaks through any stretch of the slower one.
5
Witnesses Across the Ladder
When a function mixes terms from different rungs of the ladder, trading smaller terms up uses an inequality between the two families, and we set the starting point k to where that inequality begins to hold.
Witnesses Across the Ladder
First, let's prove that f(n)=5n2+20nlog2n+100 is O(n2).
Text solution
Trade log2n up to nSince log2n≤n for all n≥1, multiplying both sides by 20n turns the middle term into an n2 term.
log2n20nlog2n≤n(for n≥1)≤20n⋅n=20n2
Trade the constant up and add like termsUsing 100≤100n2 for n≥1 puts all three terms into n2.
5n2+20nlog2n+100≤5n2+20n2+100n2(for n≥1)=125n2
Read off the witnessesf(n) is O(n2) with C=125 and k=1.
Now let's prove that f(n)=10n2+2n is Θ(2n) by finding witnesses for both the floor and the ceiling.
Text solution
Drop 10n2 for the Ω(2n) floorSince 10n2>0 for all n≥1, dropping it gives witnesses C1=1 and k1=1.
10n2+2n≥1⋅2n(for n≥1)
Find where n2≤2n stays trueAt n=3,32=9>23=8, so n2 is briefly larger than 2n before n2≤2n holds from n=4 onward (42=16≤24=16).
Trade 10n2 up to 10⋅2n from n=4 onwardStarting at k2=4, replace n2 with 2n to get ceiling multiplier C2=11.
10n2+2n≤10⋅2n+2n(for n≥4)=11⋅2n
Combine the floor and ceilingBoth bounds hold for all n≥4, proving 10n2+2n is Θ(2n).
1⋅2n≤10n2+2n≤11⋅2n(for n≥4)
6
Sums and Products of Functions
When a function multiplies factors together, we can bound each factor on its own and multiply the results, allowing us to find the growth shape of sums and products without expanding brackets.
Sums and Products of Functions
f(n)=(3n2+10n+50)⋅(4log2n+7)
f(n) is O(?)
Let's prove that f(n)=(3n2+10n+50)(4log2n+7) is O(n2log2n).
Text solution
Bound the first factorTrading up for n≥1 gives 3n2+10n+50≤63n2.
Bound the second factorTo trade 7 up to 7log2n, we need log2n≥1, which holds for all n≥2 since log22=1.
4log2n+7≤4log2n+7log2n(for n≥2)=11log2n
Multiply the bounds past both starting pointsFor all n≥max(1,2)=2, both positive bounds hold, giving witnesses C=693 and k=2.
Between the two products n2logn and n⋅2n, the exponential term n⋅2n is higher on the ladder, so the entire sum is Θ(n⋅2n).
Key concepts
Ceiling (O), Floor (Ω), and Exact Shape (Θ)
Big O (f(n)≤C⋅g(n) for n≥k): Trade smaller terms up to the leading shape so their coefficients add up to C (for 3n2+10n+50≤63n2,C=63,k=1). Because Big O only requires a ceiling, higher rungs like O(n3) are also true; only use Θ when both floor and ceiling must match.
Big Omega (f(n)≥C⋅g(n) for n≥k): Drop positive lower-order terms (3n2+10n+50≥3n2). Never drop a subtracted term; instead, replace it with one copy of the leading term once n is large enough (3n2−10n≥3n2−n2=2n2 once n≥10).
Disproving Big O: Show that for any C>0 and k>0, dividing f(n)>C⋅g(n) by g(n) leaves a factor that grows without bound, so it passes C at some n≥k (for n3 and n2, at n=max(k,C)+1).
The Ladder of Growth and Starting Points k
1≪logn≪n≪nlogn≪n2≪n3≪2n≪3n≪n!
Logarithm bases differ only by a constant multiplier (log2n is Θ(log10n)), while exponential bases create different growth shapes (3n=(1.5)n⋅2n is not O(2n)).
Check where trade-ups between different families start: log2n≤n starts at k=1, trading 1≤log2n starts at k=2, and trading n2≤2n starts at k=4 (since 32>23).
Sums vs. Products
Without expanding brackets, pick the single highest rung in each sum and multiply the winning rungs across each product.
7
Practice
1
Use the Trading Up method to prove that f(n)=4n3+7n2+15n+20 is O(n3), and state your witnesses C and k.
Watch out: don't drop the lower terms to get C=4, which builds a floor instead of a ceiling, and don't leave 20 untraded.
Trade every lower power of n (including the constant term) up to an n3 term for n≥1 so all four pieces become like terms.
For all n≥1, we have 7n2≤7n3,15n≤15n3, and 20≤20n3. (Watch out: don't drop the lower terms to get C=4, which builds a floor instead of a ceiling, and don't leave 20 untraded.) Trading each smaller term up gives:
4n3+7n2+15n+20≤4n3+7n3+15n3+20n3=46n3(for n≥1)
Thus f(n) is O(n3) with witnesses C=46 and k=1.
2
For f(n)=6n2+12nlog10n, state whether each claim is true or false and briefly explain why: (a) f(n) is O(n2) (b) f(n) is O(n4) (c) f(n) is Θ(n4) (d) log10n is Θ(log2n) (e) 4n is O(2n)
Compare log10n with n to find the true shape of f(n) first, then check whether each statement asks only for a ceiling (O) or for a matching floor and ceiling (Θ).
(a) TrueFor all n≥1,log10n≤n, so 12nlog10n≤12n2 and f(n)≤6n2+12n2=18n2.
(b) TrueBig O only requires an upper bound (don't confuse O with Θ and mark a loose ceiling false); since f(n)≤18n2≤18n4 for all n≥1,n4 is a valid ceiling.
(c) Falsef(n) has growth shape n2 and has no n4 floor, so it is not Ω(n4).
(d) TrueBy the change-of-base formula, log10n=(log2101)log2n, which differs only by a positive constant multiplier.
(e) False4n=(2⋅2)n=2n⋅2n (not 2⋅2n), and the factor 2n grows to infinity rather than staying below a fixed constant C.
3
Prove that f(n)=5n3−40n2 is Ω(n3) by finding explicit witnesses C and k.
Replace −40n2 with −n3 once n is large enough that n3≥40n2.
Split one n3 from the leading term: 5n3−40n2=4n3+(n3−40n2). (Watch out: simply dropping −40n2 to claim 5n3−40n2≥5n3 for n≥1 is false because subtracting 40n2 makes 5n3 smaller.) For all n≥40, we have n3≥40n2, or −40n2≥−n3. Replacing −40n2 with −n3 gives:
5n3−40n2≥5n3−n3=4n3(for n≥40)
Thus f(n) is Ω(n3) with witnesses C=4 and k=40.
4
Use the formal definition of Big O to prove that n4 is not O(n2).
Negate the definition of Big O: given any C>0 and k>0, divide the inequality n4>C⋅n2 by n2 to see how large n needs to be.
To disprove that n4 is O(n2), we must show that for every C>0 and every k>0, there exists some n≥k such that n4>C⋅n2. Dividing both sides by n2 (for n>0) reduces n4>C⋅n2 to n2>C. Given any C>0 and k>0, choose n=max(k,C)+1 (don't pick n=C+1 alone, which can be smaller than k when k is large). Then n≥k and, since n≥1, we have n2≥n>C, which gives:
n4=n2⋅n2>C⋅n2
Thus n4 is not O(n2).
5
Prove that f(n)=8n2+3⋅2n is Θ(2n) by giving witnesses (C1,k1) for the Ω(2n) floor and (C2,k2) for the O(2n) ceiling.
Drop the positive term 8n2 for the floor, and check small values of n before trading n2 up to 2n for the ceiling.
For the floor, since 8n2>0 for all n≥1, dropping 8n2 gives 8n2+3⋅2n≥3⋅2n for all n≥1, so f(n) is Ω(2n) with C1=3 and k1=1.
For the ceiling, the inequality n2≤2n fails at n=3(9>8) and holds for all n≥4 (watch out: setting k2=1 is invalid because of n=3). Trading 8n2 up to 8⋅2n for n≥4 gives:
8n2+3⋅2n≤8⋅2n+3⋅2n=11⋅2n(for n≥4)
So f(n) is O(2n) with C2=11 and k2=4, and combining both gives 3⋅2n≤8n2+3⋅2n≤11⋅2n for all n≥4.
6
Prove that f(n)=(2n3+9n+4)(5log2n+12) is O(n3log2n) by finding explicit witnesses C and k.
Bound each factor separately by trading up to its leading term, then multiply the two bounds where both starting points hold.
First, for all n≥1, trading up gives 2n3+9n+4≤2n3+9n3+4n3=15n3. Second, since log2n≥1 for all n≥2 (don't use k=1 here, since log21=0 makes 12≤12log21 false), trading 12 up to 12log2n gives 5log2n+12≤5log2n+12log2n=17log2n for all n≥2. For all n≥max(1,2)=2, multiplying the positive bounds gives:
Thus f(n) is O(n3log2n) with witnesses C=255 and k=2.
7
Without expanding the brackets, find the Big Theta class Θ(g(n)) of f(n)=(n3+50n2log2n)(6n+100log2n)+(4n2+2n)(7log2n+3n).
Watch out: multiplication multiplies the winners together, so don't drop 2n and write 3n.
Keep the winning rung inside each bracket, multiply the winners in each product, and then keep the winning product in the sum.
In the first product, n3 beats 50n2log2n (since n beats log2n) and 6n beats 100log2n; multiplying the winners gives n3⋅n=n4. In the second product, 2n beats 4n2 and 3n beats 7log2n; multiplying the winners gives 2n⋅3n=6n (watch out: multiplication multiplies the winners together, so don't drop 2n and write 3n). Adding the two products compares n4 with 6n, and the exponential wins, so f(n) is Θ(6n).