Unit 1

Models and Computational Resources

Turing machines, robust encodings, and the time and space measures used to compare computations.

Goals

  • Define deterministic Turing-machine time and space.
  • Explain why reasonable machine variants agree polynomially.
  • Read a configuration graph as a computation.

Intuition

A model fixes what one elementary step can do. Resource bounds then make comparisons meaningful. Complexity classes are useful because ordinary deterministic models simulate one another with modest overhead.

Formal definitions

For a machine MM, let tM(n)t_M(n) be the maximum number of steps on any input of length nn on which MM halts. Its space sM(n)s_M(n) is the maximum number of work-tape cells visited; the read-only input is conventionally excluded. A configuration records the state, tape contents, and head positions.

A deterministic single-tape machine is a tuple

M=(Q,Σ,Γ,δ,q0,qacc,qrej),M=(Q,\Sigma,\Gamma,\delta,q_0,q_{\mathrm{acc}},q_{\mathrm{rej}}),

where QQ is finite, Σ⊆Γ\Sigma\subseteq\Gamma, Γ\Gamma contains blank ⊔\sqcup, and

δ:(Q∖{qacc,qrej})×Γ→Q×Γ×{L,R}.\delta:(Q\setminus\{q_{\mathrm{acc}},q_{\mathrm{rej}}\})\times\Gamma \to Q\times\Gamma\times\{L,R\}.

On input xx, the tape initially contains xx followed by blanks, the head scans its first symbol, and the state is q0q_0. One transition reads and writes one symbol, changes state, and moves one cell. A recognizer may loop on nonmembers; a decider halts on every input. Complexity classes below are defined using deciders.

Configurations and computations

Notation such as uqavu q av records tape content uavuav, state qq, and a head scanning aa. Write C⊢MC′C\vdash_M C' for one legal transition and ⊢M∗\vdash_M^* for zero or more. A computation is

C0⊢MC1⊢M⋯⊢MCt.C_0\vdash_M C_1\vdash_M\cdots\vdash_M C_t.

For a deterministic machine each nonhalting configuration has at most one successor. Therefore, if a run repeats a configuration, its unique future repeats forever and it cannot later halt.

Guided construction

Deterministic configuration graph

Step 1 of 7
Input x=1010Invariant: state records parity of the 1s already scannedδ(q_even, 1) = (q_odd, R)
Deterministic parity-machine configuration pathSix configurations form one path. Each nonhalting configuration has exactly one outgoing transition.q_evenhead = 0scans 1[1] 0 1 0 □
q_evenhead position 0 · scanned symbol 1
1
0
1
0
□
Unique next moveδ(q_even, 1) = (q_odd, R)
visited configurationunique legal transitioncurrent head position

In the graph, identify the complete information in one node and follow its unique outgoing edge. A configuration is one snapshot, not the history leading to it.

Encodings and universal simulation

A machine is a finite object, so states, symbols, directions, and transition entries can be encoded as bits. A tuple encoding ⟨x,y⟩\langle x,y\rangle must be injective and efficiently decodable; raw concatenation is not enough because its boundary may be ambiguous. Invalid descriptions can be rejected or interpreted as a fixed trivial machine, provided the convention is explicit.

A universal machine UU interprets a machine description and input:

U(⟨M,x⟩)=M(x)U(\langle M,x\rangle)=M(x)

whenever the simulated computation halts, with the same result. It stores an encoded current configuration, finds the matching transition in ⟨M⟩\langle M\rangle, updates the encoding, and repeats. This is the formal basis for treating programs as data and later for diagonalization.

The overhead depends on the representation. If MM is fixed, constants may depend on MM; if ⟨M⟩\langle M\rangle is part of the input, its length must be counted. Universality establishes controlled simulation, not equal running time.

Example. A parity machine scans right and toggles between “even” and “odd” states whenever it reads 11. At the first blank it accepts exactly when the state is “even.” It uses n+1n+1 transitions. A universal machine given its table and xx returns the same answer, usually with extra interpretation time.

Robustness theorem. A multitape deterministic Turing machine running in time t(n)t(n) can be simulated by a standard one-tape machine in time O(t(n)2)O(t(n)^2), under standard conventions.

Proof walkthrough

Encode all virtual tapes on one physical tape, separated by delimiters, with marked head positions. One simulated step scans the used region, updates symbols, and possibly shifts data. Since at most O(t(n))O(t(n)) cells have been reached after t(n)t(n) steps, each simulation step costs O(t(n))O(t(n)) and the total is O(t(n)2)O(t(n)^2).

More explicitly:

  1. The simulator places the kk tapes on tracks with one marked cell per virtual head.
  2. A sweep collects the kk scanned symbols in finite control.
  3. The fixed transition table determines all writes and moves.
  4. A second sweep updates symbols and markers, extending the representation when needed.
  5. In t(n)t(n) steps, each head reaches at most t(n)+1t(n)+1 cells, so the encoded region has length O(t(n))O(t(n)) for fixed kk.
  6. Multiplying t(n)t(n) simulated steps by O(t(n))O(t(n)) work per step gives O(t(n)2)O(t(n)^2).

For space, the tracks require only a constant-factor increase for fixed kk. Thus standard machine variants preserve asymptotic space, subject to the same input convention.

Measuring time and space

For a decider, the worst-case time is

TM(n)=max⁡∣x∣=n{steps before M halts on x}.T_M(n)=\max_{|x|=n}\{\text{steps before }M\text{ halts on }x\}.

The maximum exists because there are finitely many length-nn strings and every run halts. It includes yes- and no-instances. Space counts the maximum number of distinct work-tape cells touched. The usual model gives a separate read-only input tape, because charging its nn cells would make sublinear space impossible merely from input storage.

A time-t(n)t(n) machine reaches at most O(t(n))O(t(n)) cells because a head moves one cell per step. Hence time bounds imply comparable space bounds. The converse fails: a bounded-space machine can revisit cells for a long time. Nevertheless, a halting fixed machine using s(n)≥log⁡ns(n)\ge\log n space has only 2O(s(n))2^{O(s(n))} configurations, so it cannot run longer without repeating one.

Worked example

To decide whether a binary string has equally many zeros and ones, repeatedly cross off one uncrossed zero and one uncrossed one. This is polynomial time and linear space, although a counter-based multitape implementation is faster.

For a more detailed analysis, each round performs at most two full sweeps, costing O(n)O(n), and there are at most n/2n/2 rounds. The time is O(n2)O(n^2) and the tape footprint is O(n)O(n). Correctness follows from the invariant that every completed round has marked exactly one 00 and one 11; the machine accepts precisely when no unmatched symbol remains.

Common mistakes

  • Counting input cells as work space without stating that convention.
  • Assuming all models simulate RAM arithmetic at unit cost for arbitrarily large integers.
  • Confusing a configuration with the full computation history.
  • Saying “simulate” without bounding the cost of one simulated step.
  • Omitting state or head position from a configuration.
  • Claiming the one-tape simulation preserves exact time.

Visualization prompt

Draw configurations as nodes and legal transitions as edges; highlight one deterministic path and the bounded set of tape cells it visits.

Exercises

Exercise 1 — Decider for 0m1m0^m1^m

Describe a single-tape decider for {0m1m:m≥0}\{0^m1^m:m\ge0\}. Prove correctness via an invariant, prove halting, and derive O(n2)O(n^2) time and O(n)O(n) space.

Solution

Construction. First scan and reject if a 00 appears after a 11. Then, in each round: mark the leftmost unmarked 00, move right, mark one unmarked 11, and return. Reject if a mate is missing; accept when both kinds are exhausted together.

Invariant. After ii rounds exactly ii zeros and ii ones are marked, and the unmarked part is 0m−i1m−i0^{m-i}1^{m-i} (unless already rejected as malformed).

Halting. Each round marks at least one new symbol, so there are at most nn rounds; each sweep ends at the tape end.

Resources. Each sweep costs O(n)O(n) and there are O(n)O(n) rounds, so time is O(n2)O(n^2). The tape footprint is O(n)O(n), so space is O(n)O(n).

Exercise 2 — Pair encoding

Prove that (x,y)↦xy(x,y)\mapsto xy is not a valid pairing. Prove that (x,y)↦0∣x∣1xy(x,y)\mapsto 0^{|x|}1xy is uniquely and efficiently decodable, and bound the encoding length.

Solution

Concatenation fails. Both (0,11)(0,11) and (01,1)(01,1) produce 011011. The boundary is not unique.

Valid encoding. From 0∣x∣1xy0^{|x|}1xy, count leading zeros until the delimiter 11, read exactly that many bits as xx, and take the rest as yy. Decoding is unique and efficient (linear on a multitape TM). Length is ∣x∣+1+∣x∣+∣y∣=O(∣x∣+∣y∣)|x|+1+|x|+|y|=O(|x|+|y|).

Exercise 3 — Configuration transition

The machine is in state qq, reads 00, writes XX, moves right, and enters rr. Write the successor of u q 0vu\,q\,0v. Handle v=εv=\varepsilon explicitly.

Solution

Under the usual notation, the transition on u q 0vu\,q\,0v yields uX r vuX\,r\,v.

If v=εv=\varepsilon, the head moves onto a new blank: the successor is uX r ⊔uX\,r\,\sqcup. Explicit edge handling prevents a missing configuration.

Exercise 4 — Time bounds space; repeated configuration

  1. Prove that a decider running in time t(n)t(n) uses O(t(n))O(t(n)) space.
  2. Prove that in a deterministic machine, repeating a configuration implies non-halting from that point on.
Solution
  1. Each step moves a head by at most one cell, so after t(n)t(n) steps at most O(t(n))O(t(n)) cells have been visited.

  2. Determinism gives a unique successor from every nonhalting configuration. If CC repeats, the path from CC onward is periodic and cannot reach a halting state that did not already appear in the cycle — in particular it cannot halt after the repetition.

Exercise 5 — Two-tape versus one-tape simulation

A two-tape machine copies an input of length nn and then makes nn passes over the copy. Bound time and space. What safe bound does the one-tape simulation theorem give? What does the theorem not claim?

Solution

Copying costs O(n)O(n); nn passes together cost O(n2)O(n^2); total time O(n2)O(n^2). Space O(n)O(n) (reused cells counted once).

The one-tape simulation theorem gives the safe bound O((n2)2)=O(n4)O((n^2)^2)=O(n^4). It is only an upper bound: it does not claim the simulator must use that much time, nor that every linear-time multitape problem requires quadratic one-tape time.

Summary

Time counts steps, space counts reusable work cells, and configuration graphs expose both. Polynomial robustness depends on reasonable encodings and cost conventions.

Guided practice

Task 1 — Universality and quantifiers

A machine description has length mm and the input has length nn. Explain when decoding overhead may be absorbed into a constant, and when it may not. State the quantifiers.

Solution

If MM is fixed (not part of the input), ∣⟨M⟩∣=m|\langle M\rangle|=m is constant and decoding cost may depend on MM as a constant.

If ⟨M⟩\langle M\rangle is part of the input, mm depends on the input and must be counted. Time depends on m+nm+n.

The slogan “universal overhead is constant” requires immediate clarification of ∀M\forall M versus MM in the input.

Task 2 — Comparing palindrome machines

Single-tape machine AA decides palindromes by marking extreme pairs in O(n)O(n) rounds of O(n)O(n) sweeps. Two-tape machine BB copies and compares from both ends in O(n)O(n) time. Compare time and space, bound the one-tape simulation of BB, encode a configuration of BB that used ss work cells, and bound their number.

Solution

AA: time O(n2)O(n^2), space O(n)O(n). BB: time O(n)O(n), space O(n)O(n). Same language, different times.

A general simulation of BB yields a one-tape machine in O(n2)O(n^2) — matching AA's order as an upper bound.

A configuration of BB: one state from a fixed set, contents of both visited regions, and a head mark on each tape. With ss cells used, encoding length is O(s)O(s) and there are 2O(s)2^{O(s)} encodings. This upper bound (not every string is legal) suffices for loop detection.

Task 3 — Resource checklist

State five mandatory questions before accepting a machine analysis as a resource proof, and answer them for the parity decider that scans right toggling even/odd states.

Solution

Questions: (1) Is the input convention explicit? (2) Does every run halt, including rejects? (3) Cost of one iteration and how many? (4) Are delimiters/description/moves counted? (5) Are distinct cells counted, not write events?

For parity: input on the tape; halts at the first blank accepting or rejecting; n+1n+1 steps; no machine description in the input; O(1)O(1) work beyond the input (or O(n)O(n) on a writable single tape, by convention). Time Θ(n)\Theta(n).

Sources

  • Student-summary evidence: merged course summary, pp. 1-7, 25-27, 86, 101-106, and 132; used for sequencing and course terminology, not final verification.
  • Course evidence: Semester A 2026 transcripts 1-2, TM definitions, encodings, multitape and universal simulation.
  • Verification: Sipser, 3e, pp. 165-181 and 205-212.
  • Verification: Arora and Barak, Computational Complexity, draft pp. 21-42.
  • Verification: Papadimitriou, Computational Complexity, pp. 19-35.