IAE Academy

GATE CS

Turing machines, decidability and undecidability

A Turing machine is the most general model of computation in the GATE syllabus: it defines which languages can be recognised (recursively enumerable) or decided (recursive) by any algorithm. GATE questions ask you to design or trace a machine, place a language in the hierarchy, use closure properties, and classify a problem as decidable, semi-decidable or undecidable.

8 previous-year questions · 8 solved · 5 practice questions

The Turing machine model

A deterministic Turing machine (TM) has a finite control and an infinite tape divided into cells. The input is written on the tape, the rest of the tape holds blanks, and the head starts on the leftmost input symbol in the start state. In each step the machine reads the cell under the head, writes a symbol, moves the head one cell left or right, and changes state.

Formally . Here is the finite set of states, the input alphabet, the tape alphabet, the blank (not in ), the start state and the set of accepting states. The transition function is , and it may be partial: if is undefined the machine halts. We assume no transition leaves an accepting state, so entering a state of halts the machine.

Notation. is the input alphabet, the empty string, the length of , the complement of with respect to , and a string encoding of the machine ; encodes the pair of a machine and an input.

Three possible outcomes on an input $w$

  1. Accept: enters a state in (and so halts).

  2. Reject: halts in a non-accepting state, because is undefined for its current state and symbol.

  3. Loop: never halts. A looping input is not accepted, but does not reject it either.

LANGUAGE OF A TURING MACHINE

Only accepted strings count; strings on which M loops or rejects are outside L(M).

Convention used below. In transition tables a cell means: go to state , write , move in direction . An empty cell means is undefined, so the machine halts and rejects (unless the state is accepting). The start state is marked →, the accepting state *.

Design idea for . Repeatedly mark the leftmost unmarked as , run right to the leftmost unmarked and mark it , then return to the leftmost unmarked . When no is left, check that only 's remain.

Transition table for a^n b^n (tape alphabet a, b, X, Y, blank)

State

a

b

X

Y

blank

→ q0

(q1, X, R)

(q3, Y, R)

q1

(q1, a, R)

(q2, Y, L)

(q1, Y, R)

q2

(q2, a, L)

(q0, X, R)

(q2, Y, L)

q3

(q3, Y, R)

(q4, blank, R)

  • q4

Trace on : marks the first ; skips the second and marks the first ; walks back to the and returns to ; marks the second ; skips the and marks the second ; walks back; sees and goes to ; skips the 's and reads a blank, so the machine enters and accepts. On the machine gets stuck in at the blank and rejects. On it rejects at once ( on blank is undefined), and on it rejects in on reading .

Variants and the Church-Turing thesis

Several changes to the basic model do not add power: each variant can be simulated by a standard single-tape deterministic TM, so the class of languages is the same.

Variants of the Turing machine

Variant

Same power as standard TM?

Cost of simulation / note

Multi-tape (k tapes, k heads)

Yes

A single-tape TM simulates steps (with ) in steps: a quadratic slow-down

Tape infinite in both directions

Yes

Fold the tape into two tracks

Stay-put move (L, R, S)

Yes

Replace S by a move right and a move back left

Non-deterministic TM

Yes (same languages)

A deterministic TM searches the computation tree breadth-first; the slow-down is exponential in general, for steps

Enumerator (prints strings)

Yes

Enumerators print exactly the RE languages; is recursive if and only if some enumerator prints it in shortlex order (by length, then alphabetically)

Two-stack PDA

Yes

The two stacks hold the tape to the left and to the right of the head. A PDA with one stack is weaker (context-free languages only)

Linear bounded automaton (head confined to the input cells)

No, weaker

Accepts exactly the context-sensitive languages; see the Chomsky section

The Church-Turing thesis says that anything computable by an algorithm in the intuitive sense is computable by a Turing machine. It is a thesis, not a theorem, because 'algorithm' has no formal definition to prove it against. It is why 'there is an algorithm' and 'a TM halts on every input' are used interchangeably when arguing about decidability.

EXAM TIP

Non-determinism does not enlarge the class of languages for TMs (unlike the PDA, where DPDA is strictly weaker than NPDA). A non-deterministic TM that halts on every branch for every input has an equivalent deterministic TM that halts on every input.

Recursive and recursively enumerable languages

Decide versus recognise

Class

Machine requirement

Also called

Recursive

Some TM halts on EVERY input: accepts if , rejects if

Decidable, Turing-decidable

Recursively enumerable (RE)

Some TM accepts exactly the strings of ; on it may reject or loop

Semi-decidable, Turing-recognisable

Not RE

No TM accepts exactly

Not even semi-decidable

Every recursive language is RE, and every context-free language is recursive. A language is RE exactly when some machine can list its members, in some order and possibly with repetitions, without necessarily ever stopping.

RECURSIVE = RE AND CO-RE

Here the complement is taken with respect to . To decide, run both recognisers in parallel (alternating steps); exactly one of them accepts: the one for if , the one for otherwise.

Consequences of this theorem for a language and its complement : exactly one of four cases holds. (1) Both are recursive. (2) Neither is RE. (3) is RE but not recursive, and then is not RE. (4) The mirror image of (3). It is never possible for to be RE but not recursive while is also RE.

Closure properties (Yes = always closed)

Operation

Regular

DCFL

CFL

Recursive

RE

Union

Yes

No

Yes

Yes

Yes

Intersection

Yes

No

No

Yes

Yes

Complement

Yes

Yes

No

Yes

No

Difference

Yes

No

No

Yes

No

Concatenation

Yes

No

Yes

Yes

Yes

Kleene star

Yes

No

Yes

Yes

Yes

Reversal

Yes

No

Yes

Yes

Yes

Intersection with a regular language

Yes

Yes

Yes

Yes

Yes

Homomorphism

Yes

No

Yes

No

Yes

Inverse homomorphism

Yes

Yes

Yes

Yes

Yes

EXAM TIP

Recursive languages are closed under every operation in the table except an arbitrary homomorphism (they are closed under -free homomorphism, but every RE language is a homomorphic image of a recursive language). RE languages are not closed under complement: if a question hands you a language known to be RE and non-recursive, its complement is outside RE. Difference is therefore recursive for recursive , is RE when is RE and is recursive, but can leave RE when is only RE.

Chomsky hierarchy and linear bounded automata

Chomsky hierarchy

Type

Grammar restriction

Machine

Language class

0

Unrestricted: , where contains at least one variable

Turing machine

Recursively enumerable

1

Context-sensitive: with ; also if never appears on a right-hand side

Linear bounded automaton (LBA)

Context-sensitive

2

Context-free:

Non-deterministic pushdown automaton

Context-free

3

Right-linear: (or all left-linear)

Finite automaton

Regular

Each class properly contains the next: , and the deterministic CFLs sit in between: . Examples that separate them: is a DCFL but not regular; is a CFL but not a DCFL; is context-sensitive but not context-free; (defined below) is RE but not recursive.

A linear bounded automaton is a non-deterministic TM whose head never leaves the cells holding the input (the input is delimited by end-markers). Its language class is exactly the context-sensitive languages; whether deterministic LBAs are equally powerful is an open question. Membership for an LBA is decidable: on an input of length the number of configurations is finite, so whether an accepting configuration is reachable can be checked. Emptiness and equivalence for LBAs are undecidable. Context-sensitive languages are closed under complement, and every one of them is recursive.

EXAM TIP

Do not confuse the strict inclusions: CSL is a proper subset of the recursive languages, so a recursive language need not be context-sensitive.

Halting problem, reductions and Rice's theorem

Two standard languages: the acceptance problem and the halting problem . Both are RE: a universal TM takes and simulates on , and . Both are undecidable, so their complements are not RE.

Why is undecidable (diagonal argument). Suppose a decider for exists. Build that on input runs on and accepts if and only if rejects, so accepts exactly when does not accept . Taking : accepts if and only if does not accept , a contradiction.

Non-RE languages exist. Every TM is a finite string, so there are countably many TMs and hence countably many RE languages, while a non-empty has uncountably many languages. A concrete example is the diagonal language : if , then if and only if . So is not RE.

REDUCTION PRINCIPLE (MANY-ONE)

Use the contrapositive: if and is undecidable, is undecidable. Also: and RE implies RE; and not RE implies not RE. Since if and only if , reducing to proves is not RE. Direction matters.

Procedure to prove a problem $P$ undecidable by reduction

  1. Pick a known undecidable problem , usually or .

  2. Give a computable function turning every instance of into an instance of .

  3. Show if and only if (both directions).

  4. Conclude that a decider for would give a decider for , which is impossible.

RICE'S THEOREM

P is a property of the language L(M). Non-trivial: some TM languages have it and some do not. Semantic: it depends only on L(M), not on the machine's structure.

Examples undecidable by Rice's theorem: is empty, finite, regular, context-free, equal to , does it contain a given string, does it contain at least two strings. Rice's theorem does NOT apply to properties of the machine's description or of bounded runs (the number of states, whether its transition table contains a left move, whether it halts within 100 steps on ): these are decidable by inspection or bounded simulation. 'Rice does not apply' does not mean decidable, though: 'does halt on the blank tape' is a property of the machine's behaviour, not of , and it is still undecidable (by reduction from ).

EXAM TIP

Rice's theorem only says undecidable. RE-ness needs a separate argument. Two conditions are necessary for to be RE: (i) if a language has , every RE superset of it has ; (ii) if a language has , some finite subset of it has . 'Contains a given string' and 'contains at least two strings' satisfy both and are RE. 'Empty', 'finite' and 'regular' fail (i), and 'equal to ' fails (ii), so none of these is RE. For emptiness, the complement set () is RE.

WORKED EXAMPLE

Classify as recursive, RE but not recursive, or not RE. Also classify .

Solution
  1. The property 'at least two strings' depends only on (semantic), and it is non-trivial: a machine accepting has it, a machine accepting does not.

  2. By Rice's theorem is undecidable, so it is not recursive.

  3. is RE: dovetail. For run for steps on each of the first strings in shortlex order; accept as soon as two different strings have been accepted. If has two strings, this halts; otherwise it runs forever.

  4. If were also RE, would be recursive by the 'RE and co-RE' theorem, contradicting step 2. So is not RE.

Answer: is RE but not recursive; is not RE.

Decidability of standard problems

Inputs are descriptions of a DFA , a context-free grammar , or a Turing machine . 'Decidable' means a TM always halts with the right yes/no answer.

Decidability status

Problem

DFA / regular

CFG / CFL

TM / RE

Membership: is ?

Decidable

Decidable (CYK; in Chomsky normal form a derivation of , , has exactly steps)

Undecidable; RE (semi-decidable)

Emptiness: is ?

Decidable (reachability of an accepting state)

Decidable (does the start symbol derive a terminal string?)

Undecidable; the language of 'empty' machines is not RE

Finiteness

Decidable

Decidable

Undecidable

Universality: is ?

Decidable

Undecidable

Undecidable

Equivalence: ?

Decidable

Undecidable

Undecidable

Containment: ?

Decidable

Undecidable

Undecidable

Is regular?

Trivial (yes)

Undecidable

Undecidable

Is ?

Decidable

Undecidable

Undecidable

Is a CFG ambiguous?

-

Undecidable

-

EXAM TIP

Memory rule for this table: every problem is decidable for finite automata; for CFGs only membership, emptiness and finiteness are; for TMs none of the language questions is. The emptiness of the intersection of two CFLs is undecidable (by reduction from PCP), but emptiness of 'CFL regular' is decidable, because that intersection is again context-free and its grammar can be built from the inputs. Equivalence of two deterministic PDAs is decidable, although equivalence of general CFGs is not.

Post correspondence problem (PCP), in brief. Given two lists of strings and over the same alphabet, does a sequence of indices () exist with ? PCP is undecidable over any alphabet of two or more symbols (over a one-symbol alphabet it is decidable). It is RE, since matches can be searched for in order of length. Reductions from PCP prove CFG universality, CFG equivalence, intersection emptiness of two CFLs, and CFG ambiguity undecidable.

Semi-decidable summary. Positive-witness problems are RE but undecidable: membership for a TM, 'does accept some string', 'does halt on ', 'does halt on the blank tape', and PCP. Their complements are not RE. Problems with no finite witness for either answer are in neither RE nor co-RE: TM equivalence, 'is finite', 'is ', and totality ('does halt on every input').

PREVIOUS-YEAR QUESTIONS

8 questions from the CS papers

Try each question first, then open the answer. We placed each question under a topic ourselves; the exam paper does not label topics.

See these papers in full: GATE CSE 2026 Set 2 · GATE CSE 2025 Set 2 · GATE CSE 2023 · GATE CSE 2022 · GATE CSE 2020 · GATE CSE 2018

GATE 2026 CS2 Q.13

GATE 2026 · CS2Q.13 · 1 mark · MCQ

Which one of the following statements is equivalent to the following assertion?

Turing machine decides the language

  1. (A)

    Turing machine halts on all input strings in

  2. (B)

    Turing machine accepts all input strings in

  3. (C)

    Turing machine rejects all input strings in

  4. (D)

    Turing machine accepts all input strings in and rejects all input strings in

Answer and solution
See the question in the paper
GATE 2026 CS2 Q.13: answer and solution

GATE 2025 CS2 Q.25

GATE 2025 · CS2Q.25 · 1 mark · MCQ

Let be Context Free Grammars (CFGs) and be a regular expression. For a grammar , let denote the language generated by .

Which ONE among the following questions is decidable?

  1. (A)

    Is ?

  2. (B)

    Is ?

  3. (C)

    Is ?

  4. (D)

    Is ?

Answer and solution
See the question in the paper
GATE 2025 CS2 Q.25: answer and solution

GATE 2023 CS Q.24

GATE 2023 · CSQ.24 · 1 mark · MSQ

Which of the following statements is/are CORRECT?

  1. (A)

    The intersection of two regular languages is regular.

  2. (B)

    The intersection of two context-free languages is context-free.

  3. (C)

    The intersection of two recursive languages is recursive.

  4. (D)

    The intersection of two recursively enumerable languages is recursively enumerable.

Answer and solution
See the question in the paper
GATE 2023 CS Q.24: answer and solution

GATE 2022 CS Q.23

GATE 2022 · CSQ.23 · 1 mark · MSQ

Which of the following statements is/are TRUE?

  1. (A)

    Every subset of a recursively enumerable language is recursive.

  2. (B)

    If a language and its complement are both recursively enumerable, then must be recursive.

  3. (C)

    Complement of a context-free language must be recursive.

  4. (D)

    If and are regular, then must be deterministic context-free.

Answer and solution
See the question in the paper
GATE 2022 CS Q.23: answer and solution

GATE 2022 CS Q.46

GATE 2022 · CSQ.46 · 2 marks · MSQ

Which of the following is/are undecidable?

  1. (A)

    Given two Turing machines and , decide if .

  2. (B)

    Given a Turing machine , decide if is regular.

  3. (C)

    Given a Turing machine , decide if accepts all strings.

  4. (D)

    Given a Turing machine , decide if takes more than steps on every string.

Answer and solution
See the question in the paper
GATE 2022 CS Q.46: answer and solution

GATE 2020 CS Q.26

GATE 2020 · CSQ.26 · 2 marks · MCQ

Which of the following languages are undecidable? Note that indicates encoding of the Turing machine .

  1. (A)

    , , and only

  2. (B)

    and only

  3. (C)

    and only

  4. (D)

    , , and only

Answer and solution
See the question in the paper
GATE 2020 CS Q.26: answer and solution

GATE 2018 CS Q.36

GATE 2018 · CSQ.36 · 2 marks · MCQ

Consider the following problems. denotes the language generated by a grammar . denotes the language accepted by a machine .

(I) For an unrestricted grammar and a string , whether
(II) Given a Turing machine , whether is regular
(III) Given two grammars and , whether
(IV) Given an NFA , whether there is a deterministic PDA such that and accept the same language.

Which one of the following statements is correct?

  1. (A)

    Only I and II are undecidable

  2. (B)

    Only III is undecidable

  3. (C)

    Only II and IV are undecidable

  4. (D)

    Only I, II and III are undecidable

Answer and solution
See the question in the paper
GATE 2018 CS Q.36: answer and solution

OTHER EXAMS

ISRO: 1 question

From ISRO's Scientist/Engineer written test: ISRO CS 2023. They are not counted in the GATE numbers on this page.

ISRO CS 2023 Q.58

ISRO 2023 · CSQ.58 · 1 mark · MCQ

Which of the following statements is NOT true?

  1. (A)

    If a language is recursive its complement is recursive

  2. (B)

    If a language is recursive its complement is recursively enumerable

  3. (C)

    If a language and its complement are recursively enumerable it is recursive

  4. (D)

    If a language is recursively enumerable its complement is also recursively enumerable

Answer and solution
See the question in the paper
ISRO CS 2023 Q.58: answer and solution

PRACTICE

5 questions to test yourself

PRACTICE 11 mark · MCQ

Let be a recursively enumerable language that is not recursive. Which statement about (complement with respect to ) is correct?

  1. (A)

    is recursive

  2. (B)

    is RE but not recursive

  3. (C)

    is not recursively enumerable

  4. (D)

    is context-free

Answer and solution

Answer: (C)

  1. If were RE, then and would both be RE, which makes recursive.

  2. That contradicts the assumption that is not recursive, so is not RE.

  3. Hence it cannot be recursive or context-free either. Answer: C.

PRACTICE 22 marks · MSQ

Which of the following problems are decidable? Inputs are a DFA , a context-free grammar and a Turing machine .

  1. (A)

    Given , is ?

  2. (B)

    Given , is ?

  3. (C)

    Given , is finite?

  4. (D)

    Given , does accept ?

Answer and solution

Answer: (A), (C)

  1. A: emptiness for a DFA is decidable by checking whether any accepting state is reachable from the start state.

  2. B: universality of a CFG is undecidable (reduction from the Post correspondence problem).

  3. C: finiteness of a CFG is decidable: if is empty it is finite; otherwise convert to Chomsky normal form with no useless symbols, and is infinite exactly when the graph with an edge for each production or has a cycle.

  4. D: '' is a non-trivial property of , so it is undecidable by Rice's theorem. Answer: A and C.

PRACTICE 32 marks · NAT

A single-tape deterministic TM increments a binary number written on the tape, most significant bit first. The head starts on the leftmost bit in state . In : on 0 or 1, write the same symbol, move right and stay in ; on blank, write blank, move left and go to . In : on 1, write 0, move left and stay in ; on 0, write 1, move right and go to the halting state , which has no transitions. Assume the input contains at least one 0. For the input , how many transitions does the machine execute before it is in state (count the transition into )?

Answer and solution

Answer:

  1. The scan right over the four bits uses 4 transitions ( on 1, 0, 1, 1).

  2. The transition on the blank into is the 5th and leaves the head on the last bit.

  3. In : the last bit 1 becomes 0 (6th), the third bit 1 becomes 0 (7th), the second bit 0 becomes 1 and the machine enters (8th).

  4. The tape holds , which is . Total transitions = 8.

PRACTICE 42 marks · MCQ

For a Turing machine , which of the following properties is undecidable?

  1. (A)

  2. (B)

    has at least five states

  3. (C)

    halts within 100 steps on the empty input

  4. (D)

    The encoding has an even number of symbols

Answer and solution

Answer: (A)

  1. A depends only on and is non-trivial (some machines accept nothing, others accept something), so Rice's theorem makes it undecidable.

  2. B and D are syntactic properties of the description, decidable by reading it.

  3. C is decidable by simulating for at most 100 steps. Answer: A.

PRACTICE 52 marks · MSQ

Let be a recursive language and a recursively enumerable language over . Which of the following statements are always true?

  1. (A)

    is recursively enumerable

  2. (B)

    is recursive

  3. (C)

    is recursively enumerable

  4. (D)

    is recursive

Answer and solution

Answer: (A), (B)

  1. A: RE languages are closed under intersection, and every recursive language is RE. True.

  2. B: recursive languages are closed under complement (swap accept and reject in the decider). True.

  3. C: false in general; if is RE but not recursive its complement is not RE.

  4. D: take and RE but not recursive; then , which is not even RE. Answer: A and B.

OFFICIAL GATE 2027 SYLLABUS WORDING

Copied from the GATE 2027 syllabus; see all 2027 syllabi.

GATE CS

Turing machines and undecidability

Preparing in Kolkata? IAE Academy's course for GATE CSE.