The Time and Space Hierarchy Theorems
Suppose someone hands you a Turing machine that decides a language using at most steps on every input of length . Can this machine also be simulated by a machine that only ever gets steps? Intuition says no — doubling a budget should let you compute more. But intuition is not proof. Complexity theory is full of surprises where extra resources buy nothing. Recall that nondeterministic space classes collapse under complementation in ways time classes do not. The Time and Space Hierarchy Theorems settle this question rigorously. They show that giving a Turing machine asymptotically more time, or more space, strictly increases the set of languages it can decide. This holds at least once the resource bound is large enough to be "constructible". The increase must also be large enough to matter. This matters because almost every claim in complexity theory about some problem being hard rests on one thing. It rests on knowing that resource classes are not all secretly the same class in disguise. Without hierarchy theorems, statements like "" would have no proof technique at all. In fact is proved exactly by a time hierarchy argument. This makes it one of the few strict separations between two natural complexity classes we can prove unconditionally. This contrasts with the still-open vs question. The proof method is diagonalization. It is the same idea Cantor used to show the reals are uncountable. Turing used it too, to show the halting problem is undecidable. Here it is repurposed with a resource-bounded twist. Build a machine that, for every candidate machine running within the smaller bound, simulates long enough to disagree with it on some input. But do this simulation itself within the larger bound. The delicate engineering is in making the simulation efficient enough. must still fit inside its own generous budget. Yet it must still have enough budget left over to flip the answer. This article builds the machinery from scratch. It covers constructible functions, the universal simulating machine, and the diagonalization argument for time. It covers the analogous (and cleaner) argument for space. It also gives precise statements of both theorems with their sufficient gap conditions. Finally, it covers the concrete consequences — , , and an infinite strict tower of classes in between. These separations are the bedrock beneath everything built later on the Polynomial Hierarchy. They also underlie our understanding of how randomized classes like BPP relate to deterministic time.
- Hierarchy theorems prove that strictly more time or space strictly increases computational power, via diagonalization.
- The Time Hierarchy Theorem needs a time-constructible bound and a quadratic-ish gap: when .
- The Space Hierarchy Theorem is tighter: whenever , no log factor needed.
- Both proofs build a diagonalizing machine that simulates every machine bounded by the smaller resource and flips its answer.
- Consequences include and — rare unconditional separations in complexity theory.
- These theorems are the scaffolding beneath later results on the Polynomial Hierarchy and time/space tradeoffs used to analyze BPP.
A machine that simulates every smaller-budget machine and deliberately disagrees with each one cannot itself be decided within that smaller budget — so more resources provably buy more power.
The idea
A complexity class hierarchy theorem asserts that increasing a resource bound (time or space) by enough of a margin creates a language decidable in the larger bound but not in the smaller one. To even state such a theorem we need the bound function itself to be computable without blowing past the budget it describes — otherwise a machine cannot know when to stop simulating. A function is time-constructible if there is a Turing machine that, given input (the unary string of length ), outputs the binary representation of using steps. It is space-constructible if some machine computes from using space. Nearly every function you would write down — , , , — is constructible; pathological non-constructible functions are needed only to build counterexamples showing the theorems are tight. The two theorems are:
Time Hierarchy Theorem. If is time-constructible and , then
Space Hierarchy Theorem. If is space-constructible and , then
Notice the asymmetry: time needs a overhead margin, space needs none. This is not a proof artifact to be waved away — it reflects a genuine simulation cost. Simulating one Turing machine by another (a universal simulation) using a single-tape or fixed-alphabet machine multiplies running time by a logarithmic factor (bookkeeping to track another machine's head position and state costs extra steps per step), whereas simulating another machine's space usage costs no asymptotic space overhead — you can reuse the same tape cells to track another machine's tape cells with only a constant multiplicative factor. This single fact — that space simulation is "free" while time simulation is "log-costly" — is the entire reason the two theorems have different gap requirements, and is worth remembering as the one sentence that explains both proofs simultaneously.
How it works
Both proofs follow the same three-step recipe: (1) fix an enumeration of all Turing machines, (2) build a universal diagonalizer that on input interprets itself as encoding a machine , simulates on within the target resource bound , and outputs the opposite of what outputs, (3) argue the -bounded class but the -bounded class, because if some -bounded machine decided the same language as , feeding the description of produces a direct contradiction.
Step-by-step construction of the diagonalizer
``` // D is a Turing machine with two behaviors, parameterized by g(n) // Input: a string w of length n, interpreted as possibly with padding procedure D(w): n := length(w) budget := compute g(n) // uses constructibility of g M := decode(w) // extract a TM description from w // (if w does not parse, treat M as // a fixed reject-everything machine) result := SIMULATE(M, w, budget) // runs M on input w for at most `budget` steps (time version) // or within `budget` tape cells (space version) // if M has not halted when the budget is exhausted, treat result as REJECT if result == ACCEPT: return REJECT else: return ACCEPT ``` The crucial subroutine is `SIMULATE`, a universal machine that runs an arbitrary encoded machine on input while enforcing a hard resource ceiling. Its efficiency determines whether itself fits inside or .
- Time version. A single-tape universal simulator can simulate steps of a -tape machine in steps, because each simulated step requires scanning across a representation of 's tapes whose relevant portion has grown to length , and locating/updating symbols costs an extra factor with an efficient encoding. So simulating for up to steps costs about steps of its own. For to run within its own time budget , we actually design 's target class as where was chosen with the log slack already built in — this is precisely why the theorem's hypothesis is rather than just : we need itself to have room to absorb the overhead of simulating machines bounded by .
- Space version. A universal simulator can track another machine's configuration using only extra tape cells beyond what itself uses (storing 's current state, head positions as tape markers, and reusing 's own tape layout rather than copying it). So simulating within space costs only space, with no logarithmic penalty — hence no log slack is needed in the space theorem's hypothesis.
- The clock/ruler and the diagonal trick. In both versions, `SIMULATE` must enforce the budget: for time, maintains a counter (itself costing only a constant multiplicative overhead to store and increment) and aborts the simulation, treating as rejecting, if has not halted after `budget` steps; for space, marks off a fixed number of tape cells (using the constructed value as a literal boundary marker) and aborts if tries to leave that region. This is why constructibility is required: must be able to compute itself, within the same resource bound, in order to know where to place the clock or the ruler.
- Self-reference via encoding. Because is simultaneously "the input" and "the description of the machine being simulated," is diagonalizing against all machines, including itself, in the classic Cantor/Turing style. If some machine with encoding decides the same language as using resource , then running on input must simultaneously equal `SIMULATE`'s result (since agrees with everywhere, by assumption) and also equal the flip of that result (by 's own definition) — a contradiction, provided the simulation actually completes within budget, which the resource gap guarantees.
Complexity & correctness
Correctness of the Time Hierarchy Theorem. Let satisfy with time-constructible (the standard statement assumes itself is time-constructible so can compute its own clock; some textbook variants only require constructible and phrase the gap differently, but the constructible- version is the clean one to prove). Define as above with `SIMULATE` implementing a universal simulator that charges steps to simulate steps of an arbitrary machine. Then: 1. runs in time : computing costs by constructibility, and simulating up to steps of costs — wait, this needs care. The standard resolution: we simulate for up to steps (not ), aborting and rejecting if hasn't halted by then, costing , which is by hypothesis; the extra overhead for computing the clock and bookkeeping keeps the total at . So . 2. No machine deciding 's language runs in time . Suppose decides and runs in time . By the padding/encoding scheme there are infinitely many strings with (via padding, since a machine has infinitely many equivalent encodings of growing length), each long enough that the simulation budget exceeds 's actual running time on that particular . Feeding such a to : simulates on to completion within the allotted steps (since 's real running time is and the constant/padding is chosen large enough), obtains 's true answer, and outputs the opposite. So . But was assumed to decide , i.e. for all — contradiction. Hence no -time machine decides , so . The padding argument deserves a note: to make the "infinitely many with and long enough" step work rigorously, one fixes an encoding scheme where a machine can be padded with unused suffix symbols to reach any larger length while computing the same function, which is a standard, harmless technicality.
Correctness of the Space Hierarchy Theorem. The structure is identical but the arithmetic is friendlier because of the free space simulation. Let with space-constructible. Build identically, except `SIMULATE` uses a space-efficient universal simulator: tracking 's configuration (state, head positions, relevant tape contents) costs only extra cells beyond 's own usage, so simulating a machine using space costs only space. Then: 1. : computing costs space (constructibility), and simulating within an -cell budget costs space — well within the ceiling. 2. By the same contradiction argument, no -space machine can decide : if used space and decided , then on a suitably padded encoding , simulates to completion within space , learns , and outputs the opposite, contradicting deciding . So , giving the strict containment, with no logarithmic slack required — precisely because space, unlike time, can be reused by a simulator rather than paid for again.
Why the gaps are necessary, not artifacts. These are not proof-technique laziness; sub-quadratic-ish gaps for time genuinely can fail to separate classes in some models, and the linear speedup theorem for space (space usage can be divided by any constant via a larger tape alphabet) is exactly why the space theorem's threshold is a clean little-o with no constant slack needed either — constant factors in space don't matter at all, unlike in time where constant factors are already absorbed by the linear speedup theorem for time but the log factor from universal simulation survives that speedup and must be paid explicitly.
Complexity of the theorems' "output." The theorems themselves are proved in polynomial-in- meta-time (constructing 's tape and running the simulation), which is irrelevant to their content — the theorems are statements about which languages fall into which resource classes, not about the runtime of the proof. The one honest caveat: the theorems give existence of a separating language, typically an artificial diagonal language, not a natural or interesting one; showing a specific natural problem (like SAT) requires more than time or more than space is a separate, often open, question.
Worked example
Concretely instantiate the Time Hierarchy Theorem with and check whether gives a valid separation, then check a tempting but invalid attempt with vs. a bigger .
Case A: , . Check the hypothesis: is ? Yes — grows strictly slower than for large (polynomial beats polylog-times-lower-polynomial). So the theorem applies:
| Step | Quantity | Value / reasoning |
|---|---|---|
| 1 | Constructibility check | is time-constructible (compute by repeated multiplication in time) |
| 2 | Gap check | ✓ |
| 3 | Build | On input of length , decode candidate machine , simulate up to steps |
| 4 | Cost of simulation | steps |
| 5 | Total cost of | (constructing clock) |
| 6 | Conclusion | but no -time machine equals everywhere |
So there genuinely exist languages decidable in cubic time but not quadratic time.
Case B: a tempting but failing attempt — , . Check: is ? No — grows faster than , so is not ; in fact eventually dominates . The hypothesis fails, and indeed the proof breaks concretely: would need steps just to simulate an -bounded machine, but its own budget is only — the simulation cannot finish inside 's own allowance, so does not fit in and the argument collapses. This is why the theorem's stated gap is not cosmetic: shrink it and the diagonalizing machine literally cannot afford to diagonalize.
Case C: the space version, for contrast. Take , . Check : yes, trivially, . No log-squared correction needed anywhere — the simulator tracking a linear-space machine costs only extra space, safely inside the budget with enormous room to spare. This gives
a separation that would have needed a far bigger gap in the time setting to survive the log-overhead of universal simulation.
Common pitfalls & traps
| Pitfall | Why it's wrong |
|---|---|
| Assuming suffices for the time hierarchy | It doesn't — you must absorb the simulation overhead; e.g. vs is not guaranteed separated by this theorem |
| Forgetting constructibility of (or ) | Without it, cannot compute its own clock/ruler within budget, so the diagonalizer might not fit its own resource class |
| Believing the separating language is "natural" | The theorem only guarantees existence of some diagonal language; it says nothing about SAT, 3-COLORING, or other natural problems |
| Confusing "no faster machine decides this exact language" with "the class is separated for all problems" | The theorem is about class containment, not about every individual problem's exact complexity |
| Ignoring the padding argument's role | Without infinitely many valid encodings of growing length, the "for infinitely many " step in the contradiction fails |
| Mixing up which theorem needs the log slack | Time needs it (per-step simulation overhead); space does not (simulation reuses tape essentially for free) |
Pioneers & history
The hierarchy theorems emerged from the same wave of foundational work that gave rise to complexity theory as a discipline distinct from computability theory — the shift from asking "can this be computed at all?" to "how much resource does computing it cost?" The time hierarchy theorem is due to Hartmanis and Stearns, whose 1965 paper is often cited as the founding document of computational complexity theory; the space hierarchy and related tape-complexity results grew out of the same collaboration and subsequent work with Lewis.
Origins · 1 minJuris Hartmanis and how this was discovered
Where this matters
Hierarchy theorems are invoked wherever someone needs a guaranteed separation rather than a conjectured one. Compiler and runtime engineers rely implicitly on the intuition these theorems formalize: allocating an algorithm more time or memory really can unlock strictly more capability, not just faster constants — this is the theoretical bedrock beneath the entire practice of algorithmic complexity analysis taught alongside Measuring Time Complexity and Measuring Space Complexity. In cryptography, hardness assumptions often implicitly lean on hierarchy-style intuition (that exponential time genuinely outclasses polynomial time) even though the specific cryptographic hardness assumptions themselves remain unproven; the hierarchy theorems are the closest thing we have to a proven instance of "more resources help," which grounds why such assumptions are plausible rather than absurd. In complexity theory pedagogy and research, the theorems are the standard first example of an unconditional separation, contrasted immediately with vs , to teach students what a proof of inequality between complexity classes actually looks like. They underlie the proof that the class L is strictly contained in PSPACE (via the chain ), and they justify why researchers studying the Polynomial Hierarchy believe its levels are plausibly distinct even without proof, by analogy to the proven strictness of the time and space towers. They also inform time-space tradeoff arguments used when analyzing randomized classes such as BPP, where derandomization results must respect the fact that time and space resources are provably not fungible without cost.
Ask the tutor: How does the padding argument formally guarantee infinitely many valid input lengths for the diagonalization contradiction?
Why can't we just say f(n) = o(g(n)) is always enough for any hierarchy theorem?
Because the proof needs a diagonalizing machine that simulates every -bounded machine while still fitting inside the budget itself. In the time model, a universal simulator pays roughly a logarithmic multiplicative penalty per simulated step, since tracking another machine's head positions and state on a different tape requires extra bookkeeping steps that grow with the simulated running time. So simulating an -time machine can cost around steps, and if isn't large enough to absorb that overhead, literally cannot finish the simulation within its own allotted budget, and the whole argument collapses. Space simulation has no such per-step penalty, which is why only the time theorem needs the extra factor in its gap condition.
Does the Time Hierarchy Theorem tell us P ≠ NP?
No, and this is one of the most common misunderstandings. The theorem separates deterministic time classes from each other directly, like from , and this chain of separations does prove , because is the union of all polynomial deterministic time classes while contains classes strictly larger than any polynomial. But is defined via nondeterministic time, and no known diagonalization technique successfully separates from , largely because nondeterministic computation cannot be efficiently simulated and then "flipped" the way deterministic computation can — you cannot cheaply complement a nondeterministic guess-and-check process. This gap is exactly why vs remains open.
What exactly is the diagonal language L(D) — is it some famous problem?
No — it is a deliberately artificial language, essentially "the set of strings such that, when is interpreted as a machine description and run on itself within the target budget, it either doesn't accept or doesn't finish in time." It is constructed purely to be different from every machine in the smaller class, by design, rather than because it corresponds to some natural computational task like sorting, satisfiability, or graph coloring. The theorems guarantee that some language separates the classes, but proving that any specific natural, previously studied problem lies strictly between two levels of a hierarchy is a separate and often much harder (sometimes still open) question.
How does this relate to L and NL and the broader space hierarchy?
The Space Hierarchy Theorem directly implies that classes like are strictly smaller than , which is strictly smaller than , and so on up through , giving an infinite strict tower of space classes between logarithmic and polynomial space. This chain proves unconditionally. It says nothing directly about , the nondeterministic analogue, since the diagonalization technique used here is inherently deterministic — flipping a "yes/no" answer only makes sense when there is a single deterministic answer to flip, not a nondeterministic branching computation.
Why does padding matter in the proof, and what would go wrong without it?
The contradiction argument needs infinitely many input strings that both encode the candidate machine (so that simulates exactly when given ) and are long enough that 's claimed running time bound actually exceeds 's real running time on that specific , guaranteeing the simulation finishes. Since a fixed machine has a description of some fixed finite length, we use a padding convention: append harmless filler symbols to to produce equivalent encodings of any larger length, all still recognized as "the machine " by the decoding scheme. Without padding, we could only test against at a single input length, which is not enough to derive the required contradiction for an asymptotic separation.
Are these theorems still used in modern complexity research, or are they just historical?
They are foundational and still actively invoked, not merely historical curiosities. Every course and paper that needs an unconditional, unconjectured resource separation reaches for a hierarchy theorem, and results about time-space tradeoffs, about the structure of the Polynomial Hierarchy's plausibility, and about lower bounds in restricted models all build on the same diagonalization skeleton. They also serve as the standard teaching example for what a genuine complexity-class inequality proof looks like, which makes them essential scaffolding before tackling deeper open questions like vs or the exact power of randomized classes such as BPP.
What's the single most important intuition to retain if I forget the technical statement?
More resources provably buy more computational power, but only once you pay the "overhead tax" of simulating everything with less power — and that tax is logarithmic for time and essentially free for space. That asymmetry is the entire reason the two theorems look different on paper despite sharing an identical diagonalization skeleton. If you remember that one sentence, you can reconstruct why the time theorem needs a bigger gap, why the proof structure is a self-referential contradiction machine, and why the resulting separations are guaranteed to exist but not guaranteed to correspond to any problem you've heard of.