3.1.2 · D1Complexity Analysis

Foundations — Common complexities — O(1), O(log n), O(n), O(n log n), O(n²), O(n³), O(2ⁿ), O(n!)

3,325 words15 min readBack to topic

This page assumes nothing. Every letter, every squiggle the parent note uses — we build it here from the ground up, in the order that each one needs the one before it. When you finish, re-read the parent note (the parent topic) and every symbol will already be familiar.


1. n — the size of the input

Why does the topic need n? Because complexity is never a single number. "This algorithm takes 40 steps" is useless — 40 steps for how much input? We always ask: as n gets bigger, what happens to the work? So n is the knob we turn, and everything else describes what happens when we turn it.

Figure — Common complexities — O(1), O(log n), O(n), O(n log n), O(n²), O(n³), O(2ⁿ), O(n!)

2. T(n) — the work as a function of n

Figure — Common complexities — O(1), O(log n), O(n), O(n log n), O(n²), O(n³), O(2ⁿ), O(n!)

The whole subject is really the study of the shape of T(n) — does it stay flat, climb gently, or shoot up like a rocket?


3. Exponents: , , and what a small raised number means

Figure — Common complexities — O(1), O(log n), O(n), O(n log n), O(n²), O(n³), O(2ⁿ), O(n!)

Why the topic needs this: a nested loop — a loop inside a loop — touches every pair of items. If the outer loop runs n times and, for each of those, the inner loop also runs n times, the total is . The square grid in the figure is that pair-counting. Three nested loops fill a cube: .


4. Powers of 2: 2ᵏ and 2ⁿ — repeated doubling

Why does the topic care? Two reasons, and they are mirror images:

  • Doubling upward (): if every new item forces a keep-or-toss choice, the number of combinations doubles with each item. n items → combinations. This is where the "exponential" wall comes from.
  • Halving downward (leads to log, next section): if each step throws away half the data, you are running the doubling tree in reverse.
Figure — Common complexities — O(1), O(log n), O(n), O(n log n), O(n²), O(n³), O(2ⁿ), O(n!)

5. The logarithm: log₂ n — "how many halvings?"

Powers of 2 answer: "I doubled k times — how big did I get?" The logarithm answers the exact reverse question.


6. Summation: — "add up a whole list of things"

Figure — Common complexities — O(1), O(log n), O(n), O(n log n), O(n²), O(n³), O(2ⁿ), O(n!)

7. Big-O: O(...) — the growth label

Now the crown symbol of the whole topic.

Figure — Common complexities — O(1), O(log n), O(n), O(n log n), O(n²), O(n³), O(2ⁿ), O(n!)

8. < and between growth classes

That is exactly the meaning inside the parent note's ladder — each class is eventually dwarfed by the next.


9. Factorial: n! — every possible ordering


The prerequisite map

n = input size

T of n = steps as function of n

exponents n squared n cubed

powers of two = doubling

logarithm = how many halvings

summation adds up loop work

Big-O growth label

factorial = every ordering

Growth ladder and much-less-than

Common Complexities topic

Read it top to bottom: n seeds everything; exponents, doubling, and halving give the shapes; summation and Big-O let us label a piece of code with a shape; the ladder orders the shapes — and that is the topic.


Equipment checklist

Cover the right side and answer out loud. If any one stumps you, re-read its section above before opening the parent note.

What does the letter n stand for, and what values may it take?
The size of the input — a non-negative whole number (); n = 0 means empty input.
Read T(n) in plain words.
"T of n" — the number of basic steps the algorithm takes for an input of size n.
What does the exponent in count?
How many copies of n are multiplied together — here two, so .
What does 2^k mean, what values may k take, and what real process does it picture?
Multiply k twos together (k a non-negative whole number, ); it pictures repeated doubling.
log₂ n answers which question, and for which values of n is it defined?
"To what power must I raise 2 to get n?"; defined only for (no power of 2 equals 0), with .
What does mean, and why do step counts use it?
"Ceiling of x" — round x up to the nearest whole number at or above it; step counts must be whole steps, so a fractional formula rounds up.
How many halvings does a non-power-of-two n need?
— round the log up, since the last partial cut still costs a full step.
What does the summation index i range over, and what is an empty sum?
i steps through whole numbers from bottom to top; if the range is empty the sum is 0.
What is in closed form?
, which grows like .
What does the class O(1) mean and what does its curve look like?
Constant time — work independent of n, a fixed bounded number of steps; its curve is a flat horizontal line.
State the formal definition of .
There exist constants and with for all .
When we write , are we comparing numbers or growth rates, and how does that differ from numeric <?
Growth rates: but not vice versa; numeric < compares two plain values, class < compares eventual growth.
What does n! count, what is , and why does it beat 2ⁿ?
Orderings of n items; (one way to arrange nothing); most of its factors exceed 2, so it overtakes from n = 4.