Modelcore
Multitape Turing machine
Also called k-tape Turing machine.
Turing machine with several independent tapes and heads, used to measure running time more naturally.
A multitape Turing machine is a Turing machine with tapes, each with its own head, and one finite control that reads the scanned symbols together. In one step it writes a symbol on each tape and moves each head by at most one cell. It decides the same languages as the one-tape machine, but many tasks are faster on it: a palindrome test takes linear time on two tapes and quadratic time on one tape. Hartmanis and Stearns (1965) introduced it as the model for time complexity, and most texts define classes such as P with it.
The machine
A -tape machine , for a fixed , has these parts:
- a finite set of states, with a start state and two halting states, accept and reject;
- a finite tape alphabet that contains a blank symbol , and an input alphabet ;
- a transition function .
Each tape has cells numbered and is infinite to the right. At the start, the input is in cells to of tape 1. All other cells hold the blank, and all heads are on cell . A step works like this. The machine is in state , and head reads the symbol . If , then for every at the same time the machine writes on tape and moves head by , and it enters state . The move keeps the head in place. A head on cell with the move also stays, as in the one-tape machine. The language , a computation, and the terms decides and recognizes are defined as for the one-tape machine.
Two common variants have the same power and the same time up to a constant factor, for time bounds . The first has a read-only input tape and a write-only output tape, with work tapes between them. The second has tapes that are infinite in both directions. The input tape variant is the one used to define sublinear space.
Example: palindromes. Let , where is written backwards. The two-tape machine below decides . It first copies to tape 2, after a marker in cell 0 of tape 2. Then it moves head 2 back to the marker. Last, it reads tape 1 from right to left and tape 2 from left to right, and it compares the two symbols at each step. The head of tape 1 ends on cell when the comparison ends, and the machine uses the left-end rule to stay there. The table lists the rules. Here , and a pair that the table does not list goes to reject.
| State | Reads | Writes | Moves | Next state |
|---|---|---|---|---|
| accept | ||||
| accept |
In state , the pair with has no rule, so the machine rejects. After comparisons, head 2 is on cell of tape 2, so it reads a blank exactly when . At that time head 1 is on cell , which holds a symbol of . So the rule of state fires after all pairs matched. On a palindrome of length the machine makes steps, for example steps on , steps on and steps on . On the empty word it makes step. On a word of length it makes at most steps. So is decided in time with two tapes.
What it counts
The time of on an input is the number of steps before it halts, and one step costs one unit, whatever is. The worst-case time is the largest time over the inputs of length .
The space of a run is the number of distinct cells that the heads visit on the work tapes. With a read-only input tape, the input cells do not count, so the space can be smaller than . Without that tape, the input cells that a head visits count.
A time class such as is the set of languages decided in time by a -tape machine for some . Papadimitriou and most complexity texts define it with multitape machines, and Sipser uses one-tape machines. The two definitions agree on polynomial time but not on classes such as . The choice of matters for the exact class: with two tapes, but not with one tape (see below). It does not matter for polynomial time, because of the simulation below.
Relation to other models
The one-tape machine simulates the -tape machine with a quadratic loss of time. The multitape simulation theorem has its own page. The proof below is complete; the theorem page gives more detail.
Claim. Let be a deterministic -tape machine that decides and halts in at most steps on every input of length . Then a one-tape machine decides in steps, where the constant depends only on .
Construction. The tape of has the cells , and cell holds one symbol of a finite alphabet . The symbol records, for each tape of :
- the symbol in cell of tape , and
- a flag . The flag means that head of is on cell . The flag is a temporary mark that is used inside one simulated step. The flag means neither.
It also records a bit that is exactly in cell . The blank of is the symbol with , and for all . The state of holds the state of and a bounded amount of other data (at most the symbols read, a set of indices, and a phase name).
Invariant . After simulated steps, is in cell in a state that holds the state of , and the flags and the symbols in the tape of describe the configuration of after steps. No flag is present.
Steps.
-
Start (phase 0). reads the input from left to right. In cell it always writes and for all , with if and if . In cell with it writes , and . In all cells for . If it stays on cell and this phase ends after one step. Otherwise it stops at the first blank, which is in cell , and moves left to cell , which it finds by the bit . This takes at most steps and makes true.
-
Scan right (phase 1). Assume with in a non-halting state . moves right from cell . On each cell it reads, for every with , the symbol and stores it. It stops when it has seen flags. Let , where is the cell of head . The step that reads cell completes the list, so this phase takes at most steps. Each head moves at most one cell in a step of , and starts on cell , so .
-
Decide. In the step that reads cell , knows and the scanned symbols . Its finite control computes . If is accept or reject, halts in the same way, and the claim is true for this input by .
-
Scan left (phase 2). The step that reads cell also starts this phase. moves left from cell to cell , which it detects by , and it stays there by the rule for cell . In each cell, and for each with , it writes in place of , and it changes the flag by the move :
- if , the flag stays ;
- if , the flag becomes ;
- if and , the flag becomes , and the state records that the next cell to the left (cell ) gets the flag for tape ;
- if and , the flag stays , by the rule for cell .
When writes cell , it also sets the flags that the state recorded. The two kinds of flag in one cell do not clash, because each tape has one head. This phase takes at most steps.
-
Scan right for the marks (phase 3). If no is , skip to step 7. Else moves right from cell . At a cell with a flag it sets that flag to , and it sets the flag for the same tape in the next cell to the right, which it writes in the next step. It stops after it has handled all indices with . The marks are in cells at most , so this takes at most steps.
-
Return. moves left to cell , found by , in at most steps.
-
End of the step. The state of now holds , and is true: every symbol was written, every head moved as says, and no mark is left.
Time. By step 2, simulated step number uses at most steps of . If halts after steps, the total is at most
which is because and (the start state is not halting, so takes at least one step), so that . By at the end, accepts exactly when accepts.
Known results in the model
- Fewer tapes, a log factor. A two-tape machine simulates a -tape machine that runs in time in steps (Hennie and Stearns, 1966). So the number of tapes beyond two changes the time by at most a log factor.
- One tape is slower on some tasks. Every one-tape machine that decides makes steps on some input of length (Hennie, 1965, by the crossing sequence method). The two-tape machine above takes . So the quadratic loss of the simulation cannot be removed for the one-tape model in general.
- Linear speedup. For every (Hartmanis and Stearns, 1965), a -tape machine with and time has an equivalent one with time . See the linear speedup theorem.
- Hierarchy. For time-constructible with , on multitape machines. See the time hierarchy theorem.
- Other models. A nondeterministic Turing machine changes the transition function, not the tapes. The random-access machine and the multitape machine simulate each other with a polynomial loss, as RAM and Turing machine equivalence shows.
References
- Michael Sipser, Introduction to the Theory of Computation, third edition, Section 3.2, multitape Turing machines
- Christos H. Papadimitriou, Computational Complexity, Addison-Wesley, 1994, Chapter 2, the sections on Turing machines with multiple strings and on linear speedup
- Frederick C. Hennie and Richard E. Stearns, Two-tape simulation of multitape Turing machines, Journal of the ACM, volume 13, issue 4, pp. 533 to 546
- Frederick C. Hennie, One-tape, off-line Turing machine computations, Information and Control, volume 8, issue 6, 1965, pp. 553 to 578
- Juris Hartmanis and Richard E. Stearns, On the computational complexity of algorithms, Transactions of the American Mathematical Society, volume 117, pp. 285 to 306
Where this leads
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W4 complete |
|
Tag WQP1MA Edit this page History Report an error Markdown JSON