Sub topic 15
Decidable and Undecidable Problems Across Language Classes
This chapter assumes you know finite automata, context-free grammars and pushdown automata, the decidable/semi-decidable distinction, and many-one reductions. It also assumes you know the statement of Rice's theorem. The goal is a lookup table you can reason out from first principles, so you do not need to memorize it.
The question being asked
A decision problem takes a description of a language, such as a DFA, a CFG or a Turing machine, and asks a yes/no question about it. Four questions come up again and again:
- Membership: is a given string w in L?
- Emptiness: is L empty?
- Equivalence: do two descriptions define the same language?
- Totality (universality): is L equal to Σ*?
Finiteness and "is L regular?" also appear in GATE questions. For each language class the question is whether some algorithm always halts with the right answer. If one does, the problem is decidable. Otherwise it is undecidable. An undecidable problem can still be semi-decidable.
Regular languages: everything is decidable
A DFA is a finite object with a simple graph structure, so every standard question reduces to a graph or product-construction check.
- Membership: simulate the DFA on w. It takes |w| steps.
- Emptiness: check whether any accepting state is reachable from the start state.
- Totality: check that no non-accepting state is reachable.
- Finiteness: L is infinite exactly when a cycle lies on some path from the start state to an accepting state.
- Equivalence: build the symmetric difference (L1 ∖ L2) ∪ (L2 ∖ L1) with product and complement constructions. Then test it for emptiness. Alternatively, minimize both DFAs and compare.
NFAs and regular expressions convert to DFAs, so these answers hold for them as well.
Context-free languages: the boundary
CFLs are where the answers start to split. Some questions stay decidable and others become undecidable.
Decidable for CFGs:
- Membership: the CYK algorithm decides it in O(n³) time for a grammar in Chomsky normal form.
- Emptiness: mark variables that can derive a string of terminals, repeating until no change. L is empty exactly when the start symbol is never marked.
- Finiteness: remove useless symbols, then check the dependency graph of the variables for a cycle. A cycle means a variable can reproduce itself with extra symbols, which makes the language infinite.
Undecidable for CFGs:
- Totality: is L(G) = Σ*?
- Equivalence: is L(G1) = L(G2)?
- Ambiguity: is G ambiguous?
- Intersection emptiness: is L(G1) ∩ L(G2) = ∅?
- Is the CFL regular?
The standard proofs reduce from the Post Correspondence Problem or from the question of whether a TM has an accepting computation history. The idea is that a CFG can generate all strings that are not valid accepting histories, because invalidity can be spotted locally. So the grammar generates everything exactly when the machine accepts nothing.
Why does emptiness stay decidable while intersection emptiness does not? CFLs are not closed under intersection. The intersection of two CFLs can encode something as strong as a computation history, which a single CFG cannot capture. Compare this with CFLs intersected with a regular language. That is still a CFL, so that case is decidable.
One useful special case: for deterministic CFLs, equivalence with a regular language is decidable, and DPDA equivalence is decidable (a famous result by Sénizergues). GATE rarely goes that far. The safe default is that equivalence for general CFGs is undecidable.
Recursive and RE languages: almost nothing is decidable
For Turing machines, Rice's theorem covers most questions. Any non-trivial property of L(M) is undecidable.
| Problem on a TM M | Decidable? | Why |
|---|---|---|
| Does M accept w? (A_TM) | Undecidable, semi-decidable | Run M on w. If it never halts, we never answer. |
| Does M halt on w? | Undecidable, semi-decidable | Same simulation argument. |
| Is L(M) empty? (E_TM) | Undecidable, not semi-decidable | Its complement is semi-decidable, so E_TM is co-RE. |
| Is L(M) = Σ*? | Undecidable, not even semi-decidable | Rice, and neither it nor its complement fits the simple case. |
| Is L(M) finite? | Undecidable | Rice. |
| Is L(M) regular? | Undecidable | Rice. |
| Is L(M1) = L(M2)? | Undecidable | Reduce from E_TM by fixing M2 as a machine that rejects everything. |
| Is L(M) context-free? | Undecidable | Rice. |
The emptiness row shows why decidable, semi-decidable and non-RE must be kept apart. A TM that has some accepting string can be found by dovetailing: run M on all strings in parallel, with a growing number of steps. If any string is accepted, you find it. So "L(M) is non-empty" is semi-decidable, and "L(M) is empty" is its complement.
A reminder on Rice's theorem
Rice's theorem applies only to properties of the language L(M), not to properties of the machine's structure. It also requires the property to be non-trivial, meaning some TMs have it and some do not.
- "L(M) is empty" is a property of the language. Rice applies, so it is undecidable.
- "M has at least 5 states" is about the machine. Rice does not apply, and it is decidable because you just count.
- "M halts on input ε" is about behavior and not purely about L(M). Rice does not apply directly. It is still undecidable, by a direct reduction from the halting problem.
Linear bounded automata and the middle levels
The Chomsky hierarchy adds one more level that GATE sometimes tests: context-sensitive languages, recognized by linear bounded automata (LBAs).
- Membership for a context-sensitive grammar is decidable. An LBA has a bounded number of configurations on an input of length n, so a simulation can detect a repeated configuration and stop.
- Emptiness for context-sensitive grammars is undecidable.
So decidability of membership holds for regular, context-free and context-sensitive languages. It fails for unrestricted grammars (type 0), which are equivalent to TMs.
A summary table
| Problem | Regular | CFL | Context-sensitive | Recursive | RE |
|---|---|---|---|---|---|
| Membership | D | D | D | D | UD |
| Emptiness | D | D | UD | UD | UD |
| Finiteness | D | D | UD | UD | UD |
| Totality | D | UD | UD | UD | UD |
| Equivalence | D | UD | UD | UD | UD |
Here D means decidable and UD means undecidable. The recursive column describes machines that halt on every input. Even then, the question of whether a given machine is such a decider cannot be answered by an algorithm.
Deciding membership and emptiness in code
Emptiness for a CFG is a short fixed-point algorithm, which shows why it is decidable.
def cfg_is_empty(grammar, start):
"""grammar: dict mapping variable -> list of right-hand sides (tuples).
Symbols that are not keys of grammar are terminals."""
productive = set()
changed = True
while changed:
changed = False
for var, rules in grammar.items():
if var in productive:
continue
for rhs in rules:
if all(s not in grammar or s in productive for s in rhs):
productive.add(var)
changed = True
break
return start not in productive
g1 = {'S': [('a', 'S', 'b'), ()]} # generates a^n b^n
g2 = {'S': [('S', 'A')], 'A': [('a',)]} # S never terminates
print(cfg_is_empty(g1, 'S')) # False
print(cfg_is_empty(g2, 'S')) # TrueThe loop adds at least one variable per round or stops, so it halts after at most |V| rounds. No such bound exists for the TM version of this question.
Common errors
- Treating "is L regular?" as decidable for CFGs. It is undecidable for general CFGs, even though regular and CFL membership are both decidable.
- Mixing up emptiness and totality for CFGs. Emptiness is decidable. Totality is not.
- Applying Rice's theorem to machine properties. Count states, count transitions, or check for a particular transition: those are decidable.
- Reading "undecidable" as "not semi-decidable". ATM is undecidable but RE. ETM is undecidable and not RE.
- Assuming a decidable class gives decidable questions about it. Recursive languages are decidable themselves, but questions about recursive languages, such as emptiness, are not.
Exercise
For each problem, say whether it is decidable: (a) given a CFG G, is L(G) empty; (b) given a CFG G, is L(G) = Σ*; (c) given two DFAs, are their languages equal; (d) given a TM M, does L(M) contain at least one string; (e) given a TM M, does M have more than 10 states.
Show answer
(a) Decidable, by the productive-variables fixed point. (b) Undecidable. (c) Decidable, by testing the symmetric difference for emptiness or by minimizing both. (d) Undecidable by Rice's theorem, but semi-decidable by dovetailing. (e) Decidable, because the check only inspects the machine's description and not its language, so Rice does not apply.
Exercise
Why is membership decidable for context-sensitive grammars but not for unrestricted grammars?
Show answer
A linear bounded automaton on input length n has only finitely many configurations, bounded by a function of n. A simulator can run until it accepts, rejects, or repeats a configuration, so it always halts. A general TM has an unbounded tape and so an unbounded number of configurations, which allows non-halting runs that cannot be detected.