Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Lecture 9

In-class notes: CS 505 Spring 2025 Lecture 9

Space Complexity

So far, we have only focused on the time complexity of computations. However, an equally important metric to consider is space complexity. Intuitively, though we would like computations to be fast, time is an abundant resource. For example, we do not need to get new hardware to let computations run longer, we simply just let our computers run longer. However, for space, we cannot simply “download more RAM” or disk space. So it is an important factor to consider in computational complexity.

Definition. Let . A language is in the class if there exists a deterministic Turing machine which decides the language using at most additional space. That is, for any , if and only if and uses space on its non-output work tapes.

Intuitively, when considering the space constraints of an algorithm, we do not count the input length against the space usage (since it must read all the input to do a deterministic computation). We also do not count the output tape (and, in fact, sometimes we remove the output tape and simply encode accept/reject in the final halting state).

Similarly, we define the class as the set of all languages decidable by a non-deterministic Turing machine using at most space on its work tapes for any non-deterministic computational path made by the NTM.

Power of Space-bounded Computations

Intuitively, we believe space-bounded computations to be more powerful than time-bounded ones. This is because we cannot reuse time, but we can continually reuse space. As an example, recall that we do not believe ; that is, no polynomial-time algorithm solves/decides . However, : it is solvable only using linear space by a deterministic Turing machine.

To see this, let be a DTM which takes as input a SAT formula . To decide if (i.e., is satisfiable), we can use linear space and simply test all possible assignments. Suppose that has variables .

:

  • For all
    • Test if .
    • If yes, output .
  • Output .

Note we are only keeping track of bits (i.e., we are counting from to in binary) and testing if this produces a satisfying assignment. Testing if is satisfiable under assignment requires space, where , and clearly . Therefore, we only need linear space to decide if is satisfiable. Notably, this is an exponential time algorithm, but only uses linear space.

Space Constructible Functions

Like with time complexity, for space complexity we care about the notion of space constructible functions. As you may guess, these are functions that are constructible in limited space.

Definition. A function such that is space constructible if there exists a deterministic Turing machine such that on input , outputs using at most space on any of its work tapes.

Theorem. For every space constructible function , we have

Proof. Clearly since any deterministic Turing machine running in time can use at most space on its work tapes. Similarly, since every deterministic computation is also a non-deterministic computation.

What remains to show is . To see this, we use the notion of a configuration graph. We let denote the configuration graph of for any NTM . The graph is a directed acyclic graph which consists of all possible configurations of the tape(s) of . There is a unique starting node, which corresponds to the unique starting configuration of every Turing machine. There is an edge from node to in the graph if the configuration can be reached by a valid transition from the configuration in a single step of the computation.

The graph is said to be accepting if there exists a path from the starting configuration to some halting configuration that is accepting. Moreover, if such a path exists, then accepts. One final thing we need is the following fact.

Fact. Any NTM running in time can be converted to an equivalent NTM where the transition function of outputs at most two states per computation step and runs in time .

By definition, we know that the non-deterministic Turing machine transition function is defined as By definition, for a fixed Turing machine , all of , , and are fixed. So . Given this, there is a way to convert the machine with transition function to an equivalent machine with transition function where outputs at most configurations per input.

All together, this allows us to notice the following properties about the configuration graph . If uses space on any input, then

  1. has at most vertices. In particular, every vertex/configuration can be encoded with space (or for a -tape machine, but is considered constant).
  2. There exists a CNF of size such that if and only if and are valid configuration sand ; that is, is reachable from in a single step of the computation.

(1) above follows from the above Fact and subsequent discussion. (2) follows directly from the Cook-Levin theorem. In particular, the formula is simply the formula which is checking that all computation windows are valid, and all symbols are valid.

With all of this setup, let be an NTM which decides some language . We construct a machine which decides in time. On input , the machine construct the graph , which takes time. Construction of this graph requires checking edges between nodes, which is done in time per pair of vertices since has size . This gives a total time of . Then simply searches for a path from the starting configuration to an accepting configuration, again taking at most time.

Space Hierarchies

Unsurprisingly, just like with time constructible functions, we have similar space hierarchy theorems for space constructible functions.

Theorem. Let be space constructible functions such that . Then .

The proof is identical to the deterministic time hierarchy theorem, except we do not have the logarithmic loss. This is because of universal simulation: when simulating a time Turing machine, we need time, but to simulate a space Turing machine, we only need space.

Space Complexity Classes

Just like with time complexity, we have complexity classes related to space bounded computations. Four of them will be of interest to us.

  1. .
    • This is the space analogue of .
  2. .
    • This is the space analogue of .
  3. .
  4. .

Some facts about the above classes.

  • It is an open question of . We believe it to not be true; that is, .
  • In a somewhat surprising result, .
  • In an even more surprising result, .

We’ll get to the bottom two points in our later discussions on space complexity. Let’s see some examples now.

Space Complexity Class Examples

This implies that . We can see this since for any language , under the certificate definition there exists a DTM and a polynomial such that for all , we have if and only if there exists a string such that . We can easily construct a polynomial space DTM which on input simply iterates over all possible strings and checks if . This only uses polynomial space since we can reuse the space for the string .

Languages in

Checking if a string has an even number of ’s is in , and so is checking if the product of two integers is equal to a third integer. Formally, let

The language is decidable in only logarithmic space because if is the size of the input, counting the number of ’s in only takes bits, then checking if this is even simply requires checking if the least significant bit is . This only takes logarithmic space.

For , we are given the binary representation of three integers , , and . Assume each integer is bits. So the input is of length . Then, to multiply and , one can simply do the grade school multiplication algorithm over the binary representations of and . If we are not careful and try to write down the result of , we would require -bits since is also bits. So we can simply compute bit by bit and compare to the bits of . We will have to track carry over bits, which will be at most bits to track.

Languages in

Deciding if a directed graph has a path between two vertices and is in . Formally, let be the following language. The number of vertices in is and the number of edges is at most . To see that , we give a non-deterministic Turing machine which decides using space. Notice that if there exists a path from to in , then it is of length at most . Thus, a non-deterministic Turing machine simply performs a depth first search of depth at most starting at . If it finds , then it outputs accept; otherwise it outputs reject. If there is a path from to , then there exists a series of non-deterministic choices to make for the depth first search that will end up at .

Note

We’ll see later that is the “essence” of ; that is, it is -complete.

-complete Languages

We continue our study of space complexity by examining -complete languages. Just like with -complete languages, we define -completeness with respect to polynomial time reductions.

Definition. A language is -complete if

  1. ; and
  2. , we have .

True Quantified Boolean Formulas

Up to now, we have only seen “fixed” Boolean formulas. For example, . Then, we say that if and only if such that .

We can generalize the above to include different quantifiers. For example:

  • ;
  • (notice this is the language , the -complete language);
  • .

With this, we can define quantified Boolean formulas.

Definition. Let be a Boolean formula with variables. Then, we say that is a quantified Boolean formula, where and for all . We say that is a true quantified Boolean formula if .

Example

  • (this is ).
  • (this is ).
  • (this is ).
  • .
    • This is if and only if .
  • .
    • This always evaluates to .

Building on what we have, we let be the set of all true quantified Boolean formulas .

Theorem. is -complete.

Aside: the Essence of

One can actually think of as the set of two-player games with perfect information such that player 1 has a winning strategy. In particular, the essence of turns out to be finding optimal strategies for player 1 in a 2 player game with perfect information (that is, no randomness and no hidden information such as a hand in card games). Three concrete examples: Chess, Go, and Tic-Tac-Toe (though for Tic-Tac-Toe you have to phrase it differently since drawing the game is the optimal strategy). Some other subtleties (which we will not get into in this class) that arise here are, for example, finite boards being easy to deal with in , which need to be fixed by making the board a 2D infinite grid.

Proving is -complete

We’ll begin the proof of this theorem, and finish it in next lecture. For now, we’ll show that . Let be a QBF on variables . We let . We construct a decider to check if , with the goal being this decider uses at most space for some polynomial in .

Let be a simple recursive Turing machine which does the following.

:

  1. If has no quantifiers, output if and output otherwise.
  2. Else if 1
    • Run with and .
    • If returns on either of these inputs, return . Else return .
  3. Else if
    • Run with and .
    • Return if and only if returns on both these inputs; otherwise return .

First, clearly decides if . In the base case, if has all variable set to a value, then simply checks if is satisfied by the generated assignment. Then, if , returns if and only if assigning or returns true, which is enough since we only need at least one of these to return true. Finally, if , then returns if and only if assigning and both result in a true QBF.

To finish the proof, note we already established we only need space in the base case of the recursion. The recursion depth is , and at every level we are only storing a single variable worth of information, so the final space complexity is . This finishes the first part of the proof; namely, we have shown .


  1. This is another QBF with 0 or more quantifiers.