Top Banner Ad

BCS402 — Unit 5: Turing Machines and Recursive Function Theory

Table of Contents (18 sections)

BCS402 · Theory of Automata and Formal Languages · Unit 5

Turing Machines and Recursive Function Theory

Unit Scope & Exam Weightage: This unit covers the basic TM model and representation, language acceptability, techniques for TM construction, TM modifications (multi-tape, nondeterministic), TM as a computer of integer functions, Universal Turing Machine, Linear Bounded Automata, Church's thesis, recursive and recursively enumerable languages, halting problem, Post's Correspondence Problem, and recursive function theory. Expect 7-mark machine constructions with instantaneous descriptions (IDs) and 2-mark definitions.


Importance-Wise Roadmap (BCS402 Unit 5)

Priority Exact Syllabus Topic PYQ Evidence Marks Pattern Tag
1 TM construction with IDs (even length, a²ⁿbⁿ, aⁿbⁿ, ww) 2023-24, 2024-25, 2025-26 7m × 3 + 2m Must show IDs
2 UTM, integer functions f(n)=n+1, f(n)=2n 2024-25, 2025-26 7m × 2 Design + simulate
3 Post Correspondence Problem + undecidability 2024-25, 2025-26 7m × 2 Proof idea
4 DTM vs NDTM, multi-tape TM 2023-24 7m + 2m Comparison
5 Recursive / RE languages, halting problem 2023-24 7m Decidability
6 LBA, Church's thesis, recursive function theory 2025-26, 2023-24 2m + integrated 7m Short theory

TM-specific examiner guidance: Write the transition as δ(q,X)=(p,Y,D)\delta(q,X)=(p,Y,D) with D ∈ {L,R,S}, then give the ID chain for one accepted string. Marks are awarded for each correctly justified ID step, not for a prose description of the algorithm.


1. The Turing Machine Model

Turing Machine (TM): a 7-tuple M=(Q,Σ,Γ,δ,q0,B,F)M=(Q,\Sigma,\Gamma,\delta,q_0,B,F) where QQ = finite states, Σ\Sigma = input alphabet, Γ\Gamma = tape alphabet (Σ⊂Γ\Sigma\subset\Gamma), B∈ΓB\in\Gamma = blank, q0q_0 = start state, FF = final/halting states, and δ:Q×Γ→Q×Γ×{L,R,S}\delta:Q\times\Gamma\rightarrow Q\times\Gamma\times\{L,R,S\} (partial for deterministic TMs).

Representation: an infinite tape divided into cells, a read/write head, and a finite control. An instantaneous description is u q vu\,q\,v: the tape content is uvuv, the head scans the first symbol of vv, and the current state is qq.

Move ID transition
δ(q,X)=(p,Y,R)\delta(q,X)=(p,Y,R) uqXv⊢uYpvuqXv \vdash uYpv
δ(q,X)=(p,Y,L)\delta(q,X)=(p,Y,L) uXqvuXqv (head on X) moves left: qq moves before the preceding symbol
δ(q,X)=(p,Y,S)\delta(q,X)=(p,Y,S) write Y, stay: uqXv⊢uYpvuqXv\vdash uYpv

Acceptability: MM accepts ww if starting from ID q0wq_0w it reaches a final state; L(M)={w∣M accepts w}L(M)=\{w\mid M \text{ accepts } w\}. A TM may also compute a function: the tape initially holds the encoded input, and the final tape holds the encoded output.


2. Construction Techniques — Solved PYQs

2.1 TM for L={02n∣n≥0}L=\{0^{2n}\mid n\ge0\}

PYQ (2025-26, 7 marks): "Design a Turing machine that accepts L={0^{2n} | n≥0}."

Idea: toggle state on every 0; accept at the first blank only if the count is even (state q0q_0).

Present state Read 0 Read B
q0q_0 (even so far) (q1,0,R)(q_1,0,R) (qacc,B,R)(q_{acc},B,R)
q1q_1 (odd so far) (q0,0,R)(q_0,0,R) (qrej,B,R)(q_{rej},B,R)

IDs for 0000: q00000⊢0q1000⊢00q000⊢000q10⊢0000q0B⊢0000Bqaccq_00000 \vdash 0q_1000 \vdash 00q_000 \vdash 000q_10 \vdash 0000q_0B \vdash 0000Bq_{acc} ✔ IDs for 000: q0000⊢0q100⊢00q00⊢000q1B⊢000Bqrejq_0000\vdash0q_100\vdash00q_00\vdash000q_1B\vdash000Bq_{rej} ✘ For n=0n=0 (empty input) the machine starts at BB in q0q_0 → accept, so ε ∈ L.

2.2 TM for L={a2nbn∣n≥1}L=\{a^{2n}b^n\mid n\ge1\}

PYQ (2023-24, 7 marks): "Construct TM that accepts L={a^{2n} b^n | n≥1}. Also show the instantaneous description for w=aaaabb."

Strategy: for every two as, mark one b. Use X for consumed as, Y for consumed bs.

State Read a Read b Read X Read Y Read B
qsq_s (start) (q1,X,R)(q_1,X,R) — — — reject
q0q_0 (loop head) (q1,X,R)(q_1,X,R) (q4,b,R)(q_4,b,R) (q0,X,R)(q_0,X,R) (q0,Y,R)(q_0,Y,R) (q4,B,R)(q_4,B,R)
q1q_1 (want 2nd a) (q2,X,R)(q_2,X,R) reject (q1,X,R)(q_1,X,R) (q1,Y,R)(q_1,Y,R) reject
q2q_2 (find a b) (q2,a,R)(q_2,a,R) (q3,Y,L)(q_3,Y,L) (q2,X,R)(q_2,X,R) (q2,Y,R)(q_2,Y,R) reject
q3q_3 (return left) (q3,a,L)(q_3,a,L) (q3,b,L)(q_3,b,L) (q3,X,L)(q_3,X,L) (q3,Y,L)(q_3,Y,L) (q0,B,R)(q_0,B,R)
q4q_4 (verify) reject reject (q4,X,R)(q_4,X,R) (q4,Y,R)(q_4,Y,R) accept

ID sequence for aaaabb (n=2):

q_s a a a a b b
X q_1 a a a b b
X X q_2 a a b b
X X a q_3 a Y b          (first b marked as Y, head moves left)
q_3 B X X a a Y b        (walk left to blank)
B q_0 X X a a Y b        (turn around, head at pos 1)
B X X q_0 a a Y b        (skip X X)
B X X X q_1 a Y b        (mark 3rd a)
B X X X X q_2 Y b        (mark 4th a, hunt for b)
B X X X X Y q_2 b
B X X X X q_3 Y Y        (mark 2nd b as Y)
B q_0 X X X X Y Y        (return to left edge)
B X X X X Y Y q_4 B      (verification: only X/Y remain)
B X X X X Y Y B q_acc    ✔ accepted

Odd a counts fail in q1q_1 when a b appears before the second a; extra bs fail in q4q_4.

2.3 TM for L={anbn∣n≥1}L=\{a^nb^n\mid n\ge1\}

PYQ (2024-25, 2 marks): "Design a Turing Machine to accept the language L={a^n b^n | n≥1}."

State a b X Y B
q0q_0 (q1,X,R)(q_1,X,R) reject (q0,X,R)(q_0,X,R) (q0,Y,R)(q_0,Y,R) accept (n=0 only; guard with qsq_s as before)
q1q_1 (find matching b) (q1,a,R)(q_1,a,R) (q2,Y,L)(q_2,Y,L) (q1,X,R)(q_1,X,R) (q1,Y,R)(q_1,Y,R) reject
q2q_2 (return) (q2,a,L)(q_2,a,L) (q2,b,L)(q_2,b,L) (q0,X,R)(q_0,X,R) when reading B after left walk (q2,Y,L)(q_2,Y,L) (q0,B,R)(q_0,B,R)

In words: mark the leftmost unmarked a as X, travel right to the leftmost unmarked b, mark it Y, return left; repeat. Accept when, after marking, the scan sees only X/Y before the blank. Trace aabb: q0aabb⊢Xq1abb⊢Xaq1bb⊢Xaq2Yb⊢Xq2aYb⊢q2XaYb⊢q0BXaYb⊢Bq0XaYb⊢BXq0aYb⊢BXXq1Yb⊢BXXYq1b⊢BXXq2YY⊢Bq0XXYY⊢BXXYYqaccq_0aabb\vdash Xq_1abb\vdash Xaq_1bb\vdash Xaq_2Yb\vdash Xq_2aYb\vdash q_2XaYb\vdash q_0BXaYb\vdash Bq_0XaYb\vdash BXq_0aYb\vdash BXXq_1Yb\vdash BXXYq_1b\vdash BXXq_2YY\vdash Bq_0XXYY\vdash BXXYYq_{acc} ✔.

2.4 TM for L={ww∣w∈(a+b)∗}L=\{ww\mid w\in(a+b)^*\}

PYQ (2023-24, 7 marks): "Differentiate between Deterministic Turing machine and Non-Deterministic Turing machine. Design a Turing machine for the language L={ww | w∈(a+b)*}."

Feature DTM NDTM
Transitions At most one per (q,X)(q,X) Several possible next moves
Computation Single path Computation tree; accepts if any branch accepts
Power Same language class (RE) Same power; may be exponentially faster
Simulation — DTM can simulate NDTM breadth-first

NDTM construction for ww: nondeterministically guess the midpoint, then compare symbols symmetrically.

q0: read first unmarked symbol, replace by X, remember it in state qa / qb,
    move right until guessing the midpoint (nondeterministic epsilon-style choice
    implemented as two transitions at each cell: continue or switch to qmid).
qmid: verify the symbol here matches the remembered one:
      (qa, a) -> (qback, X, R)   ; (qb, b) -> (qback, X, R)
qback: move right to next unmarked cell, then return to q0 to mark the next
       symbol of the first half; accept when both halves are fully marked.

For abab, choose the midpoint after two symbols: mark first a as X, compare it with the a at position 3, then mark first b as X and compare with position 4 → accept. For abba, no midpoint choice matches both pairs → reject. The guessing step is what makes this construction nondeterministic; it cannot be done by a DTM without trying all midpoints.

2.5 TM as a Computer of Integer Functions

PYQ (2024-25, 7 marks): "Design a Turing Machine to compute the function f(n)=n+1 where n is a unary number (n=3 → '111')."

Unary representation: nn is a string of nn ones.

State Read 1 Read B
q0q_0 (q0,1,R)(q_0,1,R) (qhalt,1,S)(q_{halt},1,S)

Computation: q0111⊢1q011⊢11q01⊢111q0B⊢1111qhaltq_0111\vdash1q_011\vdash11q_01\vdash111q_0B\vdash1111q_{halt}. Output 1111 = 4 ✔.

PYQ (2025-26, 7 marks): "Explain the concept of Universal Turing Machine. Construct a Turing Machine that computes f(n)=2n for unary input."

State Action
q0q_0 Scan right over 1s; at first X skip it; at first B go to qappendq_{append}
qappendq_{append} Write 11 at the right end (two steps), then go to qreturnq_{return}
qreturnq_{return} Move left over 1s to the leftmost unmarked 1, mark it X, return to q0q_0
qcleanq_{clean} When no unmarked 1 remains, move left changing every X back to 1, halt

Trace for n=2 (11): q011⊢1q01⊢11q0B⊢11 1qappendB⊢111 1qappendB⊢qreturn1111q_011\vdash 1q_01\vdash 11q_0B\vdash 11\,1q_{append}B\vdash 111\,1q_{append}B\vdash q_{return}1111 (after moving left) → mark first 1 as X → repeat → two appended ones per original symbol → tape 1111 (4 ones) after cleanup. General invariant: each pass replaces one original 1 by X and appends two new ones, so final count is 2n2n.


3. Universal TM, LBA and Undecidability

3.1 Universal Turing Machine (UTM)

Universal Turing Machine: a single fixed TM UU that takes as input an encoding ⟨M,w⟩\langle M,w\rangle of any TM MM and string ww, and simulates MM's computation on ww step by step. If MM halts/accepts, so does UU. It stores MM's transition table and current state/head position on its own tape.

How it simulates: (1) decode ⟨M,w⟩\langle M,w\rangle into separate tape tracks — description, tape contents, state, head position; (2) look up the transition matching current state/scanned symbol; (3) update the simulated tape, state and head; (4) repeat until a halting state is reached. Existence of UU shows a general-purpose computer is possible; it also underpins the halting-problem proof: if no TM can decide whether an arbitrary ⟨M,w⟩\langle M,w\rangle halts, then no program can do so either.

3.2 Linear Bounded Automaton

PYQ (2025-26, 2 marks): "What is a Linear Bounded Automaton (LBA)?" An LBA is a nondeterministic TM whose head may not move outside the portion of tape occupied by the input (end markers delimit it). Space is therefore O(∣w∣)O(|w|), and LBAs accept exactly the context-sensitive languages (Type 1).

3.3 Recursive vs. Recursively Enumerable

PYQ (2023-24, 7 marks): "Explain any two of the following: i. UTM ii. Post Correspondence Problem iii. Recursive and recursively Enumerable Languages."

Class Machine behaviour Closure Example
Recursive (decidable) TM halts with yes/no for every input Closed under complement, union, intersection {anbn}\{a^nb^n\}
Recursively enumerable (semi-decidable) TM halts and accepts members; may loop forever on non-members Closed under union, intersection; not complement Halting set H={⟨M,w⟩∣M halts on w}H=\{\langle M,w\rangle\mid M \text{ halts on } w\}
Not RE No TM can even list all members — Complement of the halting set

Theorem: a language is recursive iff both it and its complement are RE.

Halting problem: suppose TM HH decides whether any ⟨M,w⟩\langle M,w\rangle halts. Build DD that on ⟨M⟩\langle M\rangle calls H(⟨M,⟨M⟩⟩)H(\langle M,\langle M\rangle\rangle) and does the opposite (loop if HH says halt, halt if HH says loop). Running DD on its own description gives a contradiction. Hence the halting problem is undecidable.

3.4 Post's Correspondence Problem

PYQ (2025-26, 7 marks): "Define the Post Correspondence Problem (PCP). Why is it considered undecidable?" PYQ (2024-25, 7 marks): "Discuss Post's Correspondence Problem (PCP) with an example showing undecidability."

PCP: Given nn dominoes (tiles) (u1,v1),…,(un,vn)(u_1,v_1),\dots,(u_n,v_n) of nonempty strings over an alphabet, decide whether there is a nonempty sequence of indices i1,i2,…,iki_1,i_2,\dots,i_k such that ui1ui2…uik=vi1vi2…viku_{i_1}u_{i_2}\dots u_{i_k}=v_{i_1}v_{i_2}\dots v_{i_k}. The common string is called a match.

Solvable example: tiles A=(a,ab)A=(\texttt{a},\texttt{ab}) and B=(ba,a)B=(\texttt{ba},\texttt{a}). Sequence A,BA,B gives top a ba=aba\texttt{a\,ba}=\texttt{aba} and bottom ab a=aba\texttt{ab\,a}=\texttt{aba} — a match.

Why undecidable: the halting problem reduces to PCP. From a TM MM and input ww, construct tiles that force any match to spell out the sequence of instantaneous descriptions of MM's computation starting at q0wq_0w; the first and last tiles anchor the start and a halting configuration. A PCP solution exists iff MM eventually halts. Since halting is undecidable, no algorithm can decide arbitrary PCP instances.

3.5 Modifications of Turing Machines

PYQ (2023-24, 2 marks): "Explain Multi Tape Turing Machine." A TM with kk tapes and kk independent heads; each transition reads all scanned symbols and writes/moves each head separately. It is equivalent in power to a single-tape TM (simulate kk tracks on one tape with markers), but can be faster (e.g., copying a string in O(n)O(n) instead of O(n2)O(n^2)).

Other equivalent modifications: two-way infinite tape, stay-put moves, multiple final states, nondeterminism — none changes the class of accepted languages (RE).

3.6 Church's Thesis and Recursive Function Theory

Church's thesis (Church–Turing thesis): Every effectively computable function on natural numbers is computable by a Turing machine (equivalently, is a partial recursive function, or is computable in λ-calculus). It is a thesis, not a theorem, because "effectively computable" is informal.

Recursive function theory (intro):

  • Base functions: zero Z(x)=0Z(x)=0, successor S(x)=x+1S(x)=x+1, projection Uin(x1,…,xn)=xiU_i^n(x_1,\dots,x_n)=x_i.
  • Closure operations: composition, primitive recursion, and minimisation (μ-operator).
  • Primitive recursive functions use only the first two closures (e.g., addition, multiplication, factorial, predecessor). Total recursive functions may also use bounded/unbounded μ; the Ackermann function is total recursive but not primitive recursive, showing the distinction is strict.

4. Exam-Ready Question Index and Practice

Question (source) Solution location
TM for 02n0^{2n} (2025-26, 7m) §2.1 with ID trace
TM for a2nbna^{2n}b^n + IDs for aaaabb (2023-24, 7m) §2.2
TM for anbna^nb^n (2024-25, 2m) §2.3
DTM vs NDTM + TM for ww (2023-24, 7m) §2.4
f(n)=n+1 (2024-25, 7m) §2.5
UTM + f(n)=2n (2025-26, 7m) §2.5 + §3.1
PCP definition/undecidability (2025-26, 7m) §3.4
PCP example (2024-25, 7m) §3.4
Multi-tape TM (2023-24, 2m) §3.5
Recursive/RE/UTM (2023-24, 7m) §3.1, §3.3
LBA (2025-26, 2m) §3.2

Practice questions (label: practice, not real PYQs)

  1. Practice: Design a TM that accepts strings with equal numbers of 0 and 1 in any order.
  2. Practice: Write the ID sequence of the 02n0^{2n} TM on 00000 and show rejection.
  3. Practice: Explain with a tile example why a PCP instance with solution length 1 is trivial, yet no general algorithm exists.
  4. Practice: Show how a 2-tape TM copies a string in linear time.
  5. Practice: Prove that the complement of a recursive language is recursive.

5. Last-Night Survival Checklist (Unit 5 only)

  1. Transition notation: δ(q,X)=(p,Y,L/R/S)\delta(q,X)=(p,Y,L/R/S); state the tape alphabet and blank before writing tables.
  2. Four ID chains to memorise: even zeros; aaaabb; aabb; 111 → 1111.
  3. Design patterns: toggle states for parity, X/Y markers for counting, append-at-blank for integer functions.
  4. Undecidability links: halting ↔ PCP via ID-sequence tiles; UTM encodes ⟨M,w⟩; RE languages may loop.
  5. Quick definitions: LBA = space-bounded TM for CSL; Church = TM-computable = effectively computable; recursive = halts on everything.

Final TM reminder: In every construction answer, justify why the machine rejects a wrong string (leftover marker, wrong parity, unmatched symbol). The rejection explanation along with one ID chain is what distinguishes a complete 7-mark answer from a partial one.