Hello! Welcome to our final lesson in the introduction to computational complexity.
In the previous lesson, we established a formal way to measure the memory, or space, used by a Turing machine. We saw how space complexity relates to time complexity, noting that space is a reusable resource. This laid the foundation for classifying problems based on their memory requirements.
Today, we will use that foundation to define and explore PSPACE, one of the major complexity classes. This lesson addresses the learning outcome: Define the complexity class PSPACE. We will see how it fits into the hierarchy with P and NP, understand its core properties, and look at problems that define its boundaries. This will give you a more complete map of the computational landscape.
1. Defining PSPACE
Just as P is the class of problems solvable in polynomial time, PSPACE is the class of problems solvable in polynomial space.
Let's start with a formal definition.
ECS 120 Lesson 26 – Space Complexity
These lecture notes provide a crisp, formal definition of PSPACE and its nondeterministic counterpart, NPSPACE.
Please read the subsection '3.1 PSPACE and NPSPACE' to get the formal definitions. Note the direct analogy to the definitions of P and NP.
To summarize the key definitions from the reading:
- PSPACE: This is the class of languages decidable by a deterministic Turing machine in polynomial space. Formally,
- NPSPACE: This is the class of languages decidable by a nondeterministic Turing machine in polynomial space. Formally,
A problem is in PSPACE if there exists an algorithm that solves it using memory that grows as a polynomial function of the input size (e.g., , , etc.). Crucially, there is no restriction on the running time. As we saw in the last lesson, a polynomial-space algorithm might run for exponential time.
2. PSPACE in the Complexity Hierarchy
Where does PSPACE fit with P and NP? Let's watch a video that outlines the relationships.
17. Space Complexity, PSPACE, Savitch's Theorem
This video from an MIT lecture on complexity theory explains the fundamental relationships between the time-based classes (P, NP) and the space-based class PSPACE.
Please watch from 11:15 to 29:30. This is a conceptually rich segment. The first part (11:15 - 16:54) establishes that P ⊆ PSPACE as a direct consequence of the relationship between time and space. The second, more involved part (16:54 - 29:30) proves that NP ⊆ PSPACE by showing that the NP-complete problem SAT can be solved in polynomial space.
Let's break down these crucial inclusions.
P ⊆ PSPACE
This follows directly from the fact that TIME(f(n)) ⊆ SPACE(f(n)). If a problem is in P, it can be solved by a deterministic TM in time. In steps, a TM can visit at most cells. Therefore, this TM uses at most space. Since it's solvable in polynomial time, it's also solvable in polynomial space.
NP ⊆ PSPACE
This is a more profound result. The video shows two ways to think about it.
Argument 1: Solving SAT in Polynomial Space
- SAT is NP-complete: If we can solve SAT in polynomial space, we can solve any problem in NP in polynomial space. This is because any problem in NP can be reduced to SAT in polynomial time, which is also polynomial space.
- The "Odometer" Algorithm: To check if a formula with variables is satisfiable, we can deterministically iterate through all truth assignments.
- We need space to store one assignment (e.g., a binary string of length ). This takes space.
- For each assignment, we evaluate , which takes polynomial time and thus polynomial space.
- Crucially, we can reuse the same space for each new assignment. After checking
00...0, we reuse the space to check00...1, and so on.
- Result: The algorithm takes exponential time () but only polynomial space (). Therefore, SAT is in PSPACE.
Your experience with building systems gives you an intuitive grasp of this time-space tradeoff. You can often reduce memory usage at the cost of more computation, for instance, by re-calculating values instead of storing them in a large cache. This algorithm is an extreme example of that principle.
Argument 2: The Generic Verifier Approach
A more abstract way to see this, explained well in the video resource LINK, is to use the verifier definition of NP. A language is in NP if a "yes" instance has a polynomial-length certificate that can be checked by a polynomial-time verifier.
A deterministic PSPACE machine can simply:
- Iterate through every possible certificate string of the required polynomial length.
- For each certificate, run the polynomial-time verifier.
- If the verifier accepts, halt and accept. If all certificates are tried and none work, reject.
Again, space is reused for each certificate, so the total space is polynomial (enough for one certificate and one run of the verifier).
This gives us the hierarchy: P ⊆ NP ⊆ PSPACE.

3. A Quintessential PSPACE Problem: TQBF
While SAT is in PSPACE, it's not thought to be "PSPACE-hard" — it's too easy. The canonical problem that captures the full difficulty of PSPACE is TQBF (True Quantified Boolean Formulas).
A Quantified Boolean Formula (QBF) extends a regular boolean formula with universal (, "for all") and existential (, "there exists") quantifiers. For example:
This formula reads: "For all possible truth values of , does there exist a truth value of such that the expression is true?"
The TQBF problem asks: given a QBF with no free variables, is it true?
Let's watch how to solve TQBF in polynomial space.
17. Space Complexity, PSPACE, Savitch's Theorem
This final segment of the MIT lecture introduces TQBF and presents a recursive algorithm to solve it. This is a classic example of a PSPACE algorithm.
Watch from 39:04 to 57:51. Focus on two things: How the quantifiers create a game-like, alternating structure. Why the recursive algorithm, despite exploring an exponential number of paths, only uses linear space.
The algorithm presented in the video is a beautiful illustration of space reusability. Let's call it SOLVE(\phi):
- Base Case: If has no quantifiers, evaluate it directly.
- Recursive Step (): Recursively call
SOLVE(\psi)with andSOLVE(\psi)with . Return true if either call returns true. - Recursive Step (): Recursively call
SOLVE(\psi)with andSOLVE(\psi)with . Return true if both calls return true.
The key to the space analysis is that the two recursive calls in each step can be executed sequentially. After computing the result for , we can discard all the memory used for that branch (except the boolean result) and reuse it for the branch.
This is exactly how a call stack works in most programming languages. The space needed is proportional to the maximum depth of the recursion, which is the number of variables in the formula. If the input formula has length , it can have at most variables. Therefore, the algorithm runs in space, placing TQBF firmly in PSPACE.
Test your understanding!
Consider the TQBF algorithm. Why can't we apply the same space-saving logic to a standard non-deterministic algorithm for SAT, which guesses an assignment and then verifies it?
Show answer
The TQBF algorithm is deterministic. It systematically explores the entire tree of possibilities. Nondeterminism is about guessing a single correct path. While we can simulate nondeterminism deterministically (as we did for the NP ⊆ PSPACE proof), the fundamental models are different. The recursive TQBF algorithm's space efficiency comes from its deterministic, depth-first traversal of the solution space, allowing for the reuse of stack space. A nondeterministic machine, by definition, explores multiple branches in parallel, and we measure the space of the deepest single branch.
4. A Surprising Equivalence: PSPACE = NPSPACE
One of the most remarkable results in complexity theory concerns the power of nondeterminism in space-bounded computation. While it is widely believed that P ≠ NP, we know for a fact that PSPACE = NPSPACE.
This result is known as Savitch's Theorem. It states that any problem solvable by a nondeterministic TM using space can be solved by a deterministic TM using space.
For polynomial space, this means:
If a problem is in NPSPACE, it's solvable in space by an NTM. By Savitch's Theorem, it's solvable in space by a DTM. Since is still a polynomial, the problem is also in PSPACE.
Therefore, NPSPACE ⊆ PSPACE. Since we already know PSPACE ⊆ NPSPACE (a deterministic TM is a special case of an NTM), the two classes must be equal.
The proof of Savitch's theorem uses a clever recursive, divide-and-conquer strategy similar in spirit to the TQBF solver, checking for reachability between configurations. The MIT lecture's ladder problem (covered in sections 6 and 7 of LINK) is designed as an introductory example of this very technique.
Conclusion
This lesson completes our tour of the foundational complexity classes. By defining PSPACE, we have characterized a vast and important class of problems that are considered solvable in principle, even if they require an infeasible amount of time.
Key Takeaways:
- PSPACE is the class of decision problems solvable by a deterministic Turing machine using a polynomial amount of tape space.
- The known hierarchy is P ⊆ NP ⊆ PSPACE. The inclusions are believed to be proper, but this has not been proven.
- The reusability of space allows exponential-time algorithms to run in polynomial space, which is why
NP ⊆ PSPACE. - TQBF is a canonical PSPACE-complete problem, solvable with a recursive algorithm that uses linear space.
- A cornerstone result, Savitch's Theorem, proves that PSPACE = NPSPACE, a stark contrast to the presumed P vs. NP separation.
This concludes our course on the Theory of Computation. You have journeyed from the simplest models of computation, like finite automata, through the expressive power of grammars and pushdown automata, to the universal model of the Turing machine. Finally, you have explored the limits of computation itself, classifying problems by their inherent difficulty into the major complexity classes P, NP, and PSPACE. This theoretical framework is the bedrock upon which the entire field of computer science is built. Congratulations on completing this journey