Notes
Over 85% of GATE Theory of Computation marks come from 12 recurring question patterns. For each pattern below, learn the recognition trigger, follow the numbered speed-method, and study the worked example before attempting the 12 drill questions at the bottom.
1Pattern 1: Minimal DFA State Counting
Trigger: “What is the number of states in the minimal DFA over Σ accepting L = { … }?”
Fastest solving method:
- Check the standard formula table first: starts with w (k+2), ends with w (k+1), contains w (k+1), length/count = k or ≤ k (k+2), length/count ≥ k (k+1), mod n (n), k-th from start (k+2), k-th from end (2k).
- If compound (#a mod m and/or #b mod n): multiply the independent state trackers (m · n), then check if any states merge (e.g. an accepting sink or dead state absorbs sub-cases).
- If custom: use Myhill–Nerode (“distinct futures”): list the minimal pieces of information a prefix must remember to decide future continuations, and always ask whether a dead state is reachable.
Solution: Track (#a ∈ {0, ≥1}) × (#b ∈ {0, 1, ≥2}). Once #b ≥ 2, the string is hopeless regardless of #a, so all (#b ≥ 2) cases collapse into 1 dead state D. For #b ∈ {0, 1} and #a ∈ {0, ≥1}, we have 2 × 2 = 4 live states: (0,0), (≥1,0)*, (0,1), (≥1,1)*. All 4 have distinct futures (separated by ε, a, b, ab) and D is separated by everything. Total = 4 + 1 = 5 states.
2Pattern 2: NFA → DFA State Counting (Subset Construction)
Trigger: Given an NFA table/diagram (or a description with nondeterministic guessing), find the number of states in the equivalent DFA produced by subset construction.
Fastest solving method:
- Never answer 2n blindly: 2n is only the upper bound; GATE asks for the number of reachable subset-states from ECLOSE(q₀).
- Do lazy worklist expansion: start with S₀ = ECLOSE({q₀}). For each new subset S and each input symbol, compute δ(S, a). Add only newly discovered subsets to your list.
- Watch for ∅ and universal self-loops: if q₀ loops to itself on every symbol in Σ, every reachable subset contains q₀, so at most 2n−1 subsets can ever be reached and ∅ never appears! If ∅ is reached, count it as a state (the dead state).
Solution: Start with {p}.
• From {p}: on 0 → {p}; on 1 → {p, q} (new).
• From {p, q}: on 0 → {p, r} (new); on 1 → {p, q}.
• From {p, r}: on 0 → {p}; on 1 → {p, q}.
Worklist closes! Reachable subsets: {p}, {p, q}, {p, r} = 3 states (language: ends with 10).
3Pattern 3: Regex Equivalence & Language Identification
Trigger: “Which of the following regular expressions is equivalent to R?” or “Which regex represents language L?”
Fastest solving method:
- Test length 0, 1, 2 strings first (The 15-Second Sieve): Check ε, then a, b, then aa, ab, ba, bb. Any option that accepts a forbidden short string or misses a required short string is eliminated immediately.
- Check structural invariants: Does the option force the string to start/end with a fixed symbol? Does it forbid "aa" before "b"?
- Apply algebraic identities for remaining contenders: use (r + s)* = (r*s*)* = r*(sr*)* and shifting (rs)*r = r(sr)*.
Solution: Test short strings in L: ε ✓, 1 ✓, 01 ✓, 101 ✓, 0101 ✓; while 0 ∉ L and 00 ∉ L.
• (D) generates "0", which violates the rule → eliminate D.
• (B) cannot generate "101" (all 01s must come before 1s) → eliminate B.
• (C) cannot generate "011" → eliminate C.
• (A) builds strings from blocks "1" and "01" in any order: every 0 is paired with an immediate 1, and every such string decomposes into "1" and "01" blocks. Answer: (A).
4Pattern 4: Regular-or-Not Fast Test
Trigger: Given 2 to 4 set-builder languages, identify which ones are regular.
Fastest solving method:
- Check for disguised finiteness or collapse: Is there an upper bound like n ≤ 106? (Finite ⇒ Regular!) Does a free middle variable x ∈ Σ+ absorb the constraint, as in {wxwR}? (Collapses to first = last symbol ⇒ Regular!)
- Check if the memory needed is bounded: Modular arithmetic (n ≡ m mod k), parities, bounded prefix differences (|#a − #b| ≤ 3), or substring counts like #ab = #ba need only finitely many states ⇒ Regular.
- Check for unbounded exact comparisons or non-periodic unary sets: #a = #b, n ≥ m, n ≠ m, ww, wwR, an², aprime ⇒ Not Regular.
Solution: L₁ tracks only parity of length (2 states × a*b* order) ⇒ Regular. L₂ ties m and n by an exact unbounded equation m = n + 2 ⇒ Not regular. L₃ has u, v ∈ {0,1}+: choosing |u| = 1 reduces it to "starts and ends with the same bit and length ≥ 3" ⇒ Regular. Answer: L₁ and L₃.
5Pattern 5: Language Classification Ladder (Reg / DCFL / CFL / CSL / REC / RE)
Trigger: Classify a language into its smallest Chomsky/automata class.
Fastest solving method:
- Step 1 (Bounded?): Finite / mod k / free middle → Regular.
- Step 2 (One stack, deterministic trigger?): Single comparison (anbn, wcwR, #a = #b, aibjck with i = j + k) or sequential/nested pairs (anbncmdm, anbmcmdn) → DCFL.
- Step 3 (One stack, needs a guess?): Unmarked palindrome (wwR), OR of two comparisons (i = j or j = k; anbn ∪ anb2n), complement of ww → CFL (not DCFL).
- Step 4 (Two+ independent comparisons / copy / crossing / nonlinear unary?): anbncn, ww, anbmcndm, i < j < k, an², aprime → CSL (not CFL).
- Step 5 (TM description language?): Halting / acceptance / non-emptiness → RE (not REC); emptiness of L(M) → co-RE (not RE); equivalence, totality, regularity of L(M) → neither.
Solution: Rewrite L as anbmcmcn: a DPDA pushes A for each a, pushes B for each b, pops B for the first m c’s, then pops A for the remaining n c’s — no guessing! So L is a DCFL. M requires multiplication n·m, which needs repeating a count m times (two-way tape movement) — so M is a CSL (not CFL).
6Pattern 6: Closure-Property Combination MSQs
Trigger: “L₁ ∈ Class X, L₂ ∈ Class Y. Which class is L₁ op L₂ guaranteed to belong to?”
Fastest solving method:
- Convert both operands to the common / larger class, UNLESS the operation is intersection/difference with a Regular language (every class from DCFL to RE is closed under ∩ Regular!).
- Check the Master Closure Table for that class and operation.
- Remember the 4 classic traps: (a) DCFL ∪ DCFL is CFL, not necessarily DCFL; (b) CFL ∩ CFL is CSL/REC, not necessarily CFL; (c) Complement of CFL is CSL/REC, not CFL; (d) Complement of RE is co-RE, not RE.
Solution: L₁ is a DCFL ⇒ L₁̅ is a DCFL (DCFL closed under complement) ⇒ L₁̅ is also a CFL. Union with CFL L₂ gives a CFL (CFL closed under ∪). Intersecting that CFL with Regular R gives a CFL (CFL closed under ∩ Regular).
7Pattern 7: Decidability Table MSQs
Trigger: “Which of the following problems are decidable for class X?”
Fastest solving method:
- Regular: EVERYTHING is decidable.
- CFL: ONLY M E F (Membership, Emptiness, Finiteness) are decidable. Everything else (Equivalence, Universality, Inclusion, Regularity, Ambiguity, Disjointness) is undecidable! (Exception: L(G) ⊆ R for regular R reduces to emptiness of L(G) ∩ R̅, which IS decidable.)
- DCFL: M, E, F plus Universality (via complement) and Equivalence (Sénizergues) and Regularity are decidable; Inclusion and Disjointness are undecidable.
- CSL & REC: ONLY Membership is decidable. Emptiness, Finiteness, Equivalence, Universality are all undecidable.
- RE: NOTHING in the table is decidable (even membership is only semi-decidable/RE).
Solution: (i) Universality of CFG → Undecidable. (ii) Emptiness of intersection of two CFLs → Undecidable. (iii) a*b* is regular, so L(G) ∩ a*b* is a CFL whose grammar we can construct, and CFL emptiness is decidable → Decidable!
8Pattern 8: Rice’s Theorem Applicability
Trigger: Given several languages of TM encodings {⟨M⟩ | …}, decide which are decidable vs undecidable.
Fastest solving method:
- Test 1 — Is it semantic or syntactic/bounded? Does the condition talk ONLY about the set of accepted strings L(M), or does it mention states, tape cells, head moves, or a fixed step bound k?
- If it bounds steps (e.g. “halts on w within 50 steps”) or counts states/symbols in ⟨M⟩ → DECIDABLE (Rice does NOT apply).
- If it asks about unbounded head/state behavior (e.g. “ever enters state q”) → Rice doesn’t apply directly, but it is usually undecidable by direct reduction from ATM (unless trivial like “moves right on step 1”).
- Test 2 — Is the semantic property trivial? Is it true for NO RE languages (∅) or ALL RE languages? For example, “L(M) is recursively enumerable” is true for ALL TMs → DECIDABLE (always yes).
- Otherwise (non-trivial semantic property of L(M)): Rice’s theorem applies → UNDECIDABLE.
Solution: (i) Syntactic (inspect ⟨M⟩) → Decidable. (ii) Bounded simulation (run M on ε for 20 steps) → Decidable. (iii) Non-trivial semantic property (∅ is decidable, ATM is not) → Undecidable by Rice. (iv) Trivial semantic property (every TM’s language is RE!) → Decidable.
9Pattern 9: Reduction Direction & RE / co-RE Deduction
Trigger: Questions on A ≤m B, or classifying whether {⟨M⟩ | …} is RE, co-RE, or neither.
Fastest solving method:
- Arrow = "is at most as hard as": Read A ≤m B as A ≤ B. If the bigger one (B) is easy (REC / RE / co-RE), the smaller one (A) is also easy. If the smaller one (A) is hard (undecidable / not RE / not co-RE), the bigger one (B) is also hard.
- One witness vs all strings (RE vs co-RE test):
- If verifying "yes" only needs finding one finite accepting run (e.g. "M accepts w", "M halts on w", "L(M) ≠ ∅", "|L(M)| ≥ 3") → RE (not REC) via dovetailing.
- If "yes" is the exact negation of a dovetailing property (e.g. "M does not halt on w", "L(M) = ∅", "|L(M)| ≤ 2") → co-RE (not RE).
- If "yes" requires checking infinitely many inputs (e.g. "L(M) = Σ*", "M halts on ALL inputs", "L(M) is infinite/regular/CFL") → Neither RE nor co-RE (REGTM and CFLTM belong here too).
Solution: Dovetail M on all strings in Σ*; as soon as 2 distinct strings are accepted, halt and accept ⟨M⟩! So L is in RE. By Rice’s theorem L is undecidable, so L ∉ REC, which also means L ∉ co-RE. Answer: RE but not REC (and not co-RE).
10Pattern 10: CNF / GNF Step & Conversion Counts
Trigger: Counting steps in CNF/GNF derivations, parse tree nodes, or new rules after grammar cleanup.
Fastest solving method:
- CNF derivation of w (|w| = n ≥ 1): Total steps = 2n − 1. Binary rules (A → BC) used = n − 1. Terminal rules (A → a) used = n.
- GNF derivation of w (|w| = n ≥ 1): Total steps = n (one terminal generated per step).
- CNF parse tree height h (where h counts edges from root to terminal leaf): Max yield length = 2h−1 (since the last level is A → a). If height counts variable levels/binary splits k, max yield = 2k.
Solution: Number of binary rules = n − 1 = 14 ⇒ |w| = n = 15. Total derivation steps = 2(15) − 1 = 29.
11Pattern 11: PDA & TM Transition Tracing
Trigger: Given explicit δ transitions of a PDA or TM, find the accepted language, final tape content, or halting state.
Fastest solving method:
- For a PDA: Write the net stack change per symbol: e.g. a pushes 2 A’s (+2), b pops 1 A (−1). Set total change = 0: 2(#a) − #b = 0 ⇒ #b = 2(#a). Then check phase order (states) and boundary conditions (is ε accepted? must at least one b be read?).
- For a TM: Trace on tiny inputs (n = 1, 2) by writing configurations (e.g.
q0 a b □). Identify each state’s macro-role ("scan right to blank", "zig-zag matching one a with one b", "flip 0↔1", "add 1 in binary").
Solution: q₀ scans to the right end of the binary number. q₁ scans right-to-left, turning trailing 1s into 0s until the first 0 is flipped to 1 (or □ becomes 1) and halts. That is binary increment (adding 1 to a binary number)!
12Pattern 12: Counting Strings of Length n in a Language
Trigger:NAT question: “How many strings of length n over Σ belong to L?”
Fastest solving method:
- Direct combinatorics (fixed positions / counts): If k positions are fixed and n − k are free over m symbols → mn−k. If parity is fixed (even number of a’s over {a,b}) → 2n−1.
- Inclusion–Exclusion (OR of two patterns): |A ∪ B| = |A| + |B| − |A ∩ B|.
- DFA path-counting recurrence (for forbidden substrings): Write a tiny table of (state, length 0, 1, 2, …, n) where each column is the sum of incoming states from the previous column. For "no two consecutive a’s", total strings = Fibonacci Fn+2 (1, 2, 3, 5, 8, 13, 21, …).
01 OR end with 10?Solution: Let A = starts with 01 (first 2 bits fixed, 4 free ⇒ 2⁴ = 16). Let B = ends with 10 (last 2 bits fixed, 4 free ⇒ 2⁴ = 16). A ∩ B = starts with 01 AND ends with 10 (4 bits fixed, middle 2 free ⇒ 2² = 4). By inclusion–exclusion: 16 + 16 − 4 = 28.
Practice questions
- NAT · 2 marks
What is the number of states in the minimal DFA over {a, b} that accepts all strings containing
abaas a substring?Write your answer before opening the key.
- NAT · 2 marks
An NFA over {a, b} has 3 states {1, 2, 3}, start state 1, and transitions: 1 —a,b→ 1; 1 —a→ 2; 2 —a,b→ 3 (no moves from 3). How many reachable states does the subset-construction DFA have?
Write your answer before opening the key.
- MCQ · 2 marks
Which regular expression over {a, b} is equivalent to
(a + b)*b(a + b)*(strings containing at least one b)?- a*b(a + b)*
- (a + b)*ba*
- Both (A) and (B)
- a*ba*
- MSQ · 2 marks
Which of the following languages over {a, b} are REGULAR?
- { w ∈ {a,b}* | #(ab) = #(ba) }
- { aⁿbⁿ | 0 ≤ n ≤ 500 }
- { aⁿbᵐ | n ≡ m (mod 5) }
- { aⁿbᵐ | n ≠ m }
- MCQ · 2 marks
What is the smallest language class containing L = { aⁿbⁿ | n ≥ 1 } ∪ { aⁿb²ⁿ | n ≥ 1 }?
- Regular
- DCFL
- CFL (not DCFL)
- CSL (not CFL)
- MCQ · 2 marks
If L₁ is a Context-Free Language and L₂ is a Regular Language, which of the following is NOT necessarily a Context-Free Language?
- L₁ ∩ L₂
- L₁ − L₂
- L₂ − L₁
- L₁ / L₂
- MSQ · 2 marks
Which of the following decision problems are UNDECIDABLE?
- Whether a CFG G is ambiguous
- Whether L(G) = Σ* for a CFG G
- Whether L(M₁) = L(M₂) for two DPDAs M₁ and M₂
- Whether L(M) = ∅ for a Turing machine M
- MSQ · 2 marks
Which of the following languages of Turing machine encodings are DECIDABLE?
- { ⟨M⟩ | M halts on ε within 50 steps }
- { ⟨M⟩ | M has at most 12 states }
- { ⟨M⟩ | L(M) = ∅ }
- { ⟨M⟩ | L(M) is a Recursive language }
- MCQ · 2 marks
Suppose A ≤m B and A is NOT Recursively Enumerable (A ∉ RE). Which statement MUST be true?
- B is not Recursively Enumerable (B ∉ RE)
- B is Recursively Enumerable
- B is decidable
- B̅ is Recursively Enumerable
- NAT · 1 mark
In a CNF grammar, a derivation of a terminal string w applies terminal productions (of the form A → a) 18 times. How many total derivation steps (including binary rules A → BC) were used to derive w?
Write your answer before opening the key.
- MCQ · 2 marks
A PDA pushes one X for each a read in state q₀, switches to q₁ on reading c (without changing the stack), pops one X for each b read in q₁, and accepts when the stack has only Z₀ left. What language does it accept?
- { aⁿcbⁿ | n ≥ 0 }
- { aⁿbⁿ | n ≥ 0 }
- { wcwᴿ | w ∈ {a,b}* }
- { aⁿcbᵐ | n, m ≥ 0 }
- NAT · 2 marks
Over Σ = {a, b}, how many strings of length 5 start with
aAND end withb?Write your answer before opening the key.
Answer key
Reveal answers when you’re ready
- 4 — For "contains w" where |w| = k, the minimal DFA always has k + 1 = 3 + 1 = 4 states (no dead state needed).
- 4 — Start: {1}. From {1}: a → {1,2}, b → {1}. From {1,2}: a → {1,2,3}, b → {1,3}. From {1,2,3}: a → {1,2,3}, b → {1,3}. From {1,3}: a → {1,2}, b → {1}. Reachable subsets: {1}, {1,2}, {1,2,3}, {1,3} = 4 states (language: 2nd symbol from end is a).
- C — a*b(a + b)* splits on the FIRST b; (a + b)*ba* splits on the LAST b. Both describe all strings with at least one b.
- A: True, but (B) is also equivalent.
- B: True, but (A) is also equivalent.
- D: Describes strings with exactly one b.
- ABC — A holds iff |w| ≤ 1 or first symbol = last symbol (regular); B is finite (regular); C tracks (n − m) mod 5 in 5 states (regular). D is non-regular (complement ∩ a*b* = aⁿbⁿ).
- D: Unbounded inequality comparison; not regular.
- C — Each component is a DCFL, so their union is a CFL. However, a DPDA cannot deterministically know whether to pop 1 or 2 b’s per a without guessing, so L is a CFL but not a DCFL.
- A: Requires unbounded counting.
- B: DCFLs are not closed under union; this union requires nondeterminism.
- D: It is generated by S → A | B, A → aAb | ab, B → aBbb | abb (a CFG).
- C — L₂ − L₁ = L₂ ∩ L̅₁. Taking L₂ = Σ* gives Σ* − L₁ = L̅₁, the complement of a CFL, which is NOT necessarily a CFL! By contrast, L₁ ∩ L₂, L₁ − L₂ = L₁ ∩ L̅₂, and L₁ / L₂ are all CFLs.
- A: CFL ∩ Regular is always a CFL.
- B: L₁ − L₂ = L₁ ∩ L̅₂, and L̅₂ is regular, so it is a CFL.
- D: CFLs are closed under quotient with a regular language.
- ABD — CFG ambiguity, CFG universality, and TM emptiness are all undecidable. Equivalence of two DPDAs (DCFLs) is decidable by Sénizergues’ theorem.
- C: Equivalence of DCFLs is decidable.
- AB — A is decided by running M on ε for 50 steps; B is decided by counting states in ⟨M⟩. C and D are non-trivial semantic properties of L(M) and are undecidable by Rice’s theorem.
- C: Emptiness of L(M) is undecidable.
- D: Whether L(M) is recursive is a non-trivial semantic property → undecidable.
- A — If B were RE, then A ≤_m B would imply A ∈ RE (simulate the reduction f(w) and run B’s recognizer). Therefore B cannot be RE.
- B: Would force A ∈ RE.
- C: Would force A decidable.
- D: B could be neither RE nor co-RE.
- 35 — 18 terminal rules means |w| = n = 18. The total number of steps in CNF is 2n − 1 = 2(18) − 1 = 35.
- A — It reads aⁿ in q₀ (pushing n X’s), reads a single c to enter q₁, and reads bⁿ in q₁ (popping all n X’s).
- B: Requires c in the middle.
- C: Only a’s are allowed before c and only b’s after c.
- D: Counts of a and b must be equal for Z₀ to be exposed at the end.
- 8 — Position 1 is fixed to a and position 5 is fixed to b. The remaining 3 middle positions each have 2 choices: 2³ = 8.