Nondeterministic Turing Machines
Imagine a maze solver who, at every fork, could clone itself. Each clone could explore all branches simultaneously. One clone would inevitably wander into the exit, if an exit exists. We would declare success the moment any clone reaches it. This is the intuitive engine behind the nondeterministic Turing machine (NTM). It is a computational model that generalizes the Multitape Turing Machines framework. It allows many possible next moves from a single configuration, rather than exactly one. NTMs matter because they give a clean mathematical language for "guess and check" algorithms. These appear everywhere in computability and complexity theory. Verifying a satisfying assignment for a Boolean formula is one example. Checking a proposed path in a graph is another. Confirming a candidate factorization is a third. All are naturally nondeterministic tasks: guess a certificate, then verify it deterministically. The surprising and foundational fact — proved carefully in this article — is that nondeterminism buys no extra computability power over deterministic machines. This holds true even though, as later material on complexity will explore, it may buy enormous efficiency differences. The big picture is this: an NTM's computation is not a single sequence of configurations. Instead it is a tree of them, branching every time the transition function offers more than one choice. The machine accepts an input if any root-to-leaf path in this tree reaches an accepting configuration. We will show that any such tree, however wide or infinite in places, can be systematically searched. An ordinary deterministic machine can do this using breadth-first traversal. So nothing decidable-by-nondeterminism escapes deterministic decidability. This article builds the formal definition of an NTM. It walks through the breadth-first simulation algorithm that proves deterministic equivalence. It analyzes the (sometimes brutal) blowup in running time this simulation costs. It also traces the historical path that led to this model. It sets up ideas that recur throughout the theory of computability. These include decidability robustness under the Church-Turing Thesis, and the encoding tricks used to enumerate configurations.
- An NTM's transition function maps a state and tape symbol to a set of possible next moves, not a single one.
- A computation is a tree of configurations; the machine accepts if some branch reaches an accept state.
- Every NTM has an equivalent deterministic TM (DTM), proved by breadth-first search over the computation tree.
- Depth-first simulation fails: it can loop forever down one infinite branch, missing a shallow accepting leaf.
- The equivalence is constructive but not free: it can incur exponential blowup in running time.
- NTMs are the conceptual seed for complexity classes like NP, though this article stays purely in computability.
Nondeterminism only widens the search, and breadth-first simulation shows any such search is still mechanically doable — so NTMs decide exactly the same languages as deterministic Turing machines.
The idea
A deterministic Turing machine's transition function has signature
mapping each (state, tape symbol) pair to exactly one action. A nondeterministic Turing machine relaxes this to
where denotes the power set. At each step, the machine may have zero, one, or many legal moves available, and it is free to take any of them. There is no mechanism actually resolving the choice — the model simply asserts all choices are pursued "in parallel" in the mathematical sense. This turns a computation from a single sequence of configurations into a computation tree: the root is the start configuration on the given input, and each configuration has one child for every move the transition function permits from it. A branch that reaches a configuration with no available moves is a dead branch (analogous to explicit rejection). An NTM accepts an input string if at least one path from the root reaches a configuration in an accepting state — even if every other branch rejects, loops, or dies. rejects if every branch is finite and every leaf is rejecting (no branch loops forever and none accepts). If some branches loop forever and none accepts, itself does not halt on , mirroring the same three-way outcome (accept / reject / loop) that ordinary Multitape Turing Machines exhibit. It is essential to separate two distinct questions that nondeterminism raises: what languages can NTMs recognize or decide (a question of computability, answered completely in this article), and how fast can they do it compared to deterministic machines (a question of complexity, only foreshadowed here). The equivalence theorem below settles the first question unconditionally: NTMs and DTMs recognize exactly the same class of languages, and decide exactly the same class of decidable languages. The efficiency question is subtler and is precisely the origin of the P versus NP problem, which builds on the very simulation technique developed here.
How it works
The equivalence proof is constructive: given any NTM , we build a DTM that simulates and decides/recognizes the same language. The key design decision is how to explore the computation tree.
Why depth-first fails. A naive simulator might pick a branch, follow it to completion (accept, reject, or forever), then backtrack and try the next branch — a depth-first traversal. This is unsound: if the tree has an infinite branch (the machine loops on some sequence of choices) positioned before a shallow accepting leaf in the traversal order, the simulator gets stuck exploring the infinite branch and never reaches the accepting one, even though does accept .
The fix: breadth-first search. Instead, the simulator explores the tree level by level: all configurations reachable in 1 step, then all reachable in 2 steps, and so on. Since accepting configurations, if they exist at all, occur at some finite depth along some branch, a breadth-first search is guaranteed to discover one after enumerating finitely many configurations — regardless of what happens in other, possibly infinite, branches. To make this concrete on an ordinary (multitape, hence by known equivalence single-tape) deterministic machine, we use a three-tape simulator:
- Tape 1 holds the input , untouched throughout.
- Tape 2 is the simulation workspace, where writes out the tape contents of the NTM configuration currently being explored.
- Tape 3 holds an address string over the alphabet , where is the maximum branching factor of 's transition function. This string names a path from the root: symbol at position means "at depth , take the -th nondeterministic choice available."
generates address strings in a fixed enumeration order (numeric order: ) — the standard technique used later when discussing Encodings and Enumerators for systematically listing objects. For each address string, resets tape 2 to the input, then replays the moves the address dictates, one node of the tree per prefix, checking after each move whether that choice was even legal (some addresses correspond to no real branch, since not every configuration has children) and whether the resulting configuration accepts. ``` Algorithm SIMULATE-NTM(N, w): // N: an NTM with transition function δ, max branching factor b // w: input string // D: the deterministic simulator we are describing Tape 1 := w // never modified Tape 3 := empty string // will enumerate addresses in {1..b} loop forever: copy Tape 1 onto Tape 2 // reset simulated tape to input set simulated configuration C := start configuration of N on w address := next string in {1,...,b} in counting order // ε,1,2,...,b,11,... write address onto Tape 3 for each symbol s in address (left to right): if C has no legal moves (dead branch): break out of this for-loop, discard this address, continue outer loop if s > (number of legal moves available at C): break out of this for-loop, discard this address, continue outer loop // this address does not correspond to a real path C := result of applying the s-th legal move of δ to C (update Tape 2 and simulated state/head position accordingly) if C is an accepting configuration: ACCEPT // (finished replaying the whole address without accepting or dying) // do nothing special; just move on to the next address in the enumeration ``` If is a decider (every branch of every input halts), can be strengthened into a decider too: since the tree is then finite, can detect when every address up to a certain length has been exhausted with no accept found, and safely reject. If merely recognizes a language (some branches may loop), recognizes the same language but may itself loop forever on rejected inputs — which is unavoidable, since recognizability, not decidability, is all that is preserved in general.
Notice in the figure that a depth-first explorer that happened to descend into the "infinite branch" subtree before trying node 6 would never terminate, while the breadth-first order guarantees node 6 (the accept) is visited at a finite, bounded step regardless of what lurks deeper in sibling subtrees.
Complexity & correctness
Correctness argument. We must show where denotes the language recognized. () If accepts , then accepts . only enters its ACCEPT state after correctly replaying a legal sequence of moves of from the start configuration to a configuration in an accepting state of . Each step of the replay was checked against for legality, so this sequence is a genuine root-to-leaf path in 's computation tree ending in acceptance. Hence accepts by definition. () If accepts , then accepts . Since accepts , some finite path of moves (each a legal choice at its configuration) leads from the start configuration to an accepting configuration. Let be the address string encoding this exact sequence of choices, using as the alphabet size (each corresponds to some choice-index between and the branching factor at that node, which is at most ). Since 's enumeration of addresses in counting order eventually produces every finite string over , it will eventually produce itself, replay it faithfully (by the same legality argument as above, applied in reverse), and detect the accepting configuration, entering ACCEPT. This is an if-and-only-if correspondence between accepting computations of and accepting runs of 's simulation loop, which is exactly the invariant needed: enters ACCEPT on input if and only if some branch of 's tree on accepts. The breadth-first-flavored counting order is what makes the "" direction actually terminate in finite time rather than merely being true in an infinite limit — this is precisely why depth-first traversal, which can defer the correct finite-length address indefinitely, is unsound while a fair (breadth-first-equivalent) enumeration is sound.
Decider case. If is guaranteed to halt on every branch for every input (a decider), the tree on input is finite (König's lemma: a finitely branching tree with only finite paths is itself finite). can be modified to perform an explicit level-by-level breadth-first search — generating exactly the addresses of length up to the point where every branch at that depth is finished (either a leaf or dead) — and reject once no accepting configuration remains reachable at any further depth. This gives a genuine decider , matching 's decidability rather than merely its recognizability.
Time and space complexity. Let run in time on inputs of length , meaning every branch of 's computation tree on any length- input has depth at most , and let be the maximum branching factor. The tree has at most
nodes. 's breadth-first simulator must potentially visit all of them, and replaying each address from the root costs time (to copy the input and step through the address), so the total simulation time is
an exponential blowup in the running time even though itself might be small (even polynomial). This exponential gap is not a defect of this particular simulation strategy — no fundamentally faster general simulation is known, and closing this gap for polynomial-time bounded computations is exactly the content of the P versus NP question. Space usage is more modest: tape 2 needs only cells (the simulated tape cannot grow faster than the number of steps taken), and tape 3 needs cells to hold one address, so the simulator's space is polynomial in even though its time is exponential — an asymmetry worth remembering.
Tradeoffs, honestly stated. The equivalence theorem is unconditional and constructive: every NTM can be replaced by a DTM deciding or recognizing exactly the same language, with no restriction on the NTM's structure. What is not preserved, in general, is efficiency: there is no known way to simulate an NTM by a DTM with only polynomial slowdown, and it is a major open problem whether one exists. So "NTMs add no computational power" is a precise, correct, and complete statement about decidability and recognizability, but it says nothing reassuring about running time, a distinction every student should hold onto tightly.
Worked example
Consider a toy NTM deciding whether a binary string contains the substring `101`, using nondeterminism merely for illustration (this language is of course also easy deterministically — the point is to trace the simulation machinery, not to need nondeterminism). works as follows: at each tape cell, before reading it, nondeterministically guesses whether the substring `101` starts here. If it guesses "yes," it deterministically checks the next three symbols; if they match `101`, it accepts; otherwise this branch dies. If it guesses "no," it moves the head one cell right and repeats the guess. If the head runs off the end of the input without any branch having accepted, that branch rejects. So at every non-dead-end configuration, has (up to) two choices: guess `1` (try to match here) or guess `2` (skip and continue). The branching factor is . Run on (length 7). Let's trace the accepting path and see how the address-string simulator finds it.
| Position (0-indexed) | Symbol read | Choice "1" (attempt match) | Choice "2" (skip) |
|---|---|---|---|
| 0 | 0 | check `w[0..2]` = `011` ≠ `101`, dies | move to position 1 |
| 1 | 1 | check `w[1..3]` = `101` = `101` ✓ ACCEPT | move to position 2 |
| 2 | 1 | check `w[2..4]` = `010` ≠ `101`, dies | move to position 3 |
| 3 | 0 | check `w[3..5]` = `100` ≠ `101`, dies | move to position 4 |
| 4 | 1 | check `w[4..6]` = `100` ≠ `101`, dies | move to position 5 |
| 5 | 0 | off-end before 3 more symbols exist, dies | move to position 6 |
| 6 | 0 | off-end, dies | head at end, this branch rejects |
The shortest accepting path is: at position 0 choose "2" (skip), then at position 1 choose "1" (attempt, matches). Encoded as an address string over this is . The deterministic simulator enumerates addresses in counting order: . Tracing 's outer loop:
| Address tried | What happens on replay | Result |
|---|---|---|
| 0 moves replayed; configuration is start, not accepting | continue | |
| `1` | position 0, choice 1: check `011`, mismatch, branch dies mid-replay | discard, continue |
| `2` | position 0, choice 2: move to position 1; address exhausted, not accepting | continue |
| `11` | position 0 choice 1 already dead after first symbol; address `1` prefix invalid past length 1 | discard, continue |
| `12` | same — position 0 choice 1 already died, `12` unreachable | discard, continue |
| `21` | position 0 choice 2 (move to pos 1); position 1 choice 1: check `w[1..3]` = `101`, matches | ACCEPT |
accepts at address `21`, the sixth address in the enumeration — confirming both that acceptance is found, and that it is found in a small, finite number of steps despite the existence of other addresses (like ones probing positions 5, 6) whose branches simply die rather than loop. In this example nothing loops forever, but the reason 's strategy is safe in general — as argued in Complexity & correctness — is that no matter how many other branches were infinite instead of merely dead, the shallow accepting address `21` would still be reached at the same finite point in the counting-order enumeration.
Common pitfalls & traps
| Pitfall | Why it's wrong | Fix |
|---|---|---|
| Simulating with depth-first search | Can hang forever inside one infinite branch, permanently missing a shallow accept elsewhere | Use breadth-first / counting-order enumeration of addresses |
| Treating "NTM accepts" as "all branches accept" | Definition requires only some branch to accept, not all | Re-check: acceptance is existential over branches |
| Assuming NTM equivalence implies equal running time | The construction incurs overhead; no known polynomial simulation exists | State the equivalence as decidability/recognizability only, not efficiency |
| Confusing " rejects " with " does not accept " | Rejection formally requires every branch to halt without accepting; if some branch loops forever and none accepts, neither accepts nor rejects | Track all three outcomes: accept / reject / loop |
| Forgetting the branching factor bound | Without a fixed max branching factor, addresses can't be drawn from a fixed finite alphabet, breaking the enumeration | Take as the maximum number of choices ever offers (finite since are finite) |
| Copying the whole tree into memory | Tempting but unnecessary and wasteful; only the current path from root needs to be materialized | Reconstruct each configuration by replaying its address from the root, tape 2 as scratch space |
Pioneers & history
The nondeterministic Turing machine crystallized as a formal object during the 1960s and 1970s, as researchers systematized the Turing-machine framework Alan Turing had introduced decades earlier and began classifying problems not just by decidability but by resource cost.
Origins · 1 minAlan Mathison Turing and how this was discovered
Turing's 1936 paper "On Computable Numbers" defined the deterministic machine model — states, tape, transition function — that later theorists extended with nondeterministic choice. Though Turing himself worked within a strictly deterministic framework, his abstraction of "mechanical procedure" as a formal object is the substrate on which the nondeterministic generalization, and the entire question of what nondeterminism does or does not add, is built.
Where this matters
Nondeterministic Turing machines are, first and foremost, a conceptual scaffold: almost no real hardware "runs" nondeterministically in the Turing-machine sense, since physical computers must make one choice at a time. Their importance is that they crisply formalize the "guess-and-verify" pattern that pervades algorithm design and complexity theory. The class NP is literally defined as the languages decided by NTMs running in polynomial time, and the question of whether every such guess can be found as fast as it can be verified — P versus NP — is arguably the central open problem of theoretical computer science. Beyond that headline connection, nondeterministic models are the backbone of automata theory taught alongside Turing machines: nondeterministic finite automata and nondeterministic pushdown automata use the identical subset-construction or tree-search ideas to prove equivalence with their deterministic counterparts, and NPDAs (unlike NTMs) genuinely add expressive power over deterministic PDAs, making the contrast instructive. In practice, tools like SAT solvers, constraint solvers, regular-expression engines, and parser generators are engineering answers to "how do we efficiently emulate nondeterministic search on deterministic hardware," directly inheriting the breadth-first-versus-depth-first tension this article develops. The equivalence proof's technique — encode a choice sequence as a string, enumerate all such strings systematically — is also the direct ancestor of the enumeration and encoding tricks used when discussing Encodings and Enumerators, and the entire discussion presumes the robustness that the Church-Turing Thesis asserts: any reasonable notion of "effective procedure," deterministic or not, computes the same class of functions.
Ask the tutor: How does the breadth-first simulation change if we want the resulting deterministic machine to also be a decider, not just a recognizer?
Does the existence of an equivalent DTM mean NTMs are "useless" as a model?
Not at all — NTMs remain extremely useful as a design and analysis tool even though they add no computability power. Many problems have a natural, simple nondeterministic algorithm (guess a certificate, verify it) that would be awkward to express deterministically. NTMs let theorists reason about such algorithms directly and then invoke the equivalence theorem to know a deterministic version exists. More importantly, NTMs are the definitional backbone of complexity classes like NP: the time bound on the nondeterministic machine, not just its existence, is the object of study. So NTMs are indispensable for classification and algorithm design, even though every language they recognize was already deterministically recognizable.
Is the breadth-first simulation the only way to prove the DTM/NTM equivalence?
It is the standard and most intuitive proof, but not the only formalization. Some treatments instead argue via a "universal search" machine that dovetails execution across all finite address strings, interleaving one step of each in round-robin fashion rather than strictly processing complete addresses level by level; this achieves the same fairness guarantee (every finite address is eventually fully processed) through a different bookkeeping scheme. Other treatments frame it through the equivalence of Turing machines with other nondeterministic-looking models like nondeterministic RAM machines, again bottoming out in a systematic, fair enumeration of choice sequences. All correct proofs share the essential ingredient: some fairness guarantee ruling out permanent starvation of any finite-depth branch.
Why does the simulation blow up exponentially rather than just polynomially?
Because the computation tree itself can have exponentially many nodes relative to its depth: at branching factor b and depth t(n), the tree has on the order of b^{t(n)} nodes, and a systematic search visiting all of them (or a large fraction, in the worst case where the accepting leaf is one of the last enumerated) inherently costs at least that much time. No known algorithm avoids this blowup for the general case of arbitrary NTMs; whether a fundamentally cleverer deterministic strategy could always do polynomially better is exactly the P versus NP question restricted to polynomial-time NTMs (i.e., languages in NP).
Can an NTM have infinitely many choices at a single step?
In the standard definition, no — the transition function's codomain is , and since and are required to be finite sets, this codomain is itself finite, meaning the number of choices at any single configuration is bounded by a constant that does not depend on the input. This finiteness is essential: it is exactly what lets us encode a choice sequence as a string over the finite alphabet , which the breadth-first simulator can enumerate systematically. Without it, the address-string trick would not even be well-defined.
How does this connect to nondeterministic finite automata (NFAs)?
NFAs use the same fundamental idea — a transition relation instead of a transition function, yielding a tree (or more precisely a DAG when states repeat) of possible runs — and NFAs are also proved equivalent to deterministic finite automata (DFAs). The crucial difference is the mechanism: NFA-to-DFA conversion uses the subset construction, tracking the set of all NFA states reachable so far in a single DFA state, which works because NFAs have no unbounded tape and hence only finitely many possible "sets of live branches." NTMs have unbounded tape contents, so an analogous finite subset-construction is not directly available, forcing the more elaborate breadth-first address-enumeration technique instead.
What role does nondeterminism play in the Church-Turing Thesis?
The Church-Turing Thesis asserts that every "intuitively effective" computational procedure can be carried out by a deterministic Turing machine. The NTM-to-DTM equivalence theorem is exactly the kind of robustness result that supports this thesis: it shows that adding a seemingly more powerful mechanism — parallel branching choice — does not escape the deterministic Turing-computable universe. This pattern repeats across many other proposed enhancements (multiple tapes, two-dimensional tapes, random-access memory, oracle access at bounded resource levels), and each such equivalence proof adds independent evidence that the deterministic Turing machine captures a natural, stable notion of mechanical computation.
Do real programming languages or hardware implement true nondeterminism as defined here?
Not in the pure sense of literally pursuing every branch simultaneously with unbounded resources. What real systems implement are approximations: backtracking search (essentially depth-first simulation with bookkeeping to allow eventual exhaustive coverage), constraint solvers and SAT solvers (heuristically guided search over an implicit choice tree), and true hardware parallelism (a bounded number of literal parallel threads, not an unbounded branching tree). The Turing-machine notion of nondeterminism is best understood as an idealized upper bound — "what if you could try everything at once" — against which these practical approximation strategies are measured and analyzed.