Unit 9

Space Complexity

Space-bounded computation, reachability in configuration graphs, and Savitch's theorem.

Goals

  • Define deterministic and nondeterministic space with read-only input.
  • Use configuration graphs to prove membership and completeness.
  • Compose log-space reductions without storing their output.
  • Derive Savitch's recursion and its full space bound.
  • Explain NL=coNL\mathrm{NL}=\mathrm{coNL} and NPSPACE=PSPACE\mathrm{NPSPACE}=\mathrm{PSPACE} without overstating their proofs.

1. The model and what is counted

A space-bounded multitape Turing machine has a read-only input tape and one or more read/write work tapes. Input-head position is not charged as work space; work-tape cells ever visited are. Output for a transducer is write-only, so it cannot be used as free memory.

SPACE(s(n))=⋃c>0DSPACE(c s(n)),NSPACE(s(n))=⋃c>0NSPACE(c s(n)),L=SPACE(log⁡n),NL=NSPACE(log⁡n).\begin{aligned} \mathrm{SPACE}(s(n))&=\bigcup_{c>0}\mathrm{DSPACE}(c\,s(n)),\\ \mathrm{NSPACE}(s(n))&=\bigcup_{c>0}\mathrm{NSPACE}(c\,s(n)),\\ \mathrm L&=\mathrm{SPACE}(\log n),\qquad \mathrm{NL}=\mathrm{NSPACE}(\log n). \end{aligned}

A nondeterministic decider must halt on every branch and use the bound on every branch. Space differs from time because cells can be reused: a polynomial-space computation may run for exponential time. For conventional machines with s(n)≥log⁡ns(n)\ge\log n, repeated configurations can be removed from any shortest accepting path, so a halting search need not exceed the number of configurations.

2. Configuration graphs

A configuration records the finite control state, input-head position, work-tape contents in the used region, and work-head positions. For fixed alphabet and state set, an s(n)s(n)-space machine has

∣Q∣⋅(n+2)⋅2O(s(n))⋅poly⁡(s(n))=2O(s(n))|Q|\cdot(n+2)\cdot 2^{O(s(n))}\cdot\operatorname{poly}(s(n)) =2^{O(s(n))}

configurations when s(n)≥log⁡ns(n)\ge\log n. Its directed configuration graph has one vertex per legal configuration and an edge for one valid transition. The machine accepts exactly when an accepting configuration is reachable from the start configuration.

This graph is normally implicit. A simulator generates a requested configuration or checks adjacency using O(s(n))O(s(n)) space; writing all exponentially many vertices would destroy the bound.

3. STCON is the canonical NL problem

STCON (directed ss-tt connectivity) asks whether a directed graph has a path from designated ss to tt.

Membership in NL. Store the current vertex vv and a counter up to ∣V∣|V|. Nondeterministically guess a next vertex, verify that the edge exists, and accept on reaching tt. A simple path has length at most ∣V∣−1|V|-1, so the counter prevents endless branches. Both vertex and counter use O(log⁡∣V∣)O(\log|V|) bits.

NL-hardness. Let A∈NLA\in\mathrm{NL} be decided by machine MM. Map input xx to the configuration graph GM,xG_{M,x} with its start and accepting configurations. Acceptance is reachability. The reduction cannot print the whole graph from memory, but a log-space transducer can enumerate configuration names and edge pairs using O(log⁡∣x∣)O(\log |x|) counters, recomputing each local transition. Since configurations of a log-space machine have O(log⁡n)O(\log n) bits, this is a log-space many-one reduction. Therefore STCON is NL-complete.

4. Log-space reductions and composition

A≤mLBA\le_m^{\mathrm L}B means a deterministic log-space transducer computes ff such that

x∈A  ⟺  f(x)∈B,x\in A\iff f(x)\in B,

with polynomially bounded output length. Such a transducer runs in polynomial time: once its work configuration and output position repeat without progress, it loops, which a total transducer cannot do.

The subtle point in composing ff and gg is that f(x)f(x) may be polynomially long and cannot be stored. To compute an output bit of g(f(x))g(f(x)), simulate gg. Whenever it asks for the iith input symbol, rerun the transducer for ff from the start with an O(log⁡n)O(\log n) counter until symbol ii is produced. Store only gg's O(log⁡n)O(\log n) work configuration, ii, and ff's current work configuration. Polynomial output lengths imply log⁡∣f(x)∣=O(log⁡n)\log|f(x)|=O(\log n). Thus log-space reductions compose by recomputation.

Consequently, to prove BB NL-complete, show B∈NLB\in\mathrm{NL} and reduce a known NL-complete problem—usually STCON—to BB. A polynomial-time reduction is not enough for NL-completeness.

5. Savitch's theorem: full recursion

Savitch's theorem. For space-constructible s(n)≥log⁡ns(n)\ge\log n, NSPACE(s(n))⊆DSPACE(s(n)2).\mathrm{NSPACE}(s(n))\subseteq\mathrm{DSPACE}(s(n)^2).

Let MM use O(s)O(s) nondeterministic space and have at most N=2csN=2^{c s} configurations. Define

REACH⁡(u,v,ℓ)=“there is a path from u to v of length at most 2ℓ.”\operatorname{REACH}(u,v,\ell)= \text{“there is a path from $u$ to $v$ of length at most $2^\ell$.”}

Base case ℓ=0\ell=0: accept iff u=vu=v or (u,v)(u,v) is one transition. For ℓ>0\ell>0, enumerate every configuration mm and accept if both

REACH⁡(u,m,ℓ−1)andREACH⁡(m,v,ℓ−1)\operatorname{REACH}(u,m,\ell-1) \quad\text{and}\quad \operatorname{REACH}(m,v,\ell-1)

accept. Correctness follows by splitting a path of length at most 2ℓ2^\ell at its midpoint; conversely, concatenating the two recursive paths gives a path of the allowed length.

Call with ℓ=⌈log⁡N⌉=O(s)\ell=\lceil\log N\rceil=O(s). At one recursion level store u,v,mu,v,m, ℓ\ell, and an enumeration counter: O(s)O(s) bits. The two recursive calls are made sequentially, and midpoint work space is reused. Therefore

S(ℓ)≤S(ℓ−1)+O(s),S(O(s))=O(s2).S(\ell)\le S(\ell-1)+O(s),\qquad S(O(s))=O(s^2).

Time is enormous: roughly NO(log⁡N)=2O(s2)N^{O(\log N)}=2^{O(s^2)}. That is acceptable because the theorem claims space, not time. Multiplying by the recursion's branching factor is a time analysis, not a space analysis.

For s(n)=nks(n)=n^k, Savitch gives

NPSPACE⊆PSPACE.\mathrm{NPSPACE}\subseteq\mathrm{PSPACE}.

The reverse inclusion is immediate because deterministic choice is a special case of nondeterminism. Hence

NPSPACE=PSPACE.\mathrm{NPSPACE}=\mathrm{PSPACE}.

This equality is a direct corollary of Savitch; it is not known whether the analogous logarithmic inclusion collapses to L=NL\mathrm L=\mathrm{NL}, because Savitch only yields NL⊆SPACE(log⁡2n)\mathrm{NL}\subseteq\mathrm{SPACE}(\log^2 n).

6. The complement theorem

Immerman–Szelepcsényi theorem. NL=coNL\mathrm{NL}=\mathrm{coNL}; more generally, NSPACE(s(n))\mathrm{NSPACE}(s(n)) is closed under complement for s(n)≥log⁡ns(n)\ge\log n.

The statement is examinable; the full inductive-counting proof is longer than Savitch's proof. Its key idea is to certify nonreachability without listing all reached vertices. Let RiR_i be vertices reachable from ss in at most ii steps. Nondeterministically verify the count ∣Ri∣|R_i| from ∣Ri−1∣|R_{i-1}| by scanning all vertices and using reachability witnesses of length i−1i-1. Once the exact count of reachable vertices is certified, verify that tt is not among them. Counters and one vertex name require only logarithmic space.

The surprising point is that nondeterminism can certify a universal-looking negative fact by first certifying an exact count. A mere statement “guess that no path exists” proves nothing.

Worked example

Consider vertices 1,2,3,41,2,3,4 and edges 1→21\to2, 2→32\to3, 1→41\to4. The NL STCON machine may guess 1,2,31,2,3 to accept (1,3)(1,3). It stores only the current name and a counter, not the path. For Savitch on the same graph with length bound four, try midpoint m=2m=2: recursively establish a path 1⇝21\leadsto2 of length at most two and 2⇝32\leadsto3 of length at most two. Failed midpoint attempts are discarded before trying the next.

For a reduction-composition example, suppose f(x)f(x) outputs an adjacency matrix and gg reads its entries in arbitrary order. The composition does not cache that matrix. Each request for entry ii reruns ff until its iith output symbol. Time increases, but work space stays logarithmic.

Common mistakes

  • Charging the read-only input tape as work space, or using write-only output as memory.
  • Omitting the step counter in the NL algorithm, leaving nonhalting branches.
  • Materializing the configuration graph.
  • Using a polynomial-time reduction where log-space completeness is required.
  • Storing f(x)f(x) while claiming closure of log-space reductions.
  • Multiplying Savitch's recursive branches into a space bound.
  • Claiming Savitch proves L=NL\mathrm L=\mathrm{NL}.
  • Treating NL=coNL\mathrm{NL}=\mathrm{coNL} as obvious from swapping accepting states.

Visualizations

Guided construction

Savitch recursion

Step 1 of 6
Savitch configuration graph and recursionThe graph 1 to 2 to 3 with an extra edge from 1 to 4 is coordinated with a depth-first recursion for REACH of 1, 3, and level 2.Implicit configuration graph1234witness path: 1 → 2 → 3 (2 ≤ 4)Depth-first recursionbounded call appears next
Witness pathActive stack frame

Draw two views of the same computation: an implicit configuration graph and the depth-first Savitch recursion. Show only one active recursive path in memory. A second panel can depict composition as an on-demand wire: gg requests position ii, and ff is replayed to regenerate it.

Exercises

Exercise 1 — Short accepting path

Prove that a simple accepting path of a space-s(n)s(n) machine uses fewer than NN configurations, where NN is the configuration count.

Solution

If a configuration repeats on a path, the segment between repeats is a cycle that can be deleted without losing reachability to accept (along that chosen path). Hence a simple path of length <N<N exists.

Exercise 2 — What an NL STCON machine stores

Describe the work state of a standard NL machine for STCON and bound space by O(log⁡∣V∣)O(\log|V|).

Solution

Store the current vertex (O(log⁡∣V∣)O(\log|V|) bits), a step counter up to ∣V∣|V| (to avoid loops), and temporary space to test an edge. Total O(log⁡∣V∣)O(\log|V|).

Exercise 3 — Composing log-space reductions

Why is log⁡∣f(x)∣=O(log⁡∣x∣)\log|f(x)|=O(\log|x|) essential in composition? What is recomputed instead of stored?

Solution

A log-space transducer's output is polynomial length, so an output index is O(log⁡∣x∣)O(\log|x|). Composition does not store all of f(x)f(x) — it recomputes symbol-by-symbol in log space, trading space for time.

Exercise 4 — Savitch to O(s2)O(s^2)

Solve S(ℓ)=S(ℓ−1)+O(s)S(\ell)=S(\ell-1)+O(s) at depth ℓ=O(s)\ell=O(s), and deduce Savitch's space bound.

Solution

S(ℓ)=O(s⋅ℓ)=O(s2)S(\ell)=O(s\cdot\ell)=O(s^2) for ℓ=⌈log⁡N⌉=O(s)\ell=\lceil\log N\rceil=O(s). Hence NSPACE(s)⊆DSPACE(O(s2))\mathrm{NSPACE}(s)\subseteq\mathrm{DSPACE}(O(s^2)).

Exercise 5 — NPSPACE=PSPACE\mathrm{NPSPACE}=\mathrm{PSPACE} and NL=coNL

Deduce NPSPACE=PSPACE\mathrm{NPSPACE}=\mathrm{PSPACE} from Savitch. Does NL=coNL\mathrm{NL}=\mathrm{coNL} imply L=NL\mathrm L=\mathrm{NL}?

Solution

For s=nks=n^k: NSPACE(nk)⊆DSPACE(n2k)⊆PSPACE\mathrm{NSPACE}(n^k)\subseteq\mathrm{DSPACE}(n^{2k})\subseteq\mathrm{PSPACE}; the union yields NPSPACE⊆PSPACE\mathrm{NPSPACE}\subseteq\mathrm{PSPACE}. The reverse is immediate. NL=coNL\mathrm{NL}=\mathrm{coNL} does not collapse determinism vs nondeterminism: complement closure ≠\neq L=NL\mathrm L=\mathrm{NL}.

Summary

Space is understood via implicit reachability. STCON captures NL; Savitch squares space; NPSPACE=PSPACE; Immerman–Szelepcsényi yields NL=coNL.

Guided practice

Task 1 — Configuration count in log space

Prove that an O(log⁡n)O(\log n)-space machine has polynomially many configurations.

Solution

Work contents: ∣Γ∣O(log⁡n)=nO(1)|\Gamma|^{O(\log n)}=n^{O(1)}. Head positions and state contribute polynomial factors. Hence N=nO(1)N=n^{O(1)}, and the configuration graph is an implicit polynomial-size object.

Task 2 — Complete versus hard

Distinguish NL-hard from NL-complete. When does a reduction to STCON prove completeness?

Solution

Hard: every NL language reduces to BB. Complete: also B∈NLB\in\mathrm{NL}. Reductions from all NL languages to STCON prove hardness; with STCON∈NL\in\mathrm{NL} one obtains completeness.

Task 3 — Immerman–Szelepcsényi sketch

Outline at idea level why undirected-style non-reachability for STCON lies in NL (no full proof).

Solution

Count vertices reachable from ss in layers, verifying the count nondeterministically. If tt is not among them, accept non-reachability. Verified counting replaces the illegal “I found no path” guess in NL.

Source trail and authority

  • Student/course evidence: סיכומי שיעור/סיכום ממוזג.pdf, pp. 101–130 and p. 142 (L/NL, reachability, reductions, Savitch, and complement material). This is a merged student summary used for course alignment, not theorem authority.
  • Textbook authority: Sipser, 3rd ed., Ch. 8: §8.1 pp. 333–336 (Savitch), §§8.4–8.5 pp. 348–354 (L/NL and NL-completeness), §8.6 pp. 354–356 (NL=coNL); Arora–Barak draft, Ch. 4, §§4.1–4.4, book pp. 75–87; Papadimitriou, Ch. 7, especially §7.3 pp. 146–154, and Ch. 16 §16.1 pp. 395–399.
  • Editorial status: all stated class equalities and the Savitch recurrence were checked against these sections. The NL=coNL proof is explicitly a proof sketch. Reviewed; high confidence.