Math 2.0

Computer science Definition

Space complexity

Builds on Turing machineNondeterministic Turing machineMultitape Turing machineFormal languageBig O notation

Definition

Let Σ\Sigma be a finite alphabet. Consider a multitape Turing machine MM with a read-only input tape and one or more read-write work tapes. Suppose that MM is deterministic and halts on every input. Let w∈Σ∗w \in \Sigma^* be an input. The space used by MM on ww is the number of distinct work-tape cells that the heads of MM visit while MM runs on ww. The space complexity of MM is the function sM ⁣:ℕ→ℕs_M \colon \N \to \N with sM(n)=max⁡{space used by M on w:w∈Σ∗, ∣w∣=n}.s_M(n) = \max \set{\text{space used by } M \text{ on } w : w \in \Sigma^*, \ \abs{w} = n}. For a nondeterministic Turing machine that halts on every branch, the maximum is also taken over all computation branches. For a function f ⁣:ℕ→ℕf \colon \N \to \N, DSPACE(f)\mathrm{DSPACE}(f) is the set of languages L⊆Σ∗L \subseteq \Sigma^* decided by some deterministic machine MM with sM(n)=O(f(n))s_M(n) = O(f(n)), in big O notation. The class NSPACE(f)\mathrm{NSPACE}(f) is defined in the same way with nondeterministic machines.

Remarks

Example: the language {0k1k:k∈ℕ}\set{0^k 1^k : k \in \N} lies in DSPACE(log⁡n)\mathrm{DSPACE}(\log n). A machine first checks that no 11 comes before a 00, then counts the 00s and the 11s in two binary counters and compares them. Each counter holds a number at most nn, so it needs at most ⌊log⁡2n⌋+1\floor{\log_2 n} + 1 cells.

Non-example: a machine that runs forever on some input has no space complexity in this sense, because the definition asks that MM halts on every input.

The input tape is not counted. This makes sublinear bounds such as log⁡n\log n meaningful. For bounds f(n)≥nf(n) \ge n, counting the input as well changes nothing up to a constant factor.

Reading path

To understand this page from the ground up, read these 6 pages in order. The foundations come first.

Show the path as a graph
Each page uses the pages above it. The colour of the bar on a box shows how strong the evidence is, and the box also gives it as text. The list has the same pages.
  • no evidence level
  1. Big O notation concept
  2. Formal language concept
  3. Multitape Turing machine concept
  4. Nondeterministic Turing machine concept
  5. Turing machine concept
  6. Space complexity definition

Further reading

  1. Web https://en.wikipedia.org/wiki/Space_complexity
About this page
Tag8P8SY5HEGX
URIm2://8P8SY5HEGX
Kinddefinition
WritingW0 stub
MSC68Q15, 68Q04
DefinesSpace complexity
UsesTuring machine, Nondeterministic Turing machine, Multitape Turing machine, Formal language, Big O notation
Changed3 November 2026

Markdown · JSON · Edit on GitHub

What this page needs for W1

  • an inventory row: the row of the inventory that the node accounts for (0 of 1)
  • a source with a locator (0 of 1)

The writing levels say how complete the text of a page is. They do not measure its truth.

What links here

No page links to this page yet.