Complexity Theory Codexery

Space complexity

Memory required by an algorithm as a function of input size.

Space complexity

Space complexity is a measure of the memory space required by an algorithm to solve a computational problem, expressed as a function of the input's characteristics. It includes both the memory for inputs (input space) and any additional memory used during execution (auxiliary space). Space complexity is often analyzed asymptotically using big O notation, such as O(n), O(n log n), or O(2^n).

field
Computational complexity theory
known_for
DSPACE, NSPACE, PSPACE, NPSPACE, LOGSPACE, space hierarchy theorem, Savitch's theorem, Immerman–Szelepcsényi theorem

Lore & Background

Space complexity classes are defined analogously to time complexity classes. DSPACE(f(n)) and NSPACE(f(n)) are the sets of languages decidable by deterministic and non-deterministic Turing machines, respectively, using O(f(n)) space. PSPACE and NPSPACE allow f to be any polynomial, defined as the union of DSPACE(n^c) and NSPACE(n^c) over all positive integers c.

Reader's Guide

The space hierarchy theorem states that for any space-constructible function f(n), there exists a problem solvable with f(n) space but not with asymptotically less space. Containments between classes include DTIME(f(n)) ⊆ DSPACE(f(n)) ⊆ NSPACE(f(n)) ⊆ DTIME(2^{O(f(n))}). Savitch's theorem shows that for f(n) in Ω(log n), NSPACE(f(n)) ⊆ DSPACE((f(n))^2), leading to the surprising result that PSPACE = NPSPACE, suggesting non-determinism offers only a small space advantage. The Immerman–Szelepcsényi theorem states that for f(n) in Ω(log n), NSPACE(f(n)) is closed under complementation, contrasting with time complexity where NP is not believed to be closed under complement. LOGSPACE (L) is the set of problems solvable by a deterministic Turing machine using O(log n) space, useful for large data and related to streaming algorithms and derandomization.

Did You Know?

The Architecture of Computational Difficulty

Computational complexity theory sits at the intersection of theoretical computer science and mathematics, dedicated to sorting problems by how much resource they demand. Rather than asking whether a single clever algorithm can crack a task, the field asks a broader question: what is the minimum a problem fundamentally requires, regardless of which algorithm you deploy? A problem is deemed inherently hard when no algorithm—no matter how ingeniously designed—can solve it without consuming substantial resources like time or storage. To make this intuition rigorous, the theory borrows mathematical models of computation and quantifies the resource costs involved. Beyond time and memory, researchers track other dimensions: the volume of communication exchanged in distributed settings, the gate count in hardware circuits, and the processor count in parallel architectures. One of the field's central missions is to map the practical boundaries of what machines can and cannot accomplish. The P versus NP question, one of the seven Millennium Prize Problems, lives squarely within this territory. The discipline also shares borders with analysis of algorithms, which dissects a specific algorithm's resource profile, and computability theory, which asks what is solvable in principle at all. Complexity theory occupies the middle ground: classifying problems by whether they can be solved under appropriately restricted resources.

Problems, Instances, and the Power of Abstraction

A computational problem, in the eyes of complexity theory, is not a single puzzle but an infinite family of puzzles. Each concrete input, called a problem instance, pairs with a set of possible solutions, and the problem as a whole is the abstract question spanning all of them. Take primality testing: the problem asks whether a number is prime, while a particular instance might be the number 15, whose answer is no. The distinction matters because the answer to one instance tells you almost nothing about another. For this reason, complexity theory deliberately targets the problem level rather than any single instance. When instances are formalized, they become strings over an alphabet, most commonly the binary alphabet of 0s and 1s. Integers are rendered in binary notation, and graphs are encoded through adjacency matrices or binary-encoded adjacency lists. Proofs often assume a specific encoding, yet the theory strives to stay independent of that choice, relying on the fact that different encodings can be converted into one another efficiently.

Decision Problems as the Language of Computation

Among the many objects complexity theory studies, decision problems occupy a central position. A decision problem is one in which the answer to every instance is strictly binary: yes or no, 1 or 0. This structure lets the problem be recast as a formal language. The members of that language are precisely the instances that yield a yes, while the non-members are those that yield a no. An algorithm that decides the problem either accepts an input string, saying yes, or rejects it, saying no. A concrete illustration: given an arbitrary graph, decide whether it is connected. The associated formal language is the set of all connected graphs, though pinning down that set requires a precise binary encoding of graphs. The elegance of this framing is that it reduces a wide variety of computational questions to a single uniform task, namely membership testing in a language. Because the output is so constrained, decision problems serve as a natural baseline for measuring difficulty. They also provide the scaffolding onto which more complex problem types can be hung, as the following section will show.

Function Problems and the Illusion of Greater Richness

At first glance, function problems seem to open a far richer landscape than decision problems. A function problem expects a single, potentially elaborate output for every input—think of the traveling salesman problem, which demands an optimal route, or integer factorization, which requires the prime components of a large number. The output is not a simple yes or no but a structured object. Yet complexity theory reveals that this apparent richness is largely an illusion. Function problems can be recast as decision problems by shifting the question from producing the output to verifying a candidate output. Multiplying two integers, for example, can be reframed as the set of all triples (a, b, c) satisfying the relation a times b equals c. Deciding whether a given triple belongs to that set is equivalent to solving the original multiplication task. This reduction means that the yes-or-no framework of decision problems is not a limitation but a universal lens. It allows the entire edifice of complexity classification—resource bounds, problem hierarchies, and the great open questions like P versus NP—to rest on a single, elegantly constrained type of computational question.

Frequently Asked Questions

Who is Space complexity?

Space complexity is the measure of how much memory an algorithm must use to solve a given problem, expressed as a function of the input's size. It accounts for both the input data itself and any extra working memory the algorithm allocates while running.

What are Space complexity's powers and role in the canon?

It defines the entire landscape of memory-bounded computation, giving rise to the major classes DSPACE, NSPACE, PSPACE, NPSPACE, and LOGSPACE. Its landmark results include the space hierarchy theorem, which guarantees that more memory strictly buys more power.

How does Space complexity's story end?

It never truly concludes — questions like whether P equals PSPACE remain wide open, keeping the character at the center of active research. Fans often note that its arc is still being written as new separations and collapses are explored.

Why is Space complexity important to the field?

It provides the fundamental framework for understanding what is computable under realistic memory limits, which matters because physical machines have finite RAM. The Immerman–Szelepcsényi theorem, showing NSPACE and co-NSPACE are the same class, is a fan-favorite result that cemented its importance.

What is Space complexity's most famous relationship?

Savitch's theorem is its most iconic connection, proving that NPSPACE collapses to PSPACE — nondeterminism offers no extra memory advantage. Fans love this result because it sharply contrasts with time complexity, where NP versus P remains unresolved.

More in Complexity Theory 1-24

Spotted an error? Know more?

This is a living reference — every entry is fact-audited, and reader corrections feed straight into our audit queue. Suggest an edit · See this site's audit record

Comments

Loading…
Open in the interactive codex →