Intuition The one core idea
A complexity class is a bucket that holds every decision problem you can solve inside a fixed budget of time (steps) or space (memory cells), written as a function of the input's length. Everything in this topic is about measuring those two budgets, naming the buckets, and proving which bucket sits inside which.
Before you can read the parent note, you need to be able to look at each squiggle — n , O ( ⋅ ) , DTIME , ⊆ , 2 O ( f ) — and see what it means. This page builds every one of them from nothing. We go strictly in order: each symbol only uses symbols already defined above it.
Everything here is measured on a Turing machine (TM). You do not need its full theory — just this picture.
Definition A Turing machine, in one picture
Imagine an infinite paper tape divided into cells. A little head sits over one cell. It can read the symbol there, overwrite it, and slide one cell left or right per step . A tiny controller (a finite list of rules) decides what to do based on (current rule-state, symbol under head).
The two things we will count are drawn right there:
how many steps the head takes before it stops → this becomes time ,
how many distinct cells the head ever touches → this becomes space .
Intuition Why a TM and not a real laptop?
We want a definition of "steps" and "memory" that does not depend on brand of CPU. The TM is the simplest fully-specified machine where "one step" and "one cell" are unambiguous. Any reasonable computer differs from it by only a polynomial factor, which (we'll see) does not change the buckets.
w and n = ∣ w ∣
The machine's input is a finite string w — a row of symbols, like 10110 or abba. Its length is the number of symbols in it, written ∣ w ∣ , and we give that number the name n :
n = ∣ w ∣.
The bars ∣ ⋯ ∣ mean "how many symbols are inside", exactly like the length of a word.
Intuition Why measure everything against
n
A program takes longer on bigger inputs, so a single number like "40 ms" is meaningless. Instead we describe cost as a function of n — one formula that works for inputs of every size. That is the whole reason the parent writes T ( n ) and S ( n ) instead of a constant.
A language L is just a set of strings — the collection of all inputs whose answer is "YES". "Deciding L " means: given any string w , correctly say whether w ∈ L (yes) or w ∈ / L (no).
The symbol ∈ reads "is a member of"; ∈ / reads "is not a member of".
Worked example Concrete language
Let L pal = the set of all palindromes (w that read the same backwards). Then abba ∈ L pal but abc ∈ / L pal . "Solve the palindrome problem" = "decide L pal ".
Intuition Why languages, not "problems"
Every yes/no question ("is this graph connected?", "is this formula satisfiable?") becomes: which strings encode a YES instance? Turning problems into sets of strings lets one clean definition — the language — cover them all. This is why the parent says a complexity class is a set of languages , i.e. a set of sets of strings.
We count on a deterministic machine M that halts (stops) on every input.
t M ( w ) = number of steps M takes on the specific input w .
s M ( w ) = number of distinct cells M scans on input w .
For each input length n there are many inputs; we take the worst (largest) one:
T ( n ) = max { t M ( w ) : ∣ w ∣ = n } , S ( n ) = max { s M ( w ) : ∣ w ∣ = n } .
The symbol max { … } reads "the biggest value in this set". The colon : reads "such that". So T ( n ) = "the biggest step-count over all inputs of length exactly n ".
We want a guarantee . If we promise "at most T ( n ) steps for any length-n input", we take the worst input of that length — the one that makes the machine sweat the most. Averages hide the inputs that break you.
g ( n ) = O ( f ( n )) means: from some point on, g is at most a constant multiple of f . Formally, there exist numbers c > 0 and n 0 such that g ( n ) ≤ c ⋅ f ( n ) for all n ≥ n 0 .
Picture two curves: g can wobble, but eventually it stays under a stretched copy c ⋅ f of the reference curve. Big-O throws away constant factors and small-n noise, keeping only the growth rate . Deeper treatment: Big-O Asymptotic Notation .
needs O ( ⋅ )
By the linear-speedup and tape-compression theorems, you can shave time or space by any constant just with hardware tricks (bigger alphabet, more tapes). So constants are not a real property of the problem . Wrapping everything in O ( ⋅ ) means the classes measure the problem, not the gadgetry — this is exactly why the parent's DTIME/DSPACE definitions use O .
O ( n 2 ) means exactly n 2 steps."
Why it feels right: we casually say "it's O ( n 2 ) " as if it's the count. Fix: O ( n 2 ) is an upper-bound family — it includes 3 n 2 + 5 n , n 2 , even n log n . It says "no worse than a constant times n 2 ", never an exact figure.
N and f : N → N
N = { 0 , 1 , 2 , 3 , … } , the counting numbers. The notation f : N → N means "f is a rule that takes a counting number and returns a counting number" — e.g. f ( n ) = n 2 or f ( n ) = 2 n . This f is the budget : "you may use up to f ( n ) of the resource."
function is the budget
The budget must scale with input size (bigger input, bigger allowance). So the budget itself is a function of n . Choosing f ( n ) = n 2 vs f ( n ) = 2 n is choosing how generous the allowance is.
Everything above was scaffolding. Here is the payoff.
Decode it left to right with the symbols you now own:
{ L : … } — "the set of all languages L such that …".
∃ — "there exists" (at least one machine works).
deterministic ("D") — the machine's next move is fully forced; no choices. (Swap in "N" for nondeterministic and you get NTIME , NSPACE — a machine that may guess , covered in NP-Completeness and Reductions .)
O ( f ( n )) — using the Big-O budget from §4.
So DTIME ( n 2 ) is literally the bucket of all yes/no problems some ordinary machine can solve in at-most-quadratic time .
Recall What does the "D" stand for, and what changes if it becomes "N"?
D = deterministic (moves forced). N = nondeterministic — the machine may guess/branch; you only need one branch to accept. ::: D means one forced path; N lets the machine explore many paths and accept if any succeeds.
The named classes are built by plugging specific f 's in. Three shapes appear.
Definition Three growth shapes
n k — polynomial : n , n 2 , n 3 , … Curves up gently. Union over all k gives P .
2 n — exponential : doubles each time n grows by 1. Explodes. Gives EXP .
log n — logarithmic : the inverse of 2 n ; grows painfully slowly (log 2 1000 ≈ 10 ). It's the number of bits to write a counter up to n . Gives L .
log n is the "counter" budget
To store a number as large as n you need about log 2 n binary digits. So a machine holding "position i where 0 ≤ i < n " uses O ( log n ) space. That is the whole reason logspace (L ) is a meaningful, tiny budget — see Example B in the parent (Reachability). Compare against Space vs Time Tradeoffs .
⋃ k ≥ 1
⋃ is "union" — pour all the listed sets into one big set. ⋃ k ≥ 1 DTIME ( n k ) means: take DTIME ( n 1 ) , add DTIME ( n 2 ) , add DTIME ( n 3 ) , … forever, and combine.
Intuition Why a union, not a single
k
"Polynomial" isn't one fixed degree — some problems need n 2 , others n 7 . We want the bucket to hold all of them, so we union over every exponent k . That's precisely why the parent writes P = ⋃ k ≥ 1 DTIME ( n k ) .
Definition Two arrows of inclusion
A ⊆ B — "A is contained in B ": every problem in A is also in B (B is at least as big).
A ⊊ B — "A is strictly inside B ": A ⊆ B and B has something A lacks.
Intuition Why the distinction is the whole drama
The parent's chain P ⊆ NP ⊆ PSPACE uses ⊆ because we can prove each fits inside the next. Turning any of those ⊆ into ⊊ (proving the bigger class is genuinely bigger) is where the famous open problems live — including P vs NP . The Hierarchy Theorems are exactly the tools that upgrade some ⊆ to ⊊ ; Savitch's Theorem collapses some the other way (NPSPACE = PSPACE ).
P ⊆ NP , so obviously P ⊊ NP ."
Why it feels right: guessing seems strictly stronger. Fix: ⊆ is trivially true (a deterministic machine is a lazy nondeterministic one), but strictness (⊊ ) is unproven — that's the million-dollar question. Never write ⊊ you can't prove.
2 O ( f ( n ))
Read the exponent first: O ( f ( n )) is "at most a constant times f ". Then 2 that raises 2 to it. So 2 O ( f ) means "2 to a power that is at most c ⋅ f ( n ) " — used in the parent's Step 2, where a machine using f space can run for at most 2 O ( f ) steps before it must repeat a configuration.
Intuition Why this exact shape appears
Count the distinct snapshots (state + head position + tape contents) of a machine limited to f cells: there are ∣ Q ∣ ⋅ f ( n ) ⋅ ∣Γ ∣ f ( n ) = 2 O ( f ( n )) of them. A halting machine can never repeat a snapshot, so that count is also its step-limit. Bounded space ⇒ bounded time — the engine of DSPACE ( f ) ⊆ DTIME ( 2 O ( f ) ) . (The halting/looping intuition connects to Decidability and the Halting Problem .)
Turing machine steps and cells
Input string w and length n
Language a set of strings
Complexity class a bucket of languages
Named classes P NP L PSPACE EXP
Inclusions subseteq and subsetneq
2 to the O of f snapshots
Cover the right side; if you can answer each, you're ready for the parent note.
What does n stand for, and where does it come from? n = ∣ w ∣ , the number of symbols in the input string w .
What is a "language" in this subject? A set of strings — exactly the inputs whose answer is YES.
Why is cost written as a function of n instead of one number? Programs slow down on bigger inputs, so we need one formula covering every input size and comparing growth rates.
What does T ( n ) = max { t M ( w ) : ∣ w ∣ = n } mean in words? The largest step-count over all inputs of length exactly n — the worst case.
What does g ( n ) = O ( f ( n )) assert precisely? There exist c > 0 and n 0 with g ( n ) ≤ c ⋅ f ( n ) for all n ≥ n 0 — g grows no faster than f up to a constant.
Why do the DTIME/DSPACE definitions wrap the budget in O ( ⋅ ) ? Speedup/compression theorems remove constant factors, so only the asymptotic growth is a real property of the problem.
What does the "D" in DTIME mean, and its "N" cousin? D = deterministic (moves forced); N = nondeterministic (machine may guess/branch, accepts if any branch does).
How many bits store a counter up to n , and which class is that? About log 2 n bits — that's the logspace budget L = DSPACE ( log n ) .
Why is P defined as a union ⋃ k ≥ 1 DTIME ( n k ) ? Different problems need different polynomial degrees, so we union over all exponents k to hold them all.
Difference between A ⊆ B and A ⊊ B ? ⊆ = A fits inside B ; ⊊ = fits inside AND B has something extra (A strictly smaller).
Where does 2 O ( f ) come from in the space-to-time argument? It's the number of distinct machine configurations using f cells; a halting machine can't repeat one, so it bounds the step-count.