CSCI 341 Theory of Computation

Fall 2025, with Schmid
← 4.1 Polynomial Reductions4.3 Hard Problems →

Nondeterminism and Complexity

Recall that for finite automata (and stack automata, too) that nondeterminism occurs when a state has more than one defined behaviour for a given input. In Turing machines, nondeterminism occurs when a program can branch into two paths from the same program and memory state (of the tape head).

if a :
  ├ p.goto y
  └ q.goto z
The semantics of nondeterminism in vanilla and stack automata was that a word was accepted by the automaton if at least one path from a given starting input and state lead to a positive end. The semantics of nondeterminism in Turing machines will be exactly the same, although we are going to change the terminology from "decider" to "verifier" to get a clean formalism.

The word "verifier" comes from what one might stretch to consider a physical interpretation of nondeterministic Turing machines. One way to interpret nondeterminism is as a kind of search procedure, more specifically "search-for-an-answer". Each time a path through a Turing machine proceeds down one branch instead of another upon arriving at a nondeterministic state, the machine is "taking a guess" at which path ends in the correct result. A halting path is then interpreted as a "check", in the sense that it checks the resulting string on the tape to see if the guesses it made along the way result in the desied output.

So far, we have assumed that all Turing machines are deterministic. To make it clear that we are no longer making this assumption, from here on out when we want to allow a Turing machine to be nondeterministic (not require, but allow), we will call it a general Turing machine.

(Verifier) Let \(\mathcal T = (Q, A, \delta)\) be a general Turing machine, and let \(L \subseteq A^*\) be a language. We say that a state \(x \in Q\) is a verifier for \(L\) if
  1. every run of \(\mathcal T\) starting from \(x\) is finite (there are no unending loops), and
  2. for any \(w \in A^*\), \(w \in L\) if and only if there is a halting run starting from \(x\) on input \(w\) that accepts (returns the string \(1\)).
A language is called verifiable if it has a verifier.

The family of verifiable languages is written \(\mathsf{Ver}\).

(Verify a Verifier) Consider the following general Turing machine \(\mathcal V\) below.
state v
if _ : write 1.goto v
if 1 : move right.goto z
if 0 :
  ├ move right.goto u
  └ move right.goto z

state u
if _ : write 1.halt
if 0 : erase.move right.goto u
if 1 : erase.move right.goto u

state z
if _ : halt
if 0 : erase.move right.goto z
if 1 : erase.move right.goto z
Write down all of the halting runs starting from \(v\) on the input strings \(\varepsilon, 0, 110, 010, 0110\). Is it a verifier? If so, what language does it verify?

The worst-case runtime of a verifier is also a guess-and-check procedure, but it is less idealistic about the difficulty of finding an accepting run.

(Nondeterministic Runtime) Let \(\mathcal T = (Q, A, \delta)\) be a general Turing machine, and let \(x \in Q\) and \(w \in A^*\). The runtime of \(x\) on input \(w\) is the maximum over all runtimes of runs starting from \(x\), \[ \mathsf{time}(\mathcal T, x)(w) = \max\left\{\mathsf{time}(p_1\dots p_n) ~\middle|~ \begin{gathered} x \xrightarrow{a_1 \mid p_1} \cdots \xrightarrow{a_n \mid p_n} x_n \\ \text{is a run starting from \(x\)} \end{gathered} \right\} \] The worst-case runtime of \(x\) on inputs of length \(n \in \mathbb N\) in \(I\subseteq A^*\) is defined the same as before, \[ \mathsf{maxtime}_x^I(n) = \max\{\mathsf{time}(\mathcal T, x)(w) \mid \text{ \(w \in I\) and \(\mathsf{len}(w) \le n\) } \} \]

There are analogous families of languages for the complexity of verification.

(Nondeterministic Polynomial Time) We say that a language \(L \subseteq A^*\) is verifiable in polynomial time if there it has a verifier \(\mathcal V\) at state \(v\) such that \[ \mathsf{maxtime}_v \in \mathcal O(n^k) \] for some \(k \in \mathbb N\).

The family of all languages that are verifiable in polynomial time is written \(\mathsf{NP}\).

(Verification in Polynomial Time?) Does the general Turing program in the Verify the Verifier run in polynomial time?

\(\mathsf{P}\) versus \(\mathsf{NP}\)

If you will recall from the theory of regular languages, Kleene's theorem implied that nondeterministic automata are equal in expressiveness as total deterministic automata: they can decide the same family of languages. This actually doesn't hold for context-free languages: there are context-free languages that cannot be decided with any deterministic stack automaton. You have already spent time with a famous example of this, namely \(\{ww^{op} \mid w \in \{0,1\}^*\}\). It might therefore come as a surprise that in fact, general Turing machines are equal in expressivity to deterministic ones.

Every decision procedure is a verifier, so we immediately see that \[ \mathsf{Dec} \subseteq \mathsf{Ver} \] The opposite inclusion takes much more work to arrive at.

(Determinism Suffices) A language is decidable if and only if it is verifiable. That is, \(\mathsf{Dec} = \mathsf{Ver}\).
(Sketch.) We have already seen the forward inclusion. For the backward inclusion, we need to take every general Turing program, say Turing machine \(\mathcal V\) at state \(v\), that verifies a given language \(L\), and turn \(\mathcal V\) into a deterministic Turing program \(\mathcal T\) at state \(x\) that decides \(L\). Roughly: we can build a Turing program on two tapes that does a breadth-first search through the runs starting from \(v\), records the paths it has taken, and if it encounters an accepting run then it clears tape 1 and accepts (writes a \(1\)). If it has checked all possible halting runs, then it clears the tape and rejects (writes a \(0\)). The tricky part of a more formal proof would be to check that this Turing machine always halts and either writes a \(1\) or \(0\). This rests on property 1 of a verifier, that it has no infinite loops.

We failed to mention this in the Church-Turing thesis section. Why? We focused on \(k\)-tape Turing machines, multiple-symbols-to-two-symbols conversion, and even Turing machines that run on sheets because, if these run in polynomial time, then the deterministic Turing machine that simulates them also runs in polynomial time (this is not obvious, but it is true). This raises a very important problem with the deterministic Turing machine constructed in the proof above: even if the original (general) Turing program runs in polynomial time, it is likely that the constructed deterministic Turing machine runs in at least exponential time. This is simply because the number of paths that the deterministic Turing machine simulating the verifier has to sift through is in the worst case \(\mathcal O(b^{n^k})\) if there is a state that branches into \(b\) different paths somewhere in \(\mathcal V\) and the state runs in (nondeterministically) \(\mathcal O(n^k)\)-time. This immediately leads us to the following definition and theorem.

(EXP-time) A Turing program runs in polynomial-exponential time if \[ \mathsf{maxtime}_x \in \mathcal O({b^{n^k}}) \] for some \(b > 1\) and \(k \in \mathbb N\).
(Basic Inclusions) We have \(\mathsf{P} \subseteq \mathsf{NP} \subseteq \mathsf{EXP} \subseteq \mathsf{Dec}\).

This figure is not to scale! There are problems solvable in exponential time that are not in \(\mathsf{NP}\). And in reality, there are many complexity classes between \(\mathsf{EXP}\) and \(\mathsf{Dec}\).

The proof of the Determinism Suffices theorem does not tell us that a given language \(L \in \mathsf{NP}\) cannot be decided in polynomial time, it just doesn't give us a way of showing that it is. This is actually the subject of (probably) one of the most important open problems in modern mathematics.

(P vs NP) Is \(\mathsf{P} = \mathsf{NP}\)?

Solving this "bonus problem" above is an incredibly active area of research! Since we don't know the answer, we prefer instead to find solace in the techniques we do have.

(Polynomial Reductions for Nondeterminism) Let \(L_1 \in \mathsf{NP}\) be a language verifiable in polynomial time, and let \(r \colon L_1 \preceq L_2\) for a given language \(L_2\subseteq A^*\). Then \(L_2 \in \mathsf{NP}\).
(Graph Reachability Problem) Recall that a directed graph is a pair \(\mathcal G = (X, \to)\) consisting of a set \(X\) of nodes and a relation \({\to} \subseteq X \times X\) of edges. Given nodes \(x,y \in X\), \(y\) is reachable from \(x\) if there are \(x_1,\dots, x_n \in X\) such that \[ x \to x_1 \to x_2 \to \cdots \to x_n \to y \] Define \[ \mathbf{DGr} = \{(\mathcal G, x, y) \mid \text{\(\mathcal G = (X, \to)\) is a directed graph and \(x,y \in X\)} \} \] Then the reachability problem is \[ \mathit{Rch} = \{(\mathcal G, x, y) \in \mathbf{DGrph} \mid \text{\(y\) is reachable from \(x\) in \(\mathcal G\)} \} \]
  1. Draw an instance of the reachability problem.
  2. Come up with a faithful string representation of the reachability problem.
  3. Show that the reachability problem is in \(\mathsf{NP}\).
(Empty Language Problem for Automata) Recall that a state \(x \in Q\) of an automaton \(\mathcal A = (Q, A, \delta, F)\) accepts a word \(w = a_1 \cdots a_n\) if there is a path \(x \xrightarrow{a_1} x_1 \xrightarrow{a_2} \cdots \xrightarrow{a_n} x_n\) and \(x_n \in F\), and that \(\mathcal L(\mathcal A, x)\) is the set of all words accepted by the state \(x\) in \(\mathcal A\). Show that deciding whether a state accepts the empty language, i.e., \(\mathcal L(\mathcal A, x) = \{\}\), is in \(\mathsf{NP}\) by finding a polynomial time reduction to \(\mathit{Rch}\) above.
← 4.1 Polynomial Reductions4.3 Hard Problems →
Top