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 nn gets large, without getting distracted by small inputs or minor terms.

Long-Term Growth of Functions
f(n)=3n2+10n+50\htmlClass{lc-blue}{f(n) = 3n^2 + 10n + 50}
g(n)=n3\htmlClass{lc-pink}{g(n) = n^3}
steps for a problem of size n\text{steps for a problem of size }n
?\htmlClass{lc-blue}{?}
?\htmlClass{lc-pink}{?}

For small inputs like n=1n = 1 or n=2n = 2, f(n)=3n2+10n+50\func{f(n) = 3n^2 + 10n + 50} is larger than g(n)=n3\shape{g(n) = n^3}, but by n=1,000n = 1{,}000, n3\shape{n^3} is hundreds of times larger:

3n2⏟leading shape n2+10n+50⏟minor termsvs.n3\displaystyle \underbrace{\func{3n^2}}_{\text{leading shape } \shape{n^2}} + \underbrace{\func{10n + 50}}_{\text{minor terms}} \quad \text{vs.} \quad \shape{n^3}

To compare the long-term growth shapes of functions rather than single values, we use three comparisons: Big O (≤\le, a ceiling), Big Omega (≥\ge, 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)\func{f(n)} is O(g(n))\cmp{O}(\shape{g(n)}) when some positive constant multiple C⋅g(n)\wit{C} \cdot \shape{g(n)} stays at or above f(n)\func{f(n)} from some starting point n=kn = \wit{k} onward.

f(n) is O(g(n))means∃C>0, k>0⏟witnesses ∀n≥k,f(n)≤C⋅g(n)⏟ceiling\displaystyle \begin{aligned} &\func{f(n)} \text{ is } \cmp{O}(\shape{g(n)}) \quad \text{means} \\ &\quad \exists \underbrace{\wit{C} > 0, \ \wit{k} > 0}_{\text{witnesses}} \ \forall n \ge \wit{k}, \\ &\quad \func{f(n)} \le \underbrace{\wit{C} \cdot \shape{g(n)}}_{\text{ceiling}} \end{aligned}

To prove that f(n)=3n2+10n+50\func{f(n) = 3n^2 + 10n + 50} is O(n2)\cmp{O}(\shape{n^2}), we need to find a working pair of witnesses C\wit{C} and k\wit{k}.

Big O and Witnesses
ceiling: n2  ?\text{ceiling: }\htmlClass{lc-pink}{n^2}\;?
3n2+10n+50\htmlClass{lc-blue}{3n^2 + 10n + 50}
n2\htmlClass{lc-pink}{n^2}
n\htmlClass{lc-mute}{n}
Text solution
Trade smaller powers up to n2\shape{n^2}For all n≥1n \ge \wit{1}, multiplying a positive term by nn or n2n^2 never makes it smaller, so 10n≤10n2\func{10n} \le 10\shape{n^2} and 50≤50n2\func{50} \le 50\shape{n^2}.
3n2+10n+50≤3n2+10n2+50n2(for n≥1)=(3+10+50)n2=63n2\displaystyle \begin{aligned} &\func{3n^2 + 10n + 50} \\ &\quad \le 3\shape{n^2} + 10\shape{n^2} + 50\shape{n^2} \\ &\qquad \text{(for } n \ge \wit{1}\text{)} \\ &\quad = (3 + 10 + 50)\shape{n^2} \\ &\quad = \wit{63}\shape{n^2} \end{aligned}
Read off the witnessesSince 3n2+10n+50≤63n2\func{3n^2 + 10n + 50} \le \wit{63}\shape{n^2} for all n≥1n \ge \wit{1}, f(n)\func{f(n)} is O(n2)\cmp{O}(\shape{n^2}) with witnesses C=63\wit{C} = \wit{63} and k=1\wit{k} = \wit{1}.

Witnesses are never unique. Any multiplier C>3\wit{C} > 3 makes C⋅n2\wit{C} \cdot \shape{n^2} overtake 3n2+10n+50\func{3n^2 + 10n + 50}: a larger multiplier C\wit{C} crosses above the curve at a smaller starting point k\wit{k}, and a multiplier closer to 33 pushes the crossing point k\wit{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 (≤\le), any faster-growing shape is also a valid upper bound for 3n2+10n+50\func{3n^2 + 10n + 50}, whereas a slower-growing shape like n2\shape{n^2} can never stay above n3\func{n^3}.

Loose Ceilings and Disproving Big O
3n2+10n+50   is   O(n3)  ?n3   is   O(n2)  ?\displaystyle \begin{aligned} \func{3n^2 + 10n + 50} &\;\,\text{is}\;\, \cmp{O}(\shape{n^3})\;? \\ \func{n^3} &\;\,\text{is}\;\, \cmp{O}(\shape{n^2})\;? \end{aligned}

Since n2≤n3n^2 \le n^3 for all n≥1n \ge \wit{1}, our 63n2\wit{63}\shape{n^2} ceiling sits underneath 63n3\wit{63}\shape{n^3}, making n3\shape{n^3} a loose ceiling for 3n2+10n+50\func{3n^2 + 10n + 50}:

3n2+10n+50\displaystyle \func{3n^2 + 10n + 50} ≤63n2\displaystyle \le \wit{63}\shape{n^2} ≤63n3(for n≥1)\displaystyle \le \wit{63}\shape{n^3} \quad \text{(for } n \ge \wit{1}\text{)}

Going the other way fails: to prove that n3\func{n^3} is not O(n2)\cmp{O}(\shape{n^2}), we negate the definition and show that n3\func{n^3} grows past every proposed ceiling C⋅n2\wit{C} \cdot \shape{n^2}.

Text solution
Negate the Big O definitionWe must show that for every C>0\wit{C} > 0 and every k>0\wit{k} > 0, there is some n≥k\grows{n} \ge \wit{k} where n3>C⋅n2\func{n^3} > \wit{C} \cdot \shape{n^2}.
Cancel the shared n2\shape{n^2} factorFor n>0n > 0, dividing both sides by n2\shape{n^2} simplifies the inequality to n>C\grows{n} > \wit{C}.
n⋅n2>C⋅n2n>C\displaystyle \begin{aligned} \grows{n} \cdot \shape{n^2} &> \wit{C} \cdot \shape{n^2} \\ \grows{n} &> \wit{C} \end{aligned}
Pick n\grows{n} past both k\wit{k} and C\wit{C}Given any C>0\wit{C} > 0 and k>0\wit{k} > 0, choose n=max⁡(k,C)+1\grows{n} = \max(\wit{k}, \wit{C}) + 1; then n≥k\grows{n} \ge \wit{k} and n>C\grows{n} > \wit{C}, so n3>C⋅n2\func{n^3} > \wit{C} \cdot \shape{n^2}.

No matter how high the multiplier C\wit{C} stretches the parabola C⋅n2\wit{C} \cdot \shape{n^2}, it only delays the crossing point to n=Cn = \wit{C}, where n3\func{n^3} catches up and stays above C⋅n2\wit{C} \cdot \shape{n^2} for all larger nn.

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 (Ω\cmp{\Omega}) puts a floor underneath a function to say it grows at least as fast as g(n)\shape{g(n)}, and Big Theta (Θ\cmp{\Theta}) traps a function between a floor and a ceiling of the same shape g(n)\shape{g(n)}.

f(n) is Ω(g(n))means∃C>0, k>0 ∀n≥k,f(n)≥C⋅g(n)⏟floorf(n) is Θ(g(n))meansf(n) is both Ω(g(n)) and O(g(n))\displaystyle \begin{aligned} &\func{f(n)} \text{ is } \cmp{\Omega}(\shape{g(n)}) \quad \text{means} \\ &\quad \exists \wit{C} > 0, \ \wit{k} > 0 \ \forall n \ge \wit{k}, \\ &\quad \func{f(n)} \ge \underbrace{\wit{C} \cdot \shape{g(n)}}_{\text{floor}} \\ &\func{f(n)} \text{ is } \cmp{\Theta}(\shape{g(n)}) \quad \text{means} \\ &\quad \func{f(n)} \text{ is both } \cmp{\Omega}(\shape{g(n)}) \text{ and } \cmp{O}(\shape{g(n)}) \end{aligned}

Let's find a Big Ω(n2)\cmp{\Omega}(\shape{n^2}) floor first when the lower-order terms are added, and then when a lower-order term is subtracted, as in 3n2−10n\func{3n^2 - 10n}.

Big Omega and Big Theta
Big O≤ceilingBig Ω≥floor\displaystyle \begin{array}{lcl} \text{Big } \cmp{O} & \le & \text{ceiling} \\ \text{Big } \cmp{\Omega} & \ge & \text{floor} \end{array}
3n2+10n+50 is Ω(n2)  ?\displaystyle \func{3n^2 + 10n + 50} \text{ is } \cmp{\Omega}(\shape{n^2})\;?

For 3n2+10n+50\func{3n^2 + 10n + 50}, the extra terms +10n+50\func{+ 10n + 50} are positive for all n≥1n \ge \wit{1}, so dropping them immediately gives a floor:

3n2+10n+50\displaystyle \func{3n^2 + 10n + 50} ≥3n2(for n≥1, so C=3, k=1)\displaystyle \ge \wit{3}\shape{n^2} \quad \text{(for } n \ge \wit{1}\text{, so } \wit{C} = \wit{3}, \ \wit{k} = \wit{1}\text{)}

When a lower-order term is subtracted, as in 3n2−10n\func{3n^2 - 10n}, dropping −10n\func{-10n} would make the expression larger instead of smaller, so we replace −10n\func{-10n} with −n2-\shape{n^2} once nn is large enough that n2≥10n\shape{n^2} \ge \func{10n}.

Text solution
Find where n2≥10n\shape{n^2} \ge \func{10n}Comparing n⋅n\shape{n \cdot n} with 10n\func{10n} shows that n2≥10n\shape{n^2} \ge \func{10n}, or −10n≥−n2\func{-10n} \ge -\shape{n^2}, for all n≥10n \ge \wit{10}.
Replace −10n\func{-10n} with −n2-\shape{n^2}Subtracting n2\shape{n^2} instead of 10n\func{10n} can't make the expression larger for n≥10n \ge \wit{10}, and it leaves like terms.
3n2−10n≥3n2−n2(for n≥10)=2n2\displaystyle \begin{aligned} &\func{3n^2 - 10n} \\ &\quad \ge 3\shape{n^2} - \shape{n^2} \quad \text{(for } n \ge \wit{10}\text{)} \\ &\quad = \wit{2}\shape{n^2} \end{aligned}
Read off the witnessesSince 3n2−10n≥2n2\func{3n^2 - 10n} \ge \wit{2}\shape{n^2} for all n≥10n \ge \wit{10}, 3n2−10n\func{3n^2 - 10n} is Ω(n2)\cmp{\Omega}(\shape{n^2}) with witnesses C=2\wit{C} = \wit{2} and k=10\wit{k} = \wit{10}.
3n2+10n+50\htmlClass{lc-blue}{3n^2 + 10n + 50}
3n2\htmlClass{lc-green}{3}\htmlClass{lc-pink}{n^2}
63n2\htmlClass{lc-green}{63}\htmlClass{lc-pink}{n^2}
4\htmlClass{lc-mute}{4}
6\htmlClass{lc-mute}{6}
8\htmlClass{lc-mute}{8}
k=1\htmlClass{lc-green}{k = 1}
n\htmlClass{lc-mute}{n}

Combining the floor and ceiling for 3n2+10n+50\func{3n^2 + 10n + 50} traps it between two n2\shape{n^2} parabolas from n=1n = \wit{1} onward, proving it is Θ(n2)\cmp{\Theta}(\shape{n^2}):

3n2\displaystyle \wit{3}\shape{n^2} ≤3n2+10n+50\displaystyle \le \func{3n^2 + 10n + 50} ≤63n2(for n≥1)\displaystyle \le \wit{63}\shape{n^2} \quad \text{(for } n \ge \wit{1}\text{)}
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 nn grows.

The Ladder of Growth
11
nn
n2n^2
slowest\htmlClass{lc-mute}{\text{slowest}}
fastest\htmlClass{lc-mute}{\text{fastest}}

Ordered from slowest growth at the bottom to fastest growth at the top, each rung eventually overtakes every rung below it:

1⏟constant≪log⁡n⏟logarithmic≪n⏟linear≪nlog⁡n⏟log-linear≪n2≪n3⏟polynomial≪2n≪3n⏟exponential≪n!⏟factorial\displaystyle \begin{aligned} &\underbrace{1}_{\text{constant}} \ll \underbrace{\log n}_{\text{logarithmic}} \ll \underbrace{n}_{\text{linear}} \ll \underbrace{n \log n}_{\text{log-linear}} \\ &\ll \underbrace{n^2 \ll n^3}_{\text{polynomial}} \ll \underbrace{2^n \ll 3^n}_{\text{exponential}} \ll \underbrace{n!}_{\text{factorial}} \end{aligned}

All logarithms share a single rung because changing the base only multiplies the function by a fixed constant:

log⁡2n=log⁡10nlog⁡102=(1log⁡102)⏟≈ 3.32 (constant)⋅log⁡10n  ⟹  log⁡2n is Θ(log⁡10n)\displaystyle \begin{aligned} \func{\log_2 n} &= \frac{\shape{\log_{10} n}}{\wit{\log_{10} 2}} \\ &= \underbrace{\wit{\left(\frac{1}{\log_{10} 2}\right)}}_{\approx \, \wit{3.32} \text{ (constant)}} \cdot \shape{\log_{10} n} \\ &\implies \func{\log_2 n} \text{ is } \cmp{\Theta}(\shape{\log_{10} n}) \end{aligned}

Exponentials with different bases sit on different rungs because factoring 2n\shape{2^n} out of 3n\func{3^n} leaves a factor that grows to infinity rather than staying below a constant C\wit{C}:

3n=(1.5×2)n=(1.5)n⏟→ ∞⋅2n  ⟹  3n is not O(2n)\displaystyle \begin{aligned} \func{3^n} &= (\grows{1.5} \times \shape{2})^n \\ &= \underbrace{\grows{(1.5)^n}}_{\grows{\to \, \infty}} \cdot \shape{2^n} \\ &\implies \func{3^n} \text{ is not } \cmp{O}(\shape{2^n}) \end{aligned}

Multiplying log⁡10n\shape{\log_{10} n} by C=1log⁡102≈3.32\wit{C} = \wit{\tfrac{1}{\log_{10} 2}} \approx \wit{3.32} makes it match log⁡2n\func{\log_2 n} everywhere, whereas 3n\func{3^n} always grows faster and pulls away from C⋅2n\wit{C} \cdot \shape{2^n} no matter how large C\wit{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\wit{k} to where that inequality begins to hold.

Witnesses Across the Ladder
f(n)=5n2+20nlog⁡2n+100\htmlClass{lc-blue}{f(n) = 5n^2 + 20n \log_2 n + 100}
is O(n2)  ?\text{is }\htmlClass{lc-violet}{O}(\htmlClass{lc-pink}{n^2})\;?
11
log⁡n\log n
nn
nlog⁡nn\log n
n2n^2
n3n^3
2n2^n
3n3^n
n!n!
n≤n2n \le n^2
(n≥1)(n \ge 1)
?\htmlClass{lc-pink}{?}
?\htmlClass{lc-pink}{?}

First, let's prove that f(n)=5n2+20nlog⁡2n+100\func{f(n) = 5n^2 + 20n \log_2 n + 100} is O(n2)\cmp{O}(\shape{n^2}).

Text solution
Trade log⁡2n\log_2 n up to nnSince log⁡2n≤n\log_2 n \le n for all n≥1n \ge \wit{1}, multiplying both sides by 20n20n turns the middle term into an n2\shape{n^2} term.
log⁡2n≤n(for n≥1)20nlog⁡2n≤20n⋅n=20n2\displaystyle \begin{aligned} \log_2 n &\le n \quad \text{(for } n \ge \wit{1}\text{)} \\ \func{20n \log_2 n} &\le 20n \cdot n = 20\shape{n^2} \end{aligned}
Trade the constant up and add like termsUsing 100≤100n2\func{100} \le 100\shape{n^2} for n≥1n \ge \wit{1} puts all three terms into n2\shape{n^2}.
5n2+20nlog⁡2n+100≤5n2+20n2+100n2(for n≥1)=125n2\displaystyle \begin{aligned} &\func{5n^2 + 20n \log_2 n + 100} \\ &\quad \le 5\shape{n^2} + 20\shape{n^2} + 100\shape{n^2} \\ &\qquad \text{(for } n \ge \wit{1}\text{)} \\ &\quad = \wit{125}\shape{n^2} \end{aligned}
Read off the witnessesf(n)\func{f(n)} is O(n2)\cmp{O}(\shape{n^2}) with C=125\wit{C} = \wit{125} and k=1\wit{k} = \wit{1}.

Now let's prove that f(n)=10n2+2n\func{f(n) = 10n^2 + 2^n} is Θ(2n)\cmp{\Theta}(\shape{2^n}) by finding witnesses for both the floor and the ceiling.

Text solution
Drop 10n2\func{10n^2} for the Ω(2n)\cmp{\Omega}(\shape{2^n}) floorSince 10n2>0\func{10n^2} > 0 for all n≥1n \ge \wit{1}, dropping it gives witnesses C1=1\wit{C_1} = \wit{1} and k1=1\wit{k_1} = \wit{1}.
10n2+2n\displaystyle \func{10n^2 + 2^n} ≥1⋅2n(for n≥1)\displaystyle \ge \wit{1} \cdot \shape{2^n} \quad \text{(for } n \ge \wit{1}\text{)}
Find where n2≤2nn^2 \le 2^n stays trueAt n=3n = \fails{3}, 32=9>23=8\fails{3^2 = 9 > 2^3 = 8}, so n2n^2 is briefly larger than 2n2^n before n2≤2nn^2 \le 2^n holds from n=4n = \wit{4} onward (42=16≤24=164^2 = 16 \le 2^4 = 16).
Trade 10n2\func{10n^2} up to 10⋅2n10 \cdot \shape{2^n} from n=4n = \wit{4} onwardStarting at k2=4\wit{k_2} = \wit{4}, replace n2\func{n^2} with 2n\shape{2^n} to get ceiling multiplier C2=11\wit{C_2} = \wit{11}.
10n2+2n≤10⋅2n+2n(for n≥4)=11⋅2n\displaystyle \begin{aligned} &\func{10n^2 + 2^n} \\ &\quad \le 10 \cdot \shape{2^n} + \shape{2^n} \quad \text{(for } n \ge \wit{4}\text{)} \\ &\quad = \wit{11} \cdot \shape{2^n} \end{aligned}
Combine the floor and ceilingBoth bounds hold for all n≥4n \ge \wit{4}, proving 10n2+2n\func{10n^2 + 2^n} is Θ(2n)\cmp{\Theta}(\shape{2^n}).
1⋅2n\displaystyle \wit{1} \cdot \shape{2^n} ≤10n2+2n\displaystyle \le \func{10n^2 + 2^n} ≤11⋅2n(for n≥4)\displaystyle \le \wit{11} \cdot \shape{2^n} \quad \text{(for } n \ge \wit{4}\text{)}
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)⋅(4log⁡2n+7)\displaystyle \begin{aligned} \func{f(n)} &= \func{(3n^2 + 10n + 50)} \\ &\qquad \cdot \func{(4 \log_2 n + 7)} \end{aligned}
f(n) is O(  ?  )\displaystyle \func{f(n)} \text{ is } \cmp{O}(\;?\;)

Let's prove that f(n)=(3n2+10n+50)(4log⁡2n+7)\func{f(n) = (3n^2 + 10n + 50)(4 \log_2 n + 7)} is O(n2log⁡2n)\cmp{O}(\shape{n^2 \log_2 n}).

Text solution
Bound the first factorTrading up for n≥1n \ge \wit{1} gives 3n2+10n+50≤63n2\func{3n^2 + 10n + 50} \le \wit{63}\shape{n^2}.
Bound the second factorTo trade 7\func{7} up to 7log⁡2n7 \shape{\log_2 n}, we need log⁡2n≥1\log_2 n \ge 1, which holds for all n≥2n \ge \wit{2} since log⁡22=1\log_2 2 = 1.
4log⁡2n+7≤4log⁡2n+7log⁡2n(for n≥2)=11log⁡2n\displaystyle \begin{aligned} &\func{4 \log_2 n + 7} \\ &\quad \le 4 \shape{\log_2 n} + 7 \shape{\log_2 n} \\ &\qquad \text{(for } n \ge \wit{2}\text{)} \\ &\quad = \wit{11} \shape{\log_2 n} \end{aligned}
Multiply the bounds past both starting pointsFor all n≥max⁡(1,2)=2n \ge \max(\wit{1}, \wit{2}) = \wit{2}, both positive bounds hold, giving witnesses C=693\wit{C} = \wit{693} and k=2\wit{k} = \wit{2}.
(3n2+10n+50)(4log⁡2n+7)≤(63n2)(11log⁡2n)=693n2log⁡2n(for n≥2)\displaystyle \begin{aligned} &\func{(3n^2 + 10n + 50)(4 \log_2 n + 7)} \\ &\quad \le (\wit{63}\shape{n^2})(\wit{11} \shape{\log_2 n}) \\ &\quad = \wit{693} \shape{n^2 \log_2 n} \quad \text{(for } n \ge \wit{2}\text{)} \end{aligned}

Now let's find the Big Theta class of f(n)=(3n2+10n+50)(4log⁡2n+7)+(n+5)(100n2+2n)\func{f(n) = (3n^2 + 10n + 50)(4 \log_2 n + 7)} \\ \quad \func{{} + (n + 5)(100n^2 + 2^n)} directly from the winners in each part:

(3n2+10n+50)(4log⁡2n+7)⏟winners multiply: n2log⁡n+(n+5)(100n2+2n)⏟winners multiply: n⋅2n  ⟹  Θ(n⋅2n)\displaystyle \begin{aligned} &\underbrace{(\shape{\mathbf{3n^2}} + 10n + 50)(\shape{\mathbf{4 \log_2 n}} + 7)}_{\text{winners multiply: } \shape{n^2 \log n}} \\ &+ \underbrace{(\shape{\mathbf{n}} + 5)(100n^2 + \shape{\mathbf{2^n}})}_{\text{winners multiply: } \shape{n \cdot 2^n}} \\ &\implies \cmp{\Theta}(\shape{n \cdot 2^n}) \end{aligned}

Between the two products n2log⁡n\shape{n^2 \log n} and n⋅2n\shape{n \cdot 2^n}, the exponential term n⋅2n\shape{n \cdot 2^n} is higher on the ladder, so the entire sum is Θ(n⋅2n)\cmp{\Theta}(\shape{n \cdot 2^n}).

Key concepts

Ceiling (O\cmp{O}), Floor (Ω\cmp{\Omega}), and Exact Shape (Θ\cmp{\Theta})

  • Big O (f(n)≤C⋅g(n)\func{f(n)} \le \wit{C} \cdot \shape{g(n)} for n≥kn \ge \wit{k}): Trade smaller terms up to the leading shape so their coefficients add up to C\wit{C} (for 3n2+10n+50≤63n2\func{3n^2 + 10n + 50} \le \wit{63}\shape{n^2}, C=63,k=1\wit{C} = \wit{63}, \wit{k} = \wit{1}). Because Big O only requires a ceiling, higher rungs like O(n3)\cmp{O}(\shape{n^3}) are also true; only use Θ\cmp{\Theta} when both floor and ceiling must match.
  • Big Omega (f(n)≥C⋅g(n)\func{f(n)} \ge \wit{C} \cdot \shape{g(n)} for n≥kn \ge \wit{k}): Drop positive lower-order terms (3n2+10n+50≥3n2\func{3n^2 + 10n + 50} \ge \wit{3}\shape{n^2}). Never drop a subtracted term; instead, replace it with one copy of the leading term once nn is large enough (3n2−10n≥3n2−n2=2n2\func{3n^2 - 10n} \ge 3\shape{n^2} - \shape{n^2} = \wit{2}\shape{n^2} once n≥10n \ge \wit{10}).
  • Disproving Big O: Show that for any C>0\wit{C} > 0 and k>0\wit{k} > 0, dividing f(n)>C⋅g(n)\func{f(n)} > \wit{C} \cdot \shape{g(n)} by g(n)\shape{g(n)} leaves a factor that grows without bound, so it passes C\wit{C} at some n≥k\grows{n} \ge \wit{k} (for n3\func{n^3} and n2\shape{n^2}, at n=max⁡(k,C)+1\grows{n} = \max(\wit{k}, \wit{C}) + 1).
The Ladder of Growth and Starting Points k\wit{k}

1≪log⁡n≪n≪nlog⁡n≪n2≪n3≪2n≪3n≪n!\displaystyle 1 \ll \log n \ll n \ll n \log n \ll n^2 \ll n^3 \ll 2^n \ll 3^n \ll n!

  • Logarithm bases differ only by a constant multiplier (log⁡2n\func{\log_2 n} is Θ(log⁡10n)\cmp{\Theta}(\shape{\log_{10} n})), while exponential bases create different growth shapes (3n=(1.5)n⋅2n\func{3^n} = \grows{(1.5)^n} \cdot \shape{2^n} is not O(2n)\cmp{O}(\shape{2^n})).
  • Check where trade-ups between different families start: log⁡2n≤n\log_2 n \le n starts at k=1\wit{k} = \wit{1}, trading 1≤log⁡2n1 \le \log_2 n starts at k=2\wit{k} = \wit{2}, and trading n2≤2nn^2 \le 2^n starts at k=4\wit{k} = \wit{4} (since 32>23\fails{3^2 > 2^3}).
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\func{f(n) =} \\ \func{4n^3 + 7n^2 + 15n + 20} is O(n3)\cmp{O}(\shape{n^3}), and state your witnesses C\wit{C} and k\wit{k}.

Trade every lower power of nn (including the constant term) up to an n3\shape{n^3} term for n≥1n \ge 1 so all four pieces become like terms.

For all n≥1n \ge \wit{1}, we have 7n2≤7n3\func{7n^2} \le 7\shape{n^3}, 15n≤15n3\func{15n} \le 15\shape{n^3}, and 20≤20n3\func{20} \le 20\shape{n^3}. (Watch out: don't drop the lower terms to get C=4\wit{C} = \fails{4}, which builds a floor instead of a ceiling, and don't leave 20\func{20} untraded.) Trading each smaller term up gives:
4n3+7n2+15n+20≤4n3+7n3+15n3+20n3=46n3(for n≥1)\displaystyle \begin{aligned} &\func{4n^3 + 7n^2 + 15n + 20} \\ &\quad \le 4\shape{n^3} + 7\shape{n^3} + 15\shape{n^3} + 20\shape{n^3} \\ &\quad = \wit{46}\shape{n^3} \quad \text{(for } n \ge \wit{1}\text{)} \end{aligned}
Thus f(n)\func{f(n)} is O(n3)\cmp{O}(\shape{n^3}) with witnesses C=46\wit{C} = \wit{46} and k=1\wit{k} = \wit{1}.
2

For f(n)=6n2+12nlog⁡10n\func{f(n) = 6n^2 + 12n \log_{10} n}, state whether each claim is true or false and briefly explain why: (a) f(n)\func{f(n)} is O(n2)\cmp{O}(\shape{n^2}) (b) f(n)\func{f(n)} is O(n4)\cmp{O}(\shape{n^4}) (c) f(n)\func{f(n)} is Θ(n4)\cmp{\Theta}(\shape{n^4}) (d) log⁡10n\func{\log_{10} n} is Θ(log⁡2n)\cmp{\Theta}(\shape{\log_2 n}) (e) 4n\func{4^n} is O(2n)\cmp{O}(\shape{2^n})

Compare log⁡10n\log_{10} n with nn to find the true shape of f(n)\func{f(n)} first, then check whether each statement asks only for a ceiling (O\cmp{O}) or for a matching floor and ceiling (Θ\cmp{\Theta}).

(a) TrueFor all n≥1n \ge \wit{1}, log⁡10n≤n\log_{10} n \le n, so 12nlog⁡10n≤12n2\func{12n \log_{10} n} \le 12\shape{n^2} and f(n)≤6n2+12n2=18n2\func{f(n)} \le 6\shape{n^2} + 12\shape{n^2} = \wit{18}\shape{n^2}.
(b) TrueBig O only requires an upper bound (don't confuse O\cmp{O} with Θ\cmp{\Theta} and mark a loose ceiling false); since f(n)≤18n2≤18n4\func{f(n)} \le \wit{18}\shape{n^2} \le \wit{18}\shape{n^4} for all n≥1n \ge \wit{1}, n4\shape{n^4} is a valid ceiling.
(c) Falsef(n)\func{f(n)} has growth shape n2\shape{n^2} and has no n4\shape{n^4} floor, so it is not Ω(n4)\cmp{\Omega}(\shape{n^4}).
(d) TrueBy the change-of-base formula, log⁡10n=(1log⁡210)log⁡2n\func{\log_{10} n} = (\wit{\tfrac{1}{\log_2 10}}) \shape{\log_2 n}, which differs only by a positive constant multiplier.
(e) False4n=(2⋅2)n=2n⋅2n\func{4^n} = (\shape{2} \cdot \grows{2})^n = \shape{2^n} \cdot \grows{2^n} (not 2⋅2n\fails{2 \cdot 2^n}), and the factor 2n\grows{2^n} grows to infinity rather than staying below a fixed constant C\wit{C}.
3

Prove that f(n)=5n3−40n2\func{f(n) = 5n^3 - 40n^2} is Ω(n3)\cmp{\Omega}(\shape{n^3}) by finding explicit witnesses C\wit{C} and k\wit{k}.

Replace −40n2\func{-40n^2} with −n3-\shape{n^3} once nn is large enough that n3≥40n2\shape{n^3} \ge \func{40n^2}.

Split one n3\func{n^3} from the leading term: 5n3−40n2=4n3+(n3−40n2)\func{5n^3 - 40n^2} = \func{4n^3} + (\func{n^3 - 40n^2}). (Watch out: simply dropping −40n2\func{-40n^2} to claim 5n3−40n2≥5n3\fails{5n^3 - 40n^2 \ge 5n^3} for n≥1n \ge 1 is false because subtracting 40n2\func{40n^2} makes 5n3\func{5n^3} smaller.) For all n≥40n \ge \wit{40}, we have n3≥40n2\shape{n^3} \ge \func{40n^2}, or −40n2≥−n3\func{-40n^2} \ge -\shape{n^3}. Replacing −40n2\func{-40n^2} with −n3-\shape{n^3} gives:
5n3−40n2\displaystyle \func{5n^3 - 40n^2} ≥5n3−n3\displaystyle \ge 5\shape{n^3} - \shape{n^3} =4n3(for n≥40)\displaystyle = \wit{4}\shape{n^3} \quad \text{(for } n \ge \wit{40}\text{)}
Thus f(n)\func{f(n)} is Ω(n3)\cmp{\Omega}(\shape{n^3}) with witnesses C=4\wit{C} = \wit{4} and k=40\wit{k} = \wit{40}.
4

Use the formal definition of Big O to prove that n4\func{n^4} is not O(n2)\cmp{O}(\shape{n^2}).

Negate the definition of Big O: given any C>0\wit{C} > 0 and k>0\wit{k} > 0, divide the inequality n4>C⋅n2\func{n^4} > \wit{C} \cdot \shape{n^2} by n2\shape{n^2} to see how large nn needs to be.

To disprove that n4\func{n^4} is O(n2)\cmp{O}(\shape{n^2}), we must show that for every C>0\wit{C} > 0 and every k>0\wit{k} > 0, there exists some n≥k\grows{n} \ge \wit{k} such that n4>C⋅n2\func{n^4} > \wit{C} \cdot \shape{n^2}. Dividing both sides by n2\shape{n^2} (for n>0n > 0) reduces n4>C⋅n2\func{n^4} > \wit{C} \cdot \shape{n^2} to n2>C\grows{n^2} > \wit{C}. Given any C>0\wit{C} > 0 and k>0\wit{k} > 0, choose n=max⁡(k,C)+1\grows{n} = \max(\wit{k}, \wit{C}) + 1 (don't pick n=C+1\fails{n = C + 1} alone, which can be smaller than k\wit{k} when k\wit{k} is large). Then n≥k\grows{n} \ge \wit{k} and, since n≥1\grows{n} \ge 1, we have n2≥n>C\grows{n^2} \ge \grows{n} > \wit{C}, which gives:
n4\displaystyle \func{n^4} =n2⋅n2>C⋅n2\displaystyle = \grows{n^2} \cdot \shape{n^2} > \wit{C} \cdot \shape{n^2}
Thus n4\func{n^4} is not O(n2)\cmp{O}(\shape{n^2}).
5

Prove that f(n)=8n2+3⋅2n\func{f(n) = 8n^2 + 3 \cdot 2^n} is Θ(2n)\cmp{\Theta}(\shape{2^n}) by giving witnesses (C1,k1)(\wit{C_1}, \wit{k_1}) for the Ω(2n)\cmp{\Omega}(\shape{2^n}) floor and (C2,k2)(\wit{C_2}, \wit{k_2}) for the O(2n)\cmp{O}(\shape{2^n}) ceiling.

Drop the positive term 8n2\func{8n^2} for the floor, and check small values of nn before trading n2\func{n^2} up to 2n\shape{2^n} for the ceiling.

For the floor, since 8n2>0\func{8n^2} > 0 for all n≥1n \ge \wit{1}, dropping 8n2\func{8n^2} gives 8n2+3⋅2n≥3⋅2n\func{8n^2 + 3 \cdot 2^n} \ge \wit{3} \cdot \shape{2^n} for all n≥1n \ge \wit{1}, so f(n)\func{f(n)} is Ω(2n)\cmp{\Omega}(\shape{2^n}) with C1=3\wit{C_1} = \wit{3} and k1=1\wit{k_1} = \wit{1}.
For the ceiling, the inequality n2≤2nn^2 \le 2^n fails at n=3n = \fails{3} (9>8\fails{9 > 8}) and holds for all n≥4n \ge \wit{4} (watch out: setting k2=1\wit{k_2} = \fails{1} is invalid because of n=3n = \fails{3}). Trading 8n2\func{8n^2} up to 8⋅2n8 \cdot \shape{2^n} for n≥4n \ge \wit{4} gives:
8n2+3⋅2n≤8⋅2n+3⋅2n=11⋅2n(for n≥4)\displaystyle \begin{aligned} \func{8n^2 + 3 \cdot 2^n} &\le 8 \cdot \shape{2^n} + 3 \cdot \shape{2^n} \\ &= \wit{11} \cdot \shape{2^n} \quad \text{(for } n \ge \wit{4}\text{)} \end{aligned}
So f(n)\func{f(n)} is O(2n)\cmp{O}(\shape{2^n}) with C2=11\wit{C_2} = \wit{11} and k2=4\wit{k_2} = \wit{4}, and combining both gives 3⋅2n≤8n2+3⋅2n≤11⋅2n\wit{3} \cdot \shape{2^n} \le \func{8n^2 + 3 \cdot 2^n} \le \wit{11} \cdot \shape{2^n} for all n≥4n \ge \wit{4}.
6

Prove that f(n)=(2n3+9n+4)(5log⁡2n+12)\func{f(n) = (2n^3 + 9n + 4)} \\ \quad \func{(5 \log_2 n + 12)} is O(n3log⁡2n)\cmp{O}(\shape{n^3 \log_2 n}) by finding explicit witnesses C\wit{C} and k\wit{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≥1n \ge \wit{1}, trading up gives 2n3+9n+4≤2n3+9n3+4n3=15n3\func{2n^3 + 9n + 4} \le 2\shape{n^3} + 9\shape{n^3} + 4\shape{n^3} \\ \quad = \wit{15}\shape{n^3}. Second, since log⁡2n≥1\log_2 n \ge 1 for all n≥2n \ge \wit{2} (don't use k=1\wit{k} = \fails{1} here, since log⁡21=0\fails{\log_2 1 = 0} makes 12≤12log⁡21\fails{12 \le 12 \log_2 1} false), trading 12\func{12} up to 12log⁡2n12 \shape{\log_2 n} gives 5log⁡2n+12≤5log⁡2n+12log⁡2n=17log⁡2n\func{5 \log_2 n + 12} \le 5 \shape{\log_2 n} + 12 \shape{\log_2 n} \\ \quad = \wit{17} \shape{\log_2 n} for all n≥2n \ge \wit{2}. For all n≥max⁡(1,2)=2n \ge \max(\wit{1}, \wit{2}) = \wit{2}, multiplying the positive bounds gives:
(2n3+9n+4)(5log⁡2n+12)≤(15n3)(17log⁡2n)=255n3log⁡2n(for n≥2)\displaystyle \begin{aligned} &\func{(2n^3 + 9n + 4)(5 \log_2 n + 12)} \\ &\quad \le (\wit{15}\shape{n^3})(\wit{17} \shape{\log_2 n}) \\ &\quad = \wit{255}\shape{n^3 \log_2 n} \quad \text{(for } n \ge \wit{2}\text{)} \end{aligned}
Thus f(n)\func{f(n)} is O(n3log⁡2n)\cmp{O}(\shape{n^3 \log_2 n}) with witnesses C=255\wit{C} = \wit{255} and k=2\wit{k} = \wit{2}.
7

Without expanding the brackets, find the Big Theta class Θ(g(n))\cmp{\Theta}(\shape{g(n)}) of f(n)=(n3+50n2log⁡2n)(6n+100log⁡2n)+(4n2+2n)(7log⁡2n+3n)\func{f(n) = (n^3 + 50n^2 \log_2 n)} \\ \quad \func{(6n + 100 \log_2 n)} \\ \quad \func{{} + (4n^2 + 2^n)} \\ \quad \func{(7 \log_2 n + 3^n)}.

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\shape{n^3} beats 50n2log⁡2n50n^2 \log_2 n (since n\shape{n} beats log⁡2n\log_2 n) and 6n\shape{6n} beats 100log⁡2n100 \log_2 n; multiplying the winners gives n3⋅n=n4\shape{n^3} \cdot \shape{n} = \shape{n^4}. In the second product, 2n\shape{2^n} beats 4n24n^2 and 3n\shape{3^n} beats 7log⁡2n7 \log_2 n; multiplying the winners gives 2n⋅3n=6n\shape{2^n} \cdot \shape{3^n} = \shape{6^n} (watch out: multiplication multiplies the winners together, so don't drop 2n\shape{2^n} and write 3n\fails{3^n}). Adding the two products compares n4\shape{n^4} with 6n\shape{6^n}, and the exponential wins, so f(n)\func{f(n)} is Θ(6n)\cmp{\Theta}(\shape{6^n}).