Turing Machine

6 min read Last updated Wed Jun 10 2026 04:52:55 GMT+0000 (Coordinated Universal Time)

Most powerful abstract model of computation. Can simulate any real computer (ignoring efficiency). Modelled by Alan Turing.

A 5-tuple T=(Q,Σ,Γ,q0,δ)T = (Q, \Sigma, \Gamma, q_0, \delta).

Where:

  • QQ = finite set of states
  • Σ{ha,hr}\Sigma \supset \set{ h_a, h_r } = input alphabet
  • Γ{Λ}\Gamma \supset \set{ \Lambda } = tape alphabet
  • q0q_0 = start state
  • δ:Q×ΣQ×Γ×{L,R,S}δ: Q \times \Sigma \rightarrow Q \times \Gamma \times \set{L,R,S} = transition function

Components

Tape

Consists of infinite cells. One dimensional. Works as memory.

Cell

A component inside the tape. Can be read from or written to.

Symbol

Element that can be written on a cell. Λ\Lambda means empty.

Tape Head

Points to a cell. Reads from or writes to a cell. Can move left or right or stay at the current cell.

CPU

Has internal state (from an finite set of states). Decides whether to move the tape head, in which direction to move, whether to write on the cell, what to write on the cell. Decisions based on current symbol and current state.

State

State of the machine (or the CPU). Includes 2 halting states:

  • hah_a: Accept
  • hrh_r → Reject

Transition Function

δ(q,X)=(r,Y,D)\delta(q, X) = (r, Y, D)

It means, from state qq, reading XX:

  • Write YY
  • Move to state rr
  • Move head DL,R,SD \in {L, R, S}

Configuration

Represents the current status. (q,xay)Q×Γ(q, x\underline{a}y) \in Q \times \Gamma^*. Current symbol under tape head is underlined.

For input string xx, the machine starts at (q0,Δx)(q_0, \Delta x).

Configuration Changes

Turing machine changes from 1 configuration to another in each step. Can either move in:

  • Single step
    (q,xay)T(r,zbw)(q, x\underline{a}y) \vdash_T (r, z\underline{b}w)
  • Multiple steps
    (q,xay)T(r,zbw)(q, x\underline{a}y) \vdash_T^* (r, z\underline{b}w)

Halting

Turing machine halts when it reaches either of the halting states. May run forever without halting.

Acceptance

A string xx is accepted iff the machine reaches accepting state i.e. (q0,Δx)T(ha,yaz)(q_0, \Delta x) \vdash_T^* (h_a, y\underline{a}z).

Examples

Regular Language

L=(ab)aba(ab)L = (a|b)^*aba(a|b)^*

TM behaves like FA. Moves right only. Does not modify the tape.

Ends with “aba”

L={xx ends with aba}L = \{x \mid x \text{ ends with } aba\}

Must read entire input before accepting.

Palindromes

L=xx=xRL = {x \mid x = x^R}

Match first and last symbols. Replace them and repeat. Deterministic.

Functions

A function f:ΣΓf: \Sigma^* \rightarrow \Gamma^* is Turing-computable iff a Turing machine TT exists that computes ff.

TT computes f(x)f(x) iff (q0,Δx)T(ha,Δf(x))(q_0, \Delta x) \vdash_T^* (h_a, \Delta f(x)).

Partial Functions

When the function is undefined for certain inputs.

TM will produce output only for valid inputs. Loop indefinitely otherwise.

Characteristic Function

For any language LL in Σ\Sigma^*, its characteristic function χL:Σ{0,1}\chi_L: \Sigma^* \rightarrow \set{0,1} is defined as:

χL(x)={1 if xL0otherwise\chi_L(x) = \begin{cases} 1 \quad \text{ if } x \in L &\\ 0 \quad \text{otherwise} \end{cases}

Computing χL\chi_L is the same as accepting a language.

A Turing machine may distinguish between strings that are in LL and not in LL by either:

  • accepting or rejecting the string OR
  • accepting and ending up in either (ha,Δ0)(h_a,\Delta 0) or (ha,Δ1)(h_a, \Delta 1) configuration

Combination

Suppose T1T_1 and T2T_2 are 2 Turing machines with disjoint non-halting states and transition functions.

T1T2T_1T_2 denotes a new Turing machine that is a combination of the 2. It starts with the initial state of T1T_1 and executes T1T_1 first. For any move that halts in an accepting state of T1T_1, the machine moves to the initial state of T2T_2 and execute T2T_2. Can also be denoted as T1T2T_1 \rightarrow T_2.

If either T1T_1 or T2T_2 rejects, T1T2T_1T_2 also rejects.

Variations

Many minor variations can be defined such as:

  • A Turing machine that must move unidirectionally.
  • A Turing machine that can either write a symbol or move but not both.
  • A Turing machine with multiple tapes and multiple tape heads.
    However the ultimate computing power is unchanged.

n-tape Turing Machine

A Turing machine with multiple tapes. Each tape has its own tape head.

An nn-tape Turing machine is a 6-tuple M=(Q,Σ,Γ,δ,q0,F)M = (Q, \Sigma, \Gamma, \delta, q_0, F) where:

  • QQ: finite set of states
  • Σ\Sigma: input alphabet
  • Γ\Gamma: tape alphabet (ΣΓ\Sigma \subseteq \Gamma)
  • q0q_0: initial state
  • FF: set of accepting states
  • δ:Q×ΓnQ×Γn×{L,R,S}n\delta: Q \times \Gamma^n \rightarrow Q \times \Gamma^n \times \{L, R, S\}^n: transition function

The machine reads nn symbols (one from each tape). Based on the current state and these symbols:

  • It moves to a new state
  • Writes nn symbols (one on each tape)
  • Moves each tape head independently (Left, Right, or Stay)

Non-deterministic TM

Aka. NTM. Same as the deterministic TM except the transition function’s output is a set of configurations.

For any non-deterministic TM, there exists a deterministic TM that accept the same language.

Encoding

A TM can be represented as a finite string over a finite alphabet. This encoding, written T\langle T \rangle or e(T)e(T), describes the TM’s states, alphabets, and transition function.

Encoding is what allows a TM to take another TM as input. Without it, a TM cannot reason about other TMs.

Example

TM TT accepts {a}\{a\}: states q0,q1,ha,hrq_0, q_1, h_a, h_r; transitions δ(q0,a)=(q1,a,R)\delta(q_0, a) = (q_1, a, R) and δ(q1,Λ)=(ha,Λ,S)\delta(q_1, \Lambda) = (h_a, \Lambda, S).

Each transition is encoded as a 5-tuple (q,X,r,Y,D)(q,\, X,\, r,\, Y,\, D). Tuples are separated by #:

T=q0,a,q1,a,R#q1,B,ha,B,S\langle T \rangle = \texttt{q0,a,q1,a,R\#q1,B,ha,B,S}

States, symbols, and directions are replaced with agreed-upon tokens. The exact scheme is arbitrary as long as it is consistent and decodable.

Universal TM

Denoted by TuT_u A Turing machine that can run any arbitrary program with an arbitrary data set (input to the program).

  • The program is expressed as a string that specifies another special purpose TM, T1T_1
  • Data set is a string ww (input to T1T_1)

TuT_u simulates the processing of ww by T1T_1.

Accept vs Decide

A language LL is Turing-acceptable iff a Turing machine TT exists that accepts LL.

TT accepts LL iff TT halts in hah_a for every xLx \in L. For xLx \notin L, TT may:

  • Halt at hrh_r OR
  • Loop forever

A language LL is Turing-decidable iff a Turing machine TT exists that decides LL.

TT decides LL iff for every xΣx \in \Sigma^*, TT halts and computes χL(x)\chi_L(x).

T decides L    T accepts LT\text{ decides }L \implies T\text{ accepts }L

Limits

Not all problems are solvable. Some problems are undecidable — no Turing machine can solve them.

Was this helpful?