Lecture from: 21.10.2025 | Video: Videos ETHZ
Nondeterministic Turing Machines (NTMs)
We’ve introduced the deterministic Turing Machine (DTM) as our standard model of computation. Now, we explore a variant that seems much more powerful: the Nondeterministic Turing Machine (NTM).
Intuition: Guessing, Not Randomness
A common misconception is that “nondeterminism” means “randomness.” This is not the case. We are not flipping coins or dealing with probabilities.
- Randomness: A machine makes a random choice, and we care about the probability of reaching a correct answer.
- Nondeterminism: A machine can choose from multiple valid next steps. It “guesses” the correct path. If any sequence of choices leads to acceptance, the machine accepts.
Think of it as having a magical ability to always pick the right path in a maze, or exploring all paths in parallel universes.
Formal Definition of an NTM
An NTM is defined almost exactly like a DTM, as a 7-tuple . The only difference lies in the transition function .
In a DTM, the transition function maps a state and a symbol to one specific next move:
In an NTM, the transition function maps to a set of possible next moves (the power set):
This means that for a given state and tape symbol, the machine might have zero, one, or multiple valid transitions.
Computation Trees and Acceptance
Since an NTM can branch at each step, its computation on a specific input is not a single line, but a computation tree.
- The root is the start configuration q_0 \ w$.
- Each node is a configuration.
- The children of a node are all the configurations reachable in one step according to .
Acceptance Condition: An NTM accepts an input if there exists at least one path from the root to a configuration containing the accept state .
- If multiple paths accept, great.
- If some paths loop forever or reject, but one accepts, the machine still accepts.
- The machine rejects only if all possible computation paths halt and reject.
Example: The Traveling Salesperson Problem (TSP)
/Semester-3/Theoretical-Computer-Science/attachments/Pasted-image-20251202154431.png)
Consider the problem of deciding if a graph has a Hamiltonian Cycle (a cycle visiting every node exactly once).
- Deterministic Approach: A DTM would have to systematically generate and check every possible permutation of nodes. This corresponds to a brute-force search, taking roughly time.
- Nondeterministic Approach: An NTM can solve this “efficiently” (in polynomial time):
- Guess: Nondeterministically write a list of vertices on the tape. This corresponds to “guessing” a permutation. Since the machine can branch, one of its computation paths will write the correct Hamiltonian cycle (if one exists).
- Verify: Deterministically check if the list on the tape is a valid cycle in . This takes polynomial time.
If the graph has a cycle, there is a path in the computation tree where the machine guesses it correctly and accepts. Thus, the NTM accepts the language of Hamiltonian graphs efficiently. This capability is the core of the complexity class NP (Nondeterministic Polynomial time).
Equivalence of DTMs and NTMs
Does this magical guessing ability allow NTMs to solve problems that DTMs simply cannot (regardless of time)? The answer is no.
Theorem: Every Nondeterministic Turing Machine has an equivalent Deterministic Turing Machine.
Proof Idea: Breadth-First Search
We can simulate an NTM using a DTM . The DTM will explore the computation tree of .
- Why not Depth-First Search (DFS)? The computation tree of might have infinite paths (loops). If uses DFS, it might go down an infinite non-accepting path and never find the accepting state on a different branch.
/Semester-3/Theoretical-Computer-Science/attachments/Pasted-image-20251202155955.png)
- Solution: Breadth-First Search (BFS). explores the tree layer by layer.
- Check the start configuration (depth 0).
- Check all configurations reachable in 1 step (depth 1).
- Check all configurations reachable in 2 steps (depth 2).
- … and so on.
/Semester-3/Theoretical-Computer-Science/attachments/Pasted-image-20251202155940.png)
Since the branching factor of is finite (limited by ), each level of the tree is finite. If an accepting configuration exists, it must appear at some finite depth . A BFS is guaranteed to find it eventually.
Construction of : can be a 3-tape machine:
- Input tape: Holds the original input .
- Simulation tape: Used to simulate one specific path of .
- Address tape: Keeps track of which node in the tree we are currently visiting (e.g., using a string of numbers to represent “choice 1, then choice 3, then choice 2…”).
systematically generates all addresses (sequences of choices) in lexicographical order (short first). For each address, it copies to the simulation tape and runs following those specific choices. If accepts, accepts.
Implication: NTMs and DTMs accept the same class of languages (). Nondeterminism affects efficiency (time complexity), but not decidability.
Enumerating Turing Machines
We now turn to a concept crucial for proving undecidability: Countability.
Encoding Turing Machines
A Turing Machine is a finite object. It’s defined by a 7-tuple with finite sets of states and symbols and a finite transition table. This means we can encode any TM as a string (e.g., a binary string).
- Assign numbers to states .
- Assign numbers to tape symbols .
- Encode the transition function as a list of rules like
(state, read) -> (new_state, write, move).
Just as we can compile a Python program into a binary executable, we can serialize a TM into a string .
The Set of TMs is Countable
Since every TM can be encoded as a binary string, the set of all Turing Machines is a subset of the set of all binary strings . We know is countable (we can list them: ). Therefore, the set of all Turing Machines is also countable. We can create a canonical list of all TMs: .
Countability and Diagonalization
To understand the limits of computation, we need to compare the size of the set of algorithms (TMs) vs. the set of problems (languages).
Countable Sets
A set is countable if there exists a surjective function . Equivalently, we can list the elements of as .
- Finite sets are countable.
- (natural numbers) is countable.
- (integers) is countable (list: ).
- (all strings) is countable.
The Pairs of Natural Numbers ()
Is the set of pairs countable? It seems “larger” than , like a 2D plane vs. a line. However, Cantor showed it is countable using a diagonalization argument (specifically, traversing anti-diagonals).
We can list pairs by the sum of their indices :
- Sum 0:
- Sum 1:
- Sum 2:
- …
/Semester-3/Theoretical-Computer-Science/attachments/Pasted-image-20251202171040.png)
This gives us a valid enumeration (bijection with ):
This technique proves that any finite Cartesian product of countable sets is countable (e.g., , ).
Conclusion: Since the set of all possible TMs is countable, but (as we will see next time) the set of all possible languages is uncountable, there are infinitely many languages that cannot be recognized by any Turing Machine. Most problems are unsolvable!