Technopedia

The technologist’s encyclopedia

Space and Parallel Complexity

Where Computability and Complexity Classes asks how much time a computation needs, this page asks two related questions: how much memory does a computation need (space complexity), and how much can be parallelized (circuit depth)? The two are linked: a machine using little space has few configurations, so its computation can be laid out as a shallow circuit.

Authoritative sources

Space complexity classes

A language LL is in SPACE(s(n)s(n)) if a deterministic Turing machine decides it using at most s(n)s(n) tape cells on inputs of length nn; NSPACE(s(n)s(n)) is the nondeterministic analogue. The canonical classes are:

Details

The key counting fact: a machine with s(n)s(n) tape cells over a fixed alphabet, ∣Q∣|Q| states, and one head has at most ∣Q∣⋅s(n)⋅∣Γ∣s(n)|Q| \cdot s(n) \cdot |\Gamma|^{s(n)} configurations. If it never repeats a configuration it must halt within that many steps, so a decider using s(n)s(n) space runs in at most 2O(s(n))2^{O(s(n))} time. This is why PSPACE⊆EXPTIME\text{PSPACE} \subseteq \text{EXPTIME} and why polynomial space is so powerful relative to polynomial time: space is reusable, time is not.

Space hierarchy theorem: for space-constructible s2(n)≫s1(n)s_2(n) \gg s_1(n) (e.g. s2(n)≥s1(n+1)s_2(n) \ge s_1(n+1) asymptotically), SPACE(s1(n))⊊SPACE(s2(n))\text{SPACE}(s_1(n)) \subsetneq \text{SPACE}(s_2(n)). The proof is a diagonalization: enumerate all s1(n)s_1(n)-space machines, and on input xx simulate machine xx on input xx, doing the opposite — the extra space pays for the bookkeeping. Unlike the time hierarchy, this gives unconditional separations: L ⊊ PSPACE, for instance, is proven, whereas P ⊊ EXPTIME is the best unconditional time separation.

Example problem: show that ST-CONNECTIVITY is in NL.

Solution

A nondeterministic machine stores only the current vertex vv (initialized to ss), using ⌈log⁡2∣V∣⌉\lceil \log_2 |V| \rceil bits. At each step it nondeterministically guesses a neighbor uu of vv (scanning the adjacency list with an O(log⁡n)O(\log n)-bit counter), overwrites vv with uu, and repeats for at most ∣V∣|V| steps (another O(log⁡n)O(\log n)-bit counter). It accepts if v=tv = t ever occurs. Every accepting branch traces a genuine path from ss to tt, and if a path exists some branch guesses it — so the language is decided in O(log⁡n)O(\log n) nondeterministic space, i.e. ST-CONNECTIVITY ∈ NL. (Savitch’s theorem further shows NSPACE(s)⊆SPACE(s2)\text{NSPACE}(s) \subseteq \text{SPACE}(s^2), so it is even in DSPACE(log⁡2n\log^2 n).)

Circuit complexity and parallelism

A Boolean circuit is a DAG of AND, OR, and NOT gates whose inputs are the input bits; its size is its gate count and its depth is the length of its longest path. Depth measures how much the computation can be parallelized: each layer of a depth-dd circuit is one parallel step.

Details

Examples of NC1^1 computations: addition of two nn-bit numbers (carry-lookahead: each output bit is a function of O(log⁡n)O(\log n) inputs, computable by a tree of gates of depth O(log⁡n)O(\log n)), and Boolean formula evaluation. Examples of NC2^2: matrix multiplication (O(log⁡n)O(\log n) depth with O(n3)O(n^3) processors via associative reduction), determinant, and graph reachability. Problems believed not to be in NC include linear programming and circuit value evaluation (they are P-complete under log-space reductions: if any P-complete problem were in NC, then NC = P).

Example problem: show that computing the AND of nn bits is in NC1^1.

Solution

Build a balanced binary tree of 2-input AND gates: n−1n-1 gates, depth ⌈log⁡2n⌉\lceil \log_2 n \rceil. Layer ii computes the AND of disjoint blocks of 2i2^i input bits; all gates in a layer are independent and can be evaluated in parallel. Size is O(n)O(n) (polynomial) and depth is O(log⁡n)O(\log n), so the language {1n}\{1^n\} (and generally the AND of the input bits) is in NC1^1. The same tree pattern with OR gates, or with a comparator network, gives parallel OR, MAX, and sorting networks — the fundamental templates of parallel algorithms.

Quizz

Quizz

Problem: Show that L⊆P\text{L} \subseteq \text{P}: every log-space decider runs in polynomial time.

Solution

A log-space machine on inputs of length nn has s(n)=clog⁡ns(n) = c\log n tape cells, ∣Q∣|Q| states, and one head position among s(n)s(n) cells, so its number of distinct configurations is at most ∣Q∣⋅s(n)⋅∣Γ∣s(n)=∣Q∣⋅clog⁡n⋅nclog⁡∣Γ∣|Q| \cdot s(n) \cdot |\Gamma|^{s(n)} = |Q| \cdot c\log n \cdot n^{c\log|\Gamma|}, which is polynomial in nn. A decider must halt on every input, and a machine that halts never repeats a configuration (otherwise it would loop forever); hence it halts within polynomially many steps. Since it also uses only O(log⁡n)O(\log n) space — and O(log⁡n)⊆O(nk)O(\log n) \subseteq O(n^k) — the same machine witnesses membership in P.