Algorithm Search⌘K

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 kk tapes, each with its own head, and one finite control that reads the kk 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 kk-tape machine MM, for a fixed k≥1k \ge 1, has these parts:

  • a finite set QQ of states, with a start state q0q_0 and two halting states, accept and reject;
  • a finite tape alphabet Γ\Gamma that contains a blank symbol ⊔\sqcup, and an input alphabet Σ⊆Γ∖{⊔}\Sigma \subseteq \Gamma \setminus \{\sqcup\};
  • a transition function δ:(Q∖{accept,reject})×Γk→Q×Γk×{L,R,S}k\delta : (Q \setminus \{\text{accept}, \text{reject}\}) \times \Gamma^k \to Q \times \Gamma^k \times \{L, R, S\}^k.

Each tape has cells numbered 0,1,2,…0, 1, 2, \ldots and is infinite to the right. At the start, the input w∈Σ∗w \in \Sigma^* is in cells 00 to ∣w∣−1|w|-1 of tape 1. All other cells hold the blank, and all kk heads are on cell 00. A step works like this. The machine is in state qq, and head ii reads the symbol aia_i. If δ(q,a1,…,ak)=(p,b1,…,bk,D1,…,Dk)\delta(q, a_1, \ldots, a_k) = (p, b_1, \ldots, b_k, D_1, \ldots, D_k), then for every ii at the same time the machine writes bib_i on tape ii and moves head ii by DiD_i, and it enters state pp. The move SS keeps the head in place. A head on cell 00 with the move LL also stays, as in the one-tape machine. The language L(M)L(M), 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 t(n)≥nt(n) \ge n. The first has a read-only input tape and a write-only output tape, with k−2k-2 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 PAL={w∈{0,1}∗:w=wR}\mathrm{PAL} = \{ w \in \{0,1\}^* : w = w^R \}, where wRw^R is ww written backwards. The two-tape machine below decides PAL\mathrm{PAL}. It first copies ww 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 00 when the comparison ends, and the machine uses the left-end rule to stay there. The table lists the rules. Here a,x∈{0,1}a, x \in \{0, 1\}, and a pair that the table does not list goes to reject.

State Reads Writes Moves Next state
ss (⊔,⊔)(\sqcup, \sqcup) (⊔,⊔)(\sqcup, \sqcup) (S,S)(S, S) accept
ss (a,⊔)(a, \sqcup) (a,$)(a, \$) (S,R)(S, R) cc
cc (a,⊔)(a, \sqcup) (a,a)(a, a) (R,R)(R, R) cc
cc (⊔,⊔)(\sqcup, \sqcup) (⊔,⊔)(\sqcup, \sqcup) (S,L)(S, L) bb
bb (⊔,x)(\sqcup, x) (⊔,x)(\sqcup, x) (S,L)(S, L) bb
bb (⊔,$)(\sqcup, \$) (⊔,$)(\sqcup, \$) (L,R)(L, R) dd
dd (a,a)(a, a) (a,a)(a, a) (L,R)(L, R) dd
dd (a,⊔)(a, \sqcup) (a,⊔)(a, \sqcup) (S,S)(S, S) accept

In state dd, the pair (a,x)(a, x) with a≠xa \ne x has no rule, so the machine rejects. After jj comparisons, head 2 is on cell j+1j + 1 of tape 2, so it reads a blank exactly when j=nj = n. At that time head 1 is on cell 00, which holds a symbol of {0,1}\{0,1\}. So the rule (a,⊔)(a, \sqcup) of state dd fires after all nn pairs matched. On a palindrome of length n≥1n \ge 1 the machine makes 3n+43n + 4 steps, for example 77 steps on 00, 1010 steps on 1111 and 1616 steps on 01100110. On the empty word it makes 11 step. On a word of length nn it makes at most 3n+43n + 4 steps. So PAL\mathrm{PAL} is decided in time O(n)O(n) with two tapes.

What it counts

The time of MM on an input ww is the number of steps before it halts, and one step costs one unit, whatever kk is. The worst-case time T(n)T(n) is the largest time over the inputs of length nn.

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 nn. Without that tape, the input cells that a head visits count.

A time class such as DTIME(f(n))\mathrm{DTIME}(f(n)) is the set of languages decided in time O(f(n))O(f(n)) by a kk-tape machine for some kk. 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 DTIME(n)\mathrm{DTIME}(n). The choice of kk matters for the exact class: PAL∈DTIME(n)\mathrm{PAL} \in \mathrm{DTIME}(n) 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 kk-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 MM be a deterministic kk-tape machine that decides LL and halts in at most t(n)≥nt(n) \ge n steps on every input of length nn. Then a one-tape machine SS decides LL in O(t(n)2)O(t(n)^2) steps, where the constant depends only on kk.

Construction. The tape of SS has the cells 0,1,2,…0, 1, 2, \ldots, and cell jj holds one symbol of a finite alphabet Γ′\Gamma'. The symbol records, for each tape ii of MM:

  • the symbol ci∈Γc_i \in \Gamma in cell jj of tape ii, and
  • a flag fi∈{0,H,R′}f_i \in \{0, H, R'\}. The flag HH means that head ii of MM is on cell jj. The flag R′R' is a temporary mark that is used inside one simulated step. The flag 00 means neither.

It also records a bit ee that is 11 exactly in cell 00. The blank of SS is the symbol with ci=⊔c_i = \sqcup, fi=0f_i = 0 and e=0e = 0 for all ii. The state of SS holds the state of MM and a bounded amount of other data (at most the kk symbols read, a set of indices, and a phase name).

Invariant IsI_s. After ss simulated steps, SS is in cell 00 in a state that holds the state of MM, and the flags HH and the symbols cic_i in the tape of SS describe the configuration of MM after ss steps. No flag R′R' is present.

Steps.

  1. Start (phase 0). SS reads the input ww from left to right. In cell 00 it always writes e=1e = 1 and fi=Hf_i = H for all ii, with c1=w1c_1 = w_1 if n≥1n \ge 1 and c1=⊔c_1 = \sqcup if n=0n = 0. In cell jj with 1≤j<n1 \le j < n it writes c1=wj+1c_1 = w_{j+1}, fi=0f_i = 0 and e=0e = 0. In all cells ci=⊔c_i = \sqcup for i≥2i \ge 2. If n=0n = 0 it stays on cell 00 and this phase ends after one step. Otherwise it stops at the first blank, which is in cell nn, and moves left to cell 00, which it finds by the bit ee. This takes at most 2n+22n + 2 steps and makes I0I_0 true.

  2. Scan right (phase 1). Assume IsI_s with MM in a non-halting state qq. SS moves right from cell 00. On each cell it reads, for every ii with fi=Hf_i = H, the symbol cic_i and stores it. It stops when it has seen kk flags. Let P=max⁡ipiP = \max_i p_i, where pip_i is the cell of head ii. The step that reads cell PP completes the list, so this phase takes at most P+1P + 1 steps. Each head moves at most one cell in a step of MM, and starts on cell 00, so P≤sP \le s.

  3. Decide. In the step that reads cell PP, SS knows qq and the scanned symbols a1,…,aka_1, \ldots, a_k. Its finite control computes δ(q,a1,…,ak)=(q′,b1,…,bk,D1,…,Dk)\delta(q, a_1, \ldots, a_k) = (q', b_1, \ldots, b_k, D_1, \ldots, D_k). If q′q' is accept or reject, SS halts in the same way, and the claim is true for this input by IsI_s.

  4. Scan left (phase 2). The step that reads cell PP also starts this phase. SS moves left from cell PP to cell 00, which it detects by e=1e = 1, and it stays there by the rule for cell 00. In each cell, and for each ii with fi=Hf_i = H, it writes bib_i in place of cic_i, and it changes the flag fif_i by the move DiD_i:

    • if Di=SD_i = S, the flag stays HH;
    • if Di=RD_i = R, the flag becomes R′R';
    • if Di=LD_i = L and e=0e = 0, the flag becomes 00, and the state records that the next cell to the left (cell j−1j - 1) gets the flag HH for tape ii;
    • if Di=LD_i = L and e=1e = 1, the flag stays HH, by the rule for cell 00.

    When SS writes cell j−1j - 1, it also sets the flags HH 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 P+1P + 1 steps.

  5. Scan right for the marks (phase 3). If no DiD_i is RR, skip to step 7. Else SS moves right from cell 00. At a cell with a flag R′R' it sets that flag to 00, and it sets the flag HH 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 ii with Di=RD_i = R. The marks are in cells at most PP, so this takes at most P+2P + 2 steps.

  6. Return. SS moves left to cell 00, found by e=1e = 1, in at most P+2P + 2 steps.

  7. End of the step. The state of SS now holds q′q', and Is+1I_{s+1} is true: every symbol was written, every head moved as DiD_i says, and no mark R′R' is left.

Time. By step 2, simulated step number s+1s + 1 uses at most 4(s+2)4(s + 2) steps of SS. If MM halts after t′≤t(n)t' \le t(n) steps, the total is at most

(2n+2)+∑s=0t′−14(s+2)=(2n+2)+2t′(t′−1)+8t′=2t′2+6t′+2n+2,(2n + 2) + \sum_{s=0}^{t'-1} 4(s+2) = (2n + 2) + 2t'(t'-1) + 8t' = 2t'^2 + 6t' + 2n + 2,

which is O(t(n)2)O(t(n)^2) because t(n)≥nt(n) \ge n and t(n)≥1t(n) \ge 1 (the start state is not halting, so MM takes at least one step), so that 2n+2≤4t(n)2n + 2 \le 4t(n). By IsI_s at the end, SS accepts exactly when MM accepts. ■\blacksquare

Known results in the model

  • Fewer tapes, a log factor. A two-tape machine simulates a kk-tape machine that runs in time t(n)t(n) in O(t(n)log⁡t(n))O(t(n) \log t(n)) 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 PAL\mathrm{PAL} makes Ω(n2)\Omega(n^2) steps on some input of length nn (Hennie, 1965, by the crossing sequence method). The two-tape machine above takes O(n)O(n). So the quadratic loss of the simulation cannot be removed for the one-tape model in general.
  • Linear speedup. For every ε>0\varepsilon > 0 (Hartmanis and Stearns, 1965), a kk-tape machine with k≥2k \ge 2 and time t(n)t(n) has an equivalent one with time εt(n)+n+2\varepsilon t(n) + n + 2. See the linear speedup theorem.
  • Hierarchy. For time-constructible f,gf, g with f(n)log⁡f(n)=o(g(n))f(n) \log f(n) = o(g(n)), DTIME(f)⊊DTIME(g)\mathrm{DTIME}(f) \subsetneq \mathrm{DTIME}(g) 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

  1. Michael Sipser, Introduction to the Theory of Computation, third edition, Section 3.2, multitape Turing machines
  2. Christos H. Papadimitriou, Computational Complexity, Addison-Wesley, 1994, Chapter 2, the sections on Turing machines with multiple strings and on linear speedup
  3. 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
  4. Frederick C. Hennie, One-tape, off-line Turing machine computations, Information and Control, volume 8, issue 6, 1965, pp. 553 to 578
  5. 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.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW4 complete
  • a review of the text: no review record reviews/WQP1MA/text.yaml