4.6.21 · D4Theory of Computation

Exercises — Complexity — DTIME, DSPACE, complexity classes

3,384 words15 min readBack to topic

The two resources, once and for all, so no symbol is unearned:

  • = the length (number of characters) of the input string .
  • Time = number of computation steps. Space = number of distinct tape cells the head ever visits.
  • = languages a deterministic Turing machine decides in steps.
  • = languages decided in cells. Swap for the guessing (nondeterministic) versions.
Figure — Complexity — DTIME, DSPACE, complexity classes

Level 1 — Recognition

Exercise 1.1

Fill the blanks: is a set of == (languages / numbers / machines), and the "D" stands for ==.

Recall Solution

is a set of languages (decision problems), not single problems and not machines. The D stands for deterministic — at every step the next move is uniquely forced, no guessing. (Contrast: N = nondeterministic, which may branch.)

Exercise 1.2

Which resource does each class budget — time or space? , , , , , .

Recall Solution
  • time (polynomial steps, ).
  • space (, work-tape cells only).
  • space ().
  • time (nondeterministic, ).
  • time ().
  • space ().

Mnemonic: the letter L or SPACE in the name = space; P, NP, EXP = time.

Exercise 1.3

True or false: . Give the one-line reason.

Recall Solution

True. In steps a work-tape head moves at most one cell per step, so it visits at most work cells. Hence time space , i.e. . Taking the union over gives . In the ring picture (s01), the ring sits inside the ring — that is exactly this inclusion.


Level 2 — Application

Exercise 2.1

A 2-tape TM (read-only input tape + one work tape) decides palindromes by comparing input cell with input cell for . Give a tight time bound as a and name the smallest standard time class containing it.

Recall Solution

Upper bound . There are about comparisons. To align input head against input head the head must sweep up to cells, so each comparison costs steps. Total .

Lower bound (for this single-work-tape algorithm). After matching one pair, the head must travel from position back toward position to start the next comparison — a traversal of length done times. No reordering avoids these long head trips on one work tape, so at least steps are forced.

Conclusion. Both bounds meet, so this algorithm is hence palindromes ; the smallest standard time class is . (A different, cleverer 2-tape machine that first copies the input reversed onto the work tape reaches time — tightness above is a statement about the given comparison algorithm, not a lower bound on the problem.)

Exercise 2.2

Same palindrome problem, but count space: the machine stores two counters and on its work tape. How many bits does a counter holding a value up to need, and which space class results?

Recall Solution

A counter whose value can reach needs bits — because binary uses one bit per doubling. Two such counters (on the work tape, so they are charged as space) is still ; the input tape holding is read-only and not charged. So palindromes .

Concrete check: for , a counter needs bits. Two counters = bits of work tape — tiny, no matter how big the string is.

Exercise 2.3

Reachability: given a directed graph on nodes and nodes (all on the read-only input tape), decide if is reachable from . Describe an machine and state exactly what it stores on its work tape.

Recall Solution

, , sit on the read-only input tape (free). The nondeterministic machine keeps only two things on its work tape (both charged):

  1. the current node (an index in ) — bits,
  2. a step counter counting up to bits.

Repeatedly: guess a neighbour of the current node (checking the edge against the input tape), move there, increment the counter. Accept if the current node equals ; reject if the counter exceeds (a simple path visits nodes, so no honest path is longer). Total work-tape space ⇒ Reachability . We never store the whole path — that is the whole trick.


Level 3 — Analysis

Exercise 3.1

Prove from first principles: for . Explain each factor in the configuration count and show why the polynomial factors vanish into the exponent.

Recall Solution

A configuration is a complete snapshot of the machine: (current state, positions of the input head and work head, contents of the used work cells). Count how many distinct snapshots exist:

  • : finitely many control states — a constant.
  • : the read-only input head can sit over one of input positions.
  • : the work head sits in one of used work cells.
  • : each of work cells holds one of tape symbols.

Why the polynomial factors are absorbed. Take of the whole product: Because , the term dominates every other term (each of the others is or smaller). So the whole logarithm is , which means A halting machine never repeats a configuration (a repeat means an infinite loop). So its number of steps is at most the number of configurations, . Hence it runs in . Bounded space forces bounded time.

Exercise 3.2

Using Ex 3.1, explain why but not the reverse inclusion is known, and why this places inside .

Recall Solution

Set (polynomial space). Ex 3.1 gives running time , which is exactly the budget . Taking unions: . In s01 the ring sits inside the ring.

The reverse () is not known and is believed false — an exponential-time machine may genuinely need exponentially many cells.

: an problem has certificates of length . Deterministically try all certificates one at a time, reusing the same work cells for each attempt. Only polynomial space is ever occupied — the exponential blow-up is in time, not space. See Space vs Time Tradeoffs.

Exercise 3.3

State Savitch's Theorem and use it to bound the deterministic space cost of Reachability (from Ex 2.3).

Recall Solution

Savitch: for . The engine: reachability within steps splits at a midpoint into two reachability problems of steps; recursion depth , each level storing one midpoint of bits, giving total work-tape space.

Reachability is in , so . Savitch gives So the deterministic version of Reachability costs space — see Savitch's Theorem.


Level 4 — Synthesis

Exercise 4.1

Show SAT and SAT , giving the resource bound for each, and say in one sentence what the gap between them illustrates.

Recall Solution

NP route (guess then verify): a formula on variables has a truth assignment describable in bits. Guess those bits nondeterministically, then evaluate the formula — plugging in values and checking each clause is time. So SAT .

EXP route (brute force): deterministically enumerate all assignments; evaluate each in poly time. Cost .

What the gap shows: checking a proposed solution is cheap (poly), while finding one is currently exponential — the beating heart of . See NP-Completeness and Reductions.

Exercise 4.2

For variables, compute the brute-force assignment count , and the certificate length in bits that the NP verifier reads. Contrast the two numbers.

Recall Solution
  • Brute-force assignments: — over a million full evaluations.
  • NP certificate length: exactly bits (one bit per variable), read once.

The verifier looks at 20 bits; the deterministic searcher may look at over a million assignments. That vs contrast is precisely why guessing well would be so powerful — and why we cannot currently do it deterministically in polynomial time.

Exercise 4.3

Order these classes into the full known chain and mark the two inclusions that are known to be strict: .

Recall Solution

Known strict (via the Hierarchy Theorems):

  • — by the deterministic time hierarchy theorem: with time-constructible and you get ; pick , .
  • — this one needs care: is a nondeterministic space class, so separating it from uses the nondeterministic space hierarchy theorem (with the proper space-constructibility condition on the bounds), which gives (the middle step is Savitch). It is not just "the space hierarchy" applied naively — the nondeterministic version and constructibility are essential.

Every inclusion strictly between these (e.g. vs , vs ) is open. The rule: hierarchy theorems separate classes of the same type (D-time vs D-time, or N-space vs N-space), not vs of the same budget.


Level 5 — Mastery

Reminder for this level: denotes the encoding of machine as a finite string (its states and transitions spelled out), which any machine can take as input.

Exercise 5.1

Prove that (i.e. the inclusion is strict) without citing the theorem name — reconstruct the diagonalization idea from scratch.

Recall Solution

The Time Hierarchy Theorem says: if grows enough faster than (precisely ), then . Here is why, built from zero:

  1. Simulate. With a time budget , build a universal machine that, given the code of any machine using only time, runs on its own code. The simulation overhead is a factor of about , which the gap absorbs — so finishes within .
  2. Flip. Define a language : string is in iff (running in time ) rejects its own code. is decidable in (just simulate and flip the bit).
  3. Contradiction. Suppose , decided by some machine . Feed its own code . Then iff rejects iff — a flat contradiction. So .

Thus : strictly more languages with more time. Choosing (any polynomial) and (well inside ) satisfies the gap, so no polynomial time class captures , yet does. Therefore . This is the same self-referential move as the halting-problem argument in Decidability and the Halting Problem.

Exercise 5.2

Explain precisely why this diagonal argument proves but fails to settle vs .

Recall Solution

Diagonalization needs the bigger class to simulate every machine of the smaller class and then flip its answer, all within its own budget. This works when both classes measure the same resource (time vs time): more time can host the simulation-plus-flip.

For vs the difference is not "more of the same resource" but a change of machine type ( vs ). A deterministic machine cannot cleanly "flip" a nondeterministic machine's answer, because -acceptance is an existential (accept if some branch accepts) — its negation is a universal, which is not the same machine model. So the diagonal trick does not transfer. Formally, results like the relativization barrier show diagonalization alone cannot resolve vs . That is why one gap is a theorem and the other is a millennium prize.

Exercise 5.3

Steel-man and refute: "Because space is reusable and time is not, must contain — memory is the cheaper, more powerful resource, so space classes are the small ones."

Recall Solution

The strong version of the claim: a single tape cell can be overwritten and reused across many steps, so a fixed amount of memory supports arbitrarily long computations. It genuinely feels like space is the "richer" resource.

Why it is exactly backwards for inclusions:

  • Reuse means space time (Ex 1.3 / Step 1): you can never touch more work cells than you have steps, so — small time sits inside small space.
  • Reuse also makes space powerful in the other direction: bounded space permits up to configurations (Ex 3.1), hence that much time — so .

Combining: contains all of and sits below — it is a huge class (a large outer ring in s01), not a small one. The reusability of memory is precisely what makes space classes large, so the claim's conclusion ("space classes are the small ones") is refuted by its own premise. See Space vs Time Tradeoffs.