Sub topic 4
Multi-tape and nondeterministic machines are equivalent in power
This chapter assumes you can trace a single-tape deterministic Turing machine (DTM) by its configurations. It also assumes you know the difference between a machine that halts on every input (a decider) and one that may loop (a recognizer). You should also remember that an NFA and a DFA accept the same languages.
Why variants matter
The basic model has one tape and one deterministic transition rule. Textbooks and exams also use machines with several tapes, or machines that can guess. If these variants could compute more than the basic model, every theorem about "Turing machines" would need a version for each of them. They cannot. Adding tapes or nondeterminism changes how fast a machine runs, but not which languages it recognizes or decides. That is the idea behind the Church-Turing thesis, which a later chapter covers.
| Variant | What is added | Same languages as a single-tape DTM? | Cost of simulating it on a DTM |
|---|---|---|---|
| Multi-tape TM | k tapes, k independent heads | Yes | t steps become O(t²) steps |
| Nondeterministic TM (NTM) | Several possible moves per configuration | Yes | t steps become 2^O(t) steps |
| Two-way infinite tape, stay-put move | Tape unbounded on both sides, or an S move | Yes | Constant-factor or small overhead |
Multi-tape machines
A k-tape machine has a finite control and k tapes, each with its own head. In one step it reads the k symbols under its heads. Based on the state and those symbols, it writes a symbol on each tape, moves each head left, right, or not at all, and changes state:
δ: Q × Γ^k → Q × Γ^k × {L, R, S}^k
The input is written on tape 1 and the other tapes start blank.
Simulating k tapes on one tape
A single-tape machine can store all k tapes on its one tape. It writes the contents of the tapes one after another, separated by a marker #. To remember where each head is, it uses a marked copy of each symbol, such as a for an unmarked cell and a dotted ȧ for a cell under a head. The tape alphabet grows, but it stays finite.
To simulate one step of the multi-tape machine, the single-tape machine does the following:
- It sweeps left to right across the whole used region and records the k marked symbols in its state.
- It sweeps again and applies the writes and head moves.
- If a head moves onto a
#, it shifts the rest of the tape one cell to the right to make room.
After t simulated steps, the used region has length O(t + n). Each simulated step takes one or two sweeps over that region, so the total time is O(t²) when t ≥ n. The cost is polynomial, so the language is unchanged.
A two-tape machine recognizes palindromes in O(n) steps. It copies the input to tape 2, moves head 2 back to the start, and then compares the two tapes in opposite directions. A single-tape machine needs Ω(n²) steps for the same language, because it must shuttle between the two ends of the input. This gap in running time does not affect decidability.
Nondeterministic machines
An NTM allows several moves from one configuration:
δ: Q × Γ → P(Q × Γ × {L, R})
The computation is a tree. Each node is a configuration, and its children are the configurations reachable in one step. Acceptance and decision are defined over the whole tree:
- N accepts w if at least one branch reaches the accept state.
- N rejects w if every branch ends in reject, or ends because no transition applies.
- N decides a language if on every input every branch halts.
- N recognizes a language if it accepts exactly the strings in it. Other branches may loop.
Simulating an NTM deterministically
A deterministic machine must explore the tree. The order of exploration matters.
- Depth-first search is wrong. If the first branch it follows runs forever, it never looks at a different branch that accepts. The simulation would fail to accept a string that N accepts.
- Breadth-first search is right. It visits all configurations at depth 1, then depth 2, and so on. If any branch accepts, it appears at some finite depth, and the search reaches it.
A standard construction uses three tapes, which step 1 above lets you convert to a single tape:
- Tape 1 holds the original input and is never changed.
- Tape 2 is a working copy where one branch is simulated.
- Tape 3 holds an address, a string over {1, …, b} where b is the largest number of choices in any transition. The address says which child to take at each step of the branch.
The machine tries addresses in order of length, and in numerical order within each length. For each address it copies tape 1 to tape 2 and simulates N, using the address digits to resolve each choice. Addresses that name a nonexistent choice are skipped. If a simulated branch reaches the accept state, the machine accepts.
What happens with deciders
Suppose N halts on every branch for every input, so N is a decider. The computation tree is then finite, because a tree with finite branching and no infinite path is finite. The breadth-first simulation therefore either finds an accepting branch or empties the queue and rejects. The simulating machine is a decider as well. So NTM deciders and DTM deciders define the same class, the recursive languages.
If N is only a recognizer, the simulation is also only a recognizer. It accepts when N accepts and may run forever when N does not. Nondeterministic and deterministic machines therefore define the same class of recursively enumerable languages.
A runnable simulator
This Python code does breadth-first search over configurations. A configuration is a state, the tape contents, and the head position. The tape is a string that grows on the right when needed. The head cannot move left of cell 0. The max_configs limit returns None when the search is cut off. That result means "no verdict", which is the same trade-off as the step limit in the deterministic simulator from the design chapter.
from collections import deque
def ntm_accepts(delta, w, start='q0', accept='qa', blank='_', max_configs=100000):
init = (start, w, 0)
queue = deque([init])
seen = {init}
explored = 0
while queue:
state, tape, head = queue.popleft()
if state == accept:
return True
explored += 1
if explored > max_configs:
return None # cut off: no verdict
sym = tape[head] if head < len(tape) else blank
for new_state, write, move in delta.get((state, sym), []):
t = tape if head < len(tape) else tape + blank
t = t[:head] + write + t[head + 1:]
h = max(head + (1 if move == 'R' else -1), 0)
cfg = (new_state, t, h)
if cfg not in seen:
seen.add(cfg)
queue.append(cfg)
return False
# Accepts binary strings that contain the substring 11.
# On reading a 1 in q0, the machine guesses whether this 1 starts the 11.
delta = {
('q0', '0'): [('q0', '0', 'R')],
('q0', '1'): [('q0', '1', 'R'), ('q1', '1', 'R')],
('q1', '1'): [('qa', '1', 'R')],
}
for w in ['', '0', '10', '011', '1011', '1010']:
print(repr(w), ntm_accepts(delta, w))
# '' False, '0' False, '10' False, '011' True, '1011' True, '1010' FalseA missing entry in delta means the branch dies. The seen set stops the search from repeating a configuration it has already queued.
Power versus efficiency
The simulations show equal power but unequal cost. The NTM simulation takes time exponential in the number of steps. Nobody knows whether this blow-up is needed for decision problems that run in polynomial time on an NTM. That question is P versus NP. It concerns resource use only, and it has no effect on decidability.
Other variants also keep the same power: a tape infinite in both directions, a "stay" move, several heads on one tape, and a machine with a two-dimensional tape. A machine with two stacks is also equivalent, which shows how little extra a pushdown machine needs to become a full TM. Restrictions can reduce power. A tape limited to the input length gives a linear bounded automaton, which is weaker.
Common errors
- Claiming nondeterminism adds power. This is false for TMs. It is also false for finite automata. It is true for pushdown automata: deterministic PDAs accept a proper subset of the languages that nondeterministic PDAs accept. Do not carry the PDA fact over to TMs.
- Using depth-first search in the simulation argument. It fails on trees with infinite branches.
- Forgetting that an NTM decider needs every branch to halt. One looping branch makes it only a recognizer.
- Treating a time gap as a power gap. "A multi-tape machine is faster" does not mean it recognizes more languages.
Exercise
A student argues that a nondeterministic Turing machine can recognize the halting language, which no deterministic machine can, because it can guess a halting computation. What is wrong with this argument?
Show answer
The guessing does not add power. The breadth-first simulation tries every branch in order of depth, so a deterministic machine accepts exactly when some branch of the NTM accepts. The halting language is recursively enumerable, so a deterministic machine already recognizes it by simulating the program. It is not recursive, and an NTM cannot decide it either. If the NTM were a decider, the simulation would give a deterministic decider.
Exercise
A 3-tape DTM decides a language in t(n) = n³ steps. What is the best bound this chapter's construction gives for an equivalent single-tape DTM, and does the language remain decidable?
Show answer
The simulation takes O(t²) steps, so the single-tape machine runs in O(n⁶) steps. The machine still halts on every input, so the language remains decidable. Only the running time changed.