Skip to content
GATEiit

GATE CSE · Theory of Computation

Turing machines and undecidability

Turing machines and their variants, recursive and recursively enumerable languages and their closure, the halting problem, reductions and Rice's theorem, and the table of decidable and undecidable problems that GATE tests.

Before you start

Concept notes

1. Turing machines and their variants

A Turing machine (TM) has a finite control and an infinite tape with a read/write head. Formally M=(Q,Σ,Γ,δ,q0,⊔,F) where Γ⊇Σ∪{⊔} is the tape alphabet and ⊔ is the blank. A move δ(q,X)=(p,Y,D) writes Y over X, moves the head one cell left or right (D∈{L,R}) and enters state p.

On an input a TM can accept (enter an accepting state and halt), reject (halt without accepting), or loop (never halt). This third outcome is what makes undecidability possible.

Equivalent models. These all accept exactly the same languages as the basic TM:

  • multi-tape TM (simulated on one tape with at most quadratic slowdown),
  • nondeterministic TM (simulated by breadth-first search over its choices; possibly exponential slowdown),
  • TM with a two-way infinite tape, multiple heads, or a stay-in-place move,
  • a PDA with two stacks (or a FIFO queue automaton).

A linear bounded automaton (LBA) is a nondeterministic TM that may use only the cells holding the input. LBAs accept exactly the context-sensitive languages, and membership for them is decidable.

Church–Turing thesis. Anything computable by an algorithm is computable by a TM. This is a thesis, not a theorem.

Reading a TM. To find what a TM computes, trace it on two or three short inputs and write each configuration as (tape, head position, state). Count moves carefully: each application of δ is one move.

⊔1011⊔⊔⊔⊔⊔……finite controlstate q, table δδ(q, X) = (p, Y, L/R): write Y, move the head one cell, go to state phead
A Turing machine: finite control, read/write head and an unbounded tape (⊔ is the blank)

2. Recursive and recursively enumerable languages

  • L is recursively enumerable (RE, Turing-recognisable) if some TM accepts every string in L. On strings not in L it may reject or loop.
  • L is recursive (decidable) if some TM accepts every string in L and halts and rejects every string not in L. Such a TM is a decider.

CSL⊊Recursive⊊RE⊊all languages

The complement theorem. L is recursive if and only if both L and L‾ are RE. (Run both recognisers in parallel; one of them must accept.) Consequences:

  • If L is RE but not recursive, then L‾ is not RE.
  • The complement of a recursive language is recursive.
Operation Recursive RE
Union, intersection Yes Yes
Concatenation, Kleene star Yes Yes
Complement Yes No
Difference L1−L2 Yes No
Homomorphism No Yes
Inverse homomorphism Yes Yes

Non-RE languages exist. TMs can be listed as M1,M2,… (each is a finite string), so there are countably many. The set of all languages over Σ is uncountable. So most languages have no TM at all. The diagonal language Ld={⟨Mi⟩:Mi does not accept ⟨Mi⟩} is a concrete non-RE language.

An enumerator view: L is RE iff some TM can list its strings (possibly with repeats); L is recursive iff some TM can list them in increasing (shortlex) order.

3. The halting problem and reductions

ATM={⟨M,w⟩:M accepts w} and HALTTM={⟨M,w⟩:M halts on w} are both RE but not recursive.

  • RE: a universal TM simulates M on w and accepts if M accepts (or halts).
  • Not recursive: if a decider H existed, build D that on input ⟨M⟩ runs H on ⟨M,⟨M⟩⟩ and does the opposite. Running D on ⟨D⟩ gives a contradiction.
  • Hence ATM‾ and HALTTM‾ are not RE.

Mapping reduction. A≤mB means a computable function f maps every instance x to f(x) with x∈A  ⟺  f(x)∈B. It says "B is at least as hard as A".

If A≤mB and … then …
B is recursive A is recursive
B is RE A is RE
A is undecidable B is undecidable
A is not RE B is not RE

The direction is the usual trap: to prove a new problem B undecidable, reduce a known undecidable problem to B, never the other way. Also, A≤mB implies A‾≤mB‾.

Other standard undecidable problems: Post's correspondence problem (PCP), whether a CFG is ambiguous, whether two CFGs generate the same language, whether a CFG generates Σ∗, and whether two CFLs have an empty intersection. Most of these are proved by reductions from ATM or PCP.

4. Rice's theorem

Rice's theorem. Let P be any non-trivial property of the language of a TM: some TM's language has it and some TM's language does not. Then {⟨M⟩:L(M) has P} is undecidable.

Two conditions must hold before you apply it:

  1. Language property. If L(M1)=L(M2), then M1 and M2 must both have P or both lack it. Properties of the machine itself (states, moves, running time) are not covered.
  2. Non-trivial. Not true for all RE languages and not false for all.
Question about TM M Decidable? Reason
Is L(M) empty? No Rice
Is L(M) regular / context-free / finite? No Rice
Does L(M) contain ε? No Rice (but this set is RE)
Is L(M) recursively enumerable? Yes trivial: always true
Does M have more than 10 states? Yes read the description
Does M make at least 20 moves on input ε? Yes simulate 20 moves
Does M halt on every input? No not by Rice directly, but by reduction from HALTTM

RE or not? Rice says undecidable; it does not say whether the set is RE. A rough guide: "L(M) contains some particular string" is RE (search and wait for acceptance). "L(M)=∅" and "L(M) is finite" are not RE, since no finite amount of watching can confirm them.

5. Decidability table across language classes

For each class, assume the language is given by its standard machine or grammar (DFA, CFG, decider TM, TM).

Problem Regular CFL Recursive RE
Membership w∈L D D D U
Emptiness L=∅ D D U U
Finiteness D D U U
Universality L=Σ∗ D U U U
Equivalence L1=L2 D U U U
Disjointness L1∩L2=∅ D U U U
Subset L1⊆L2 D U U U

(D = decidable, U = undecidable.)

How the decidable ones work:

  • Regular: everything reduces to reachability in a DFA. Equivalence: build a DFA for the symmetric difference and test emptiness, or minimise both and compare.
  • CFL membership: CYK in O(n3). Emptiness: check whether the start symbol is generating. Finiteness: after removing useless symbols, check the grammar graph for a cycle.

Also undecidable for CFGs: ambiguity. But for a CFL L and a regular language R, L∩R is a CFL, so whether L∩R=∅ is decidable.

PCP is undecidable in general, but decidable when the alphabet has a single letter. When a question says "decidable", ask: is there an algorithm that always halts with the right yes/no answer? A procedure that halts only on yes-instances shows RE, not decidability.

Formulas to remember

Recursive iff RE and co-RE
L∈REC  ⟺  L∈RE and L‾∈RE
Hierarchy
Reg⊊DCFL⊊CFL⊊CSL⊊REC⊊RE
Reduction transfers hardness forward
A≤mB, A undecidable⇒B undecidable
Reduction transfers easiness backward
A≤mB, B decidable⇒A decidable
Complements under reduction
A≤mB⇒A‾≤mB‾

Common mistakes

  • Reversing the reduction: to prove B undecidable, reduce a known undecidable problem to B, not B to it.
  • Applying Rice's theorem to properties of the machine (number of states, steps taken) rather than of the language it accepts.
  • Treating 'undecidable' as 'not RE'; the halting problem is undecidable yet RE, while its complement is not RE.
  • Assuming RE languages are closed under complement; only recursive languages are.
  • Taking 'decidable' to mean an algorithm that answers yes when the answer is yes; it must also halt with no on every no-instance.

Worked examples

Try each step yourself, then reveal the working.

Example 1: Tracing a TM: binary increment

numerical

A TM starts in q0 on the leftmost symbol of a binary number. Rules: q0: on 0 or 1 move right (no change); on ⊔ move left and go to q1. q1: on 1 write 0 and move left; on 0 or ⊔ write 1 and halt. Find the output and the number of moves on input 1011.

  1. Step 1: Run $q_0$ to the end of the input.

    Try it on paper first.

Example 2: Using the complement theorem

conceptual

L is recursively enumerable and L‾ is not recursive. What can you say about L and L‾?

  1. Step 1: Relate $L$ and $\overline{L}$.

    Try it on paper first.

Example 3: Applying Rice's theorem correctly

conceptual

Which of these are decidable for a TM M? (i) L(M) has at least 3 strings. (ii) M has an even number of states. (iii) M visits state q5 within its first 100 moves on input ab. (iv) L(M)=L(M′) for a fixed TM M′ with L(M′)={ab}.

  1. Step 1: Sort into language and machine properties.

    Try it on paper first.

Example 4: Getting the reduction direction right

conceptual

A student shows Lnew≤mHALTTM and claims Lnew is undecidable. Another shows ATM≤mLnew. Which argument proves undecidability?

  1. Step 1: Read $A \le_m B$ as 'B is at least as hard as A'.

    Try it on paper first.

Previous year questions

16 official GATE CSE questions on this topic, newest first.

Practise these 16 PYQs →

Topic test

10 questions: up to 4 official PYQs and original practice questions, with GATE marking (MCQ wrong answers lose marks). Score 60% or more to pass. A new set is drawn each time.

Mark as mastered

Loading your progress…

My revision notes

Notes written by the GATEiit team against the official GATE CSE syllabus; being checked by a reviewer. Updated 2026-11-21. Spotted a mistake? Use Report an issue on any question, or contact us.