TL;DR
PSPACE is the class of yes-or-no problems that a Turing machine can decide while using an amount of memory (its tape) that is a Polynomial in the length of the input. The running time is not limited to a polynomial, so PSPACE allows far more time than P and NP. It is useful because it captures games, planning and many puzzles, where the number of possible moves is huge but the memory needed to search through them is small.
Builds on: Turing Machine, P and NP, Big-O Notation · Leads to: the PSPACE-complete problems, which are the hardest problems in PSPACE, and the open question of whether P equals PSPACE
Where it's used
Two-player games. Deciding whether the first player has a winning strategy in a generalised board game, where the board size grows with the input, is a PSPACE problem. The game tree can be enormous, but a search that walks it depth-first only needs to remember one path at a time.
Verification and planning. In formal verification, checking that a system with components can never reach a bad state, where each component has a few states, is a PSPACE problem for many models. Planning tasks in artificial intelligence, such as "can a robot reach this configuration with these moves", have the same form.
Logic and proofs. The question "is this fully quantified Boolean formula true?" generalises Boolean satisfiability, and asks whether a statement with alternating "for all" and "there exists" over its variables holds. It is the standard example of a PSPACE-complete problem, and the reduction from any PSPACE problem to it is the reason the class is studied so closely.
How it works
Take a tiny formula with two variables. Ask whether this statement is true: "for every there exists a such that ". Each variable is either 0 or 1, and the question is whether the formula holds. In the formula, means and, means or, and means not.
A procedure can answer this by trying values as in a tree search, reusing the same memory. Read the quantifiers from left to right.
- Start with . The first quantifier is "for every ", so the procedure must check both values. It picks first and stores that choice. Check: one bit of memory now holds the value of .
- Go inside for . The next quantifier is "there exists ", so the procedure tries . The formula is , which is . The value is false, so the procedure tries . The formula is , which is . Check: works, so the inner question is true for .
- Erase the choices. The procedure no longer needs the trials for and , so it reuses that memory. Check: the memory now holds only again.
- Go inside for . The procedure sets in the same place and tries again. For , the formula is . Check: works, so the inner question is true for .
- Read the answer. Both values of have a working , so the whole statement is true. Check: the memory used at any moment was a few bits, and the procedure never stored all the trials at once.
flowchart TD A["for all x"] --> B["x = 0"] A --> C["x = 1"] B --> D["exists y: y = 0 fails, y = 1 works"] C --> E["exists y: y = 0 works"] D --> F["true"] E --> F
The tree has leaves here, so the time grows with the number of trials. The memory does not, because each level of the tree stores only one variable's value.
The math
A language is in PSPACE if there is a deterministic Turing machine and a polynomial such that for every input , decides whether and uses at most cells of tape, where is the length of . The time takes is not restricted by this definition.
In words: PSPACE is the set of problems that need only polynomial memory. The memory is measured against the input length , and it is allowed to be reused over time.
Step 1 in symbols: the quantified formula
A fully quantified Boolean formula has the form , where each is ("for all") or ("there exists"), and is an ordinary formula with and, or and not. The example is , with .
Step 2 in symbols: the recursive evaluation
Let stand for the rest of the quantified formula after the first quantifier. Then
where means the rest of the formula with set to . For the example, , which is true, and is also true, so is true.
Step 3 in symbols: the memory count
The evaluation makes a call for each choice of each variable, and a call holds one value. The depth of the recursion is , so the procedure stores at most bits of choices plus a constant amount of bookkeeping for each level. That is space, which is well inside the polynomial bound.
Step 4 in symbols: the time count
The number of leaves of the tree is , so the time is times the cost of evaluating . The time is exponential, and it is still allowed by PSPACE, which puts no limit on time. This is the key difference from the time classes.
Step 5 in symbols: the relationship to NP
For a problem in NP, a yes answer has a short certificate that can be checked in polynomial time. A PSPACE machine can try every certificate of polynomial length one at a time, reusing the same space for each try. So , and likewise .
Worked examples
Take the formula .
- Set . The formula is .
- Set . The formula is .
- Both values give 1, so the "for all" statement is true.
- Interpretation: the formula is a tautology. The procedure needed one bit for , and it tried two values.
A pile has stones. Two players take turns removing 1 or 2 stones. The player who takes the last stone wins. Let be true when the player to move can force a win.
- Base cases: is true, since the player takes the last stone. is true, since the player takes both.
- Compute . Taking 1 leaves 2, and the opponent wins from 2. Taking 2 leaves 1, and the opponent wins from 1. So is false.
- Compute . Taking 1 leaves 3, which is a losing position for the opponent. So is true.
- Compute . Taking 1 leaves 4, which is winning for the opponent. Taking 2 leaves 3, which is losing for the opponent. So is true, and the first player should take 2.
- Interpretation: the search is the same as the recursive evaluation above, with "for all" for the opponent's moves and "there exists" for the player's moves. Its memory is the current pile and the choices on the path, which is small, even though the number of positions grows.
Try it: for a pile of 6 stones, is the player to move winning? Answer: taking 1 leaves 5, which is winning for the opponent. Taking 2 leaves 4, which is winning for the opponent. Both moves lose, so is false.
A circuit has 20 inputs, and a team wants to know whether it is equivalent to a reference circuit: whether the two agree on every input. The question "for every input, the outputs agree" has the form , where compares the two outputs. The numbers below are invented for illustration.
- The check tries inputs in a fixed order. It starts with all inputs 0, then changes the last input, and so on, like counting in binary.
- At each input, the procedure evaluates both circuits and compares the outputs. It stores only the current input, which is 20 bits.
- The number of inputs is , which is about one million, so the check takes a million evaluations.
- The memory used is 20 bits plus the working space of the two circuits, which is small and does not grow with the number of inputs tried.
- Interpretation: the check is slow in the worst case, but it fits in small memory. Problems of this shape, with a universal quantifier over many inputs, are where PSPACE-style reasoning appears.
Try it: the same check is run on 30 inputs instead of 20. How many input patterns are there, and how many bits does the procedure store for them? Answer: there are , about a billion, patterns, and the procedure stores 30 bits for the input.
Common mistakes and tradeoffs
It is tempting to think that PSPACE is the same as polynomial time. In fact PSPACE allows exponential time, because the memory can be reused for an exponential number of steps. The class is about how much memory a procedure needs, not how long it runs.
It is tempting to think that PSPACE problems are harder than NP problems in every sense. In fact , so NP problems are inside PSPACE. The PSPACE-complete problems are the hardest ones in PSPACE, and they include many problems that look like games or puzzles.
It is tempting to think that a problem using little memory is quick. In fact the search can take an exponential number of steps while using only a little memory, as the circuit example shows. Memory and time are different resources, and PSPACE measures only one of them.
It is tempting to think that the question P versus PSPACE has been answered. In fact it is open. Researchers believe the two are different, but nobody has proven it.
When to use it. Use PSPACE when a problem involves a long sequence of alternating choices, such as moves in a game or a search over states, and the memory needed is clearly polynomial.
When not to use it. Do not treat PSPACE as a guide to running time. A PSPACE-complete problem may take exponential time in practice, so a practical solver needs other ideas.
Alternatives. For problems in NP, a certificate-checking view often gives a clearer picture of cost. For games with bounded depth, a bounded search with memoisation may be enough in practice. A breadth-first search of the same tree would need memory that grows exponentially, which is why the depth-first search used here is the one that fits in polynomial space.
History
In 1971 Stephen Cook showed that satisfiability is NP-complete, and in 1972 Richard Karp showed that many other problems share that property. Their work made the question of how problems relate in cost central to computer science.
In 1970 Walter Savitch proved a result now called Savitch's theorem. It shows that a nondeterministic machine using polynomial space can be simulated by a deterministic one using polynomial space, with only a polynomial increase in memory. This is why the nondeterministic and deterministic versions of PSPACE are the same class.
In 1973 Larry Stockmeyer and Albert Meyer showed that the true quantified Boolean formula problem is PSPACE-complete. That result gave the class its standard complete problem and made the connection between PSPACE and games and logic precise. The class caught on because it captures many problems that people solve by searching through choices with limited memory.
Recap
- PSPACE is the class of problems solvable with polynomial memory, with no limit on time.
- The recursive evaluation of a quantified formula uses one bit per variable, which is why it fits in PSPACE even though its running time is exponential.
- , and PSPACE allows far more time than either.
- The PSPACE-complete problems are the hardest in the class, and they include the quantified formula problem and many game problems.
- Read next: NP-Completeness for the reduction method, and Polynomial-Time Reduction for how one problem is shown to be as hard as another.