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 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 where = finite states, = input alphabet, = tape alphabet (), = blank, = start state, = final/halting states, and (partial for deterministic TMs).
Representation: an infinite tape divided into cells, a read/write head, and a finite control. An instantaneous description is : the tape content is , the head scans the first symbol of , and the current state is .
| Move | ID transition |
|---|---|
| (head on X) moves left: moves before the preceding symbol | |
| write Y, stay: |
Acceptability: accepts if starting from ID it reaches a final state; . 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
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 ).
| Present state | Read 0 | Read B |
|---|---|---|
| (even so far) | ||
| (odd so far) |
IDs for 0000:
✔
IDs for 000: ✘
For (empty input) the machine starts at in → accept, so ε ∈ L.
2.2 TM for
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 |
|---|---|---|---|---|---|
| (start) | — | — | — | reject | |
| (loop head) | |||||
| (want 2nd a) | reject | reject | |||
| (find a b) | reject | ||||
| (return left) | |||||
| (verify) | reject | reject | 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 when a b appears before the second a; extra bs fail in .
2.3 TM for
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 |
|---|---|---|---|---|---|
| reject | accept (n=0 only; guard with as before) | ||||
| (find matching b) | reject | ||||
| (return) | when reading B after left walk |
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: ✔.
2.4 TM for
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 | 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: is a string of ones.
| State | Read 1 | Read B |
|---|---|---|
Computation: . 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 |
|---|---|
| Scan right over 1s; at first X skip it; at first B go to | |
Write 11 at the right end (two steps), then go to |
|
Move left over 1s to the leftmost unmarked 1, mark it X, return to |
|
When no unmarked 1 remains, move left changing every X back to 1, halt |
Trace for n=2 (11):
(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 .
3. Universal TM, LBA and Undecidability
3.1 Universal Turing Machine (UTM)
Universal Turing Machine: a single fixed TM that takes as input an encoding of any TM and string , and simulates 's computation on step by step. If halts/accepts, so does . It stores 's transition table and current state/head position on its own tape.
How it simulates: (1) decode 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 shows a general-purpose computer is possible; it also underpins the halting-problem proof: if no TM can decide whether an arbitrary 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 , 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 | |
| Recursively enumerable (semi-decidable) | TM halts and accepts members; may loop forever on non-members | Closed under union, intersection; not complement | Halting set |
| 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 decides whether any halts. Build that on calls and does the opposite (loop if says halt, halt if says loop). Running 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 dominoes (tiles) of nonempty strings over an alphabet, decide whether there is a nonempty sequence of indices such that . The common string is called a match.
Solvable example: tiles and . Sequence gives top and bottom — a match.
Why undecidable: the halting problem reduces to PCP. From a TM and input , construct tiles that force any match to spell out the sequence of instantaneous descriptions of 's computation starting at ; the first and last tiles anchor the start and a halting configuration. A PCP solution exists iff 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 tapes and 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 tracks on one tape with markers), but can be faster (e.g., copying a string in instead of ).
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 , successor , projection .
- 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 (2025-26, 7m) | §2.1 with ID trace |
TM for + IDs for aaaabb (2023-24, 7m) |
§2.2 |
| TM for (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)
- Practice: Design a TM that accepts strings with equal numbers of
0and1in any order. - Practice: Write the ID sequence of the TM on
00000and show rejection. - Practice: Explain with a tile example why a PCP instance with solution length 1 is trivial, yet no general algorithm exists.
- Practice: Show how a 2-tape TM copies a string in linear time.
- Practice: Prove that the complement of a recursive language is recursive.
5. Last-Night Survival Checklist (Unit 5 only)
- Transition notation: ; state the tape alphabet and blank before writing tables.
- Four ID chains to memorise: even zeros;
aaaabb;aabb;111 → 1111. - Design patterns: toggle states for parity, X/Y markers for counting, append-at-blank for integer functions.
- Undecidability links: halting ↔ PCP via ID-sequence tiles; UTM encodes ⟨M,w⟩; RE languages may loop.
- 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.