GATE CS Theory of Computation Previous Year Questions

60 solved GATE CS questions on Theory of Computation, drawn from 8 exam years and grouped by year. Every question shows the official answer and a step-by-step solution.

Want to practise this topic and ask follow-up questions? Explore Success Tracker.

Revision companion

Theory of Computation: define the language, then choose the machine

Specify the set of strings a language contains before attempting to recognize or generate them. These selected foundations connect regular languages, context-free grammars, Turing machines, and undecidability. Formal proofs of non-regularity and undecidability follow structured techniques, not intuition.

Our study notes and original examples support the PYQs below; they are not official exam questions or a replacement for the current syllabus.

Before you start

  • Set notation: union, intersection, complement, Kleene star, and the empty string ε.
  • Basic understanding of directed graphs as used in state-transition diagrams.

Concepts to revise before solving

Regular languages and finite automata

A DFA has exactly one transition per state per symbol; an NFA may have multiple or none. Both recognize the same class of languages: regular languages. Regular expressions, DFAs, and NFAs are equivalent in power. Closure properties: regular languages are closed under union, intersection, complement, and concatenation.

Check yourself: Does your DFA have a transition for every symbol in every state?

Pumping lemma for regular languages

To prove a language L is not regular: assume L is regular, then for any pumping length p chosen by the adversary, find a string w in L with |w| ≥ p such that every valid decomposition xyz (with |xy| ≤ p, |y| ≥ 1) produces some xy^i z not in L. The string choice is yours; the decomposition is the adversary's.

Check yourself: Have you shown the failure for every valid decomposition, not just one?

Context-free grammars and pushdown automata

A CFG generates strings through productions from a start symbol. A language is context-free if and only if some PDA recognizes it. CFLs are closed under union, concatenation, and Kleene star, but not under intersection or complement. Ambiguity means more than one parse tree for some string.

Check yourself: Can you derive the same string via two distinct leftmost derivations?

Turing machines and decidability

A Turing machine can read, write, and move on an unbounded tape. A language is decidable if some TM halts on every input and correctly accepts or rejects. A language is recognizable (recursively enumerable) if some TM accepts every member, but may loop on non-members. Decidable languages are closed under complement.

Check yourself: Does the machine halt on every input, or only on members of the language?

Undecidability and reductions

The halting problem is undecidable: no TM can decide whether an arbitrary TM halts on a given input. Reductions prove undecidability: if deciding L would let you decide a known undecidable problem, then L is also undecidable. The reduction must transform instances correctly in both directions.

Check yourself: Does your reduction map yes-instances to yes-instances and no-instances to no-instances?

Mistakes to avoid

Choosing a specific decomposition in a pumping lemma proof.
You choose the string w; the adversary chooses the decomposition. You must handle every valid split.
Assuming non-determinism increases the power of finite automata.
NFAs and DFAs recognize the same languages. The subset construction converts any NFA to a DFA.
Claiming a language is undecidable because it is infinite.
Many infinite languages are decidable. Undecidability requires a formal proof, typically via reduction.

Original teaching example · not a PYQ

Work through the reasoning

Original mini-example: prove that L = {a^n b^n | n ≥ 0} is not regular using the pumping lemma.

  1. Assume L is regular with pumping length p. Choose w = a^p b^p, which is in L and has length 2p ≥ p.
  2. Any decomposition xyz with |xy| ≤ p and |y| ≥ 1 places y entirely within the a-region: y = a^k for some k ≥ 1.
  3. Pumping down: xy^0z = a^(p−k) b^p. Since k ≥ 1, the count of a's is less than p, so this string is not in L.
  4. This contradicts the pumping lemma's guarantee, so L is not regular.

L = {a^n b^n | n ≥ 0} is not regular.

Try it before reading the answer

Construct a DFA over alphabet {0, 1} that accepts exactly those strings ending in 01.

Show answer and reasoning

Three states: q0 (start), q1, q2 (accept). Transitions: q0→q0 on 1, q0→q1 on 0, q1→q1 on 0, q1→q2 on 1, q2→q0 on 1, q2→q1 on 0.

q0 represents 'last symbol was 1 or no input yet'. q1 represents 'last symbol was 0'. q2 represents 'last two symbols were 01'. Only q2 accepts. Every state has exactly one transition per symbol.

Go deeper with free learning resources

Supplemental reading, not an official GATE reading list or an endorsement of these notes.

Apply this to the previous-year questions

Previous-year questions by year

This page shows 60 recent questions from the released archive, newest first. For older questions and complete papers, browse all GATE CS papers. Questions can carry more than one subject tag; counts are not marks weightage.

GATE CS 20268 questions

  1. Set 1 Q25Consider the following grammar where SS is the start symbol, and aa and bb are terminal symbols. S→aSbS∣bS∣ϵS \rightarrow aSbS \mid bS \mid \epsilon Which of the…MSQ · +1 marks · Medium
  2. Set 1 Q26Let MM be a nondeterministic finite automaton (NFA) with 6 states over a finite alphabet. Which of the following options CANNOT be the number of states in the…MSQ · +1 marks · Medium
  3. Set 1 Q51Let L1L_1 and L2L_2 be two languages over a finite alphabet, such that L1∩L2L_1 \cap L_2 and L2L_2 are regular languages. Which of the following statements is/are…MSQ · +2 marks · Hard
  4. Set 1 Q52Consider the following context-free grammar GG.…MSQ · +2 marks · Hard
  5. Set 2 Q13Which one of the following statements is equivalent to the following assertion? Turing machine MM decides the language L⊆{0,1}∗L \subseteq \{0,1\}^*MCQ · +1 marks · Easy
  6. Set 2 Q29Which of the following grammars is/are ambiguous?MSQ · +1 marks · Medium
  7. Set 2 Q47Consider the following two finite automata D1D_1 and D2D_2. [figure] Which of the following statements is/are true?MSQ · +2 marks · Medium
  8. Set 2 Q48Let Σ={a,b,c,d}\Sigma = \{a, b, c, d\} and let L={aibjckdℓ∣i,j,k,ℓ≥0}L = \{a^i b^j c^k d^\ell \mid i, j, k, \ell \ge 0\}. Which of the following constraints ensure(s) that the language LL…MSQ · +2 marks · Medium

GATE CS 202511 questions

  1. Set 1 Q19Consider the following context-free grammar GG, where S,AS, A, and BB are the variables (non-terminals), aa and bb are the terminal symbols, SS is the…MCQ · +1 marks · Easy
  2. Set 1 Q28A regular language LL is accepted by a non-deterministic finite automaton (NFA) with nn states. Which of the following statement(s) is/are FALSE?MSQ · +1 marks · Medium
  3. Set 1 Q44Consider the following two languages over the alphabet {a,b}\{a, b\}:…MCQ · +2 marks · Hard
  4. Set 1 Q45Consider the following two languages over the alphabet {a,b,c}\{a, b, c\}, where mm and nn are natural numbers. L1={ambmcm+n∣m,n≥1}L_1 = \{ a^m b^m c^{m+n} \mid m, n \ge 1 \}…MCQ · +2 marks · Medium
  5. Set 1 Q50Consider the following deterministic finite automaton (DFA) defined over the alphabet, Σ={a,b}\Sigma = \{a, b\}. Identify which of the following language(s) is/are…MSQ · +2 marks · Medium
  6. Set 2 Q24Which ONE of the following languages is accepted by a deterministic pushdown automaton?MCQ · +1 marks · Easy
  7. Set 2 Q25Let G1,G2G_1, G_2 be Context Free Grammars (CFGs) and RR be a regular expression. For a grammar GG, let L(G) denote the language generated by GG. Which ONE…MCQ · +1 marks · Easy
  8. Set 2 Q30Consider the two lists List I and List II given below: | List I | List II | |---|---| | (i) Context free languages | (a) Closed under union | | (ii)…MSQ · +1 marks · Medium
  9. Set 2 Q51Consider two grammars G1G_1 and G2G_2 with the production rules given below: G1:S→if E then S∣if E then S else S∣aG_1: S \to if\ E\ then\ S \mid if\ E\ then\ S\ else\ S \mid a…MSQ · +2 marks · Hard
  10. Set 2 Q52Let Σ={a,b,c}\Sigma = \{a, b, c\}. For x∈Σ∗x \in \Sigma^*, and α∈Σ\alpha \in \Sigma, let #α(x)\#_\alpha(x) denote the number of occurrences of α\alpha in xx. Which one or…MSQ · +2 marks · Medium
  11. Set 2 Q60Let Σ={1,2,3,4}\Sigma = \{1,2,3,4\}. For x∈Σ∗x \in \Sigma^*, let prod(x)prod(x) be the product of symbols in xx modulo 7. We take prod(ϵ)=1prod(\epsilon) = 1, where ϵ\epsilon is…NAT · +2 marks · Hard

GATE CS 20248 questions

  1. Set 1 Q23Let L1,L2L_1, L_2 be two regular languages and L3L_3 a language which is not regular. Which of the following statements is/are always TRUE?MSQ · +1 marks · Medium
  2. Set 1 Q50Consider the 5-state DFA MM accepting the language L(M)⊂(0+1)∗L(M) \subset (0 + 1)^* shown below. For any string w∈(0+1)∗w \in (0 + 1)^* let n0(w)n_0(w) be the number of 0's in…MSQ · +2 marks · Medium
  3. Set 1 Q59Let G=(V,Σ,S,P)G = (V, \Sigma, S, P) be a context-free grammar in Chomsky Normal Form with Σ={a,b,c}\Sigma = \{a, b, c\} and VV containing 10 variable symbols including the…NAT · +2 marks · Medium
  4. Set 1 Q61Consider the following two regular expressions over the alphabet {0,1}\{0,1\}: r=0∗+1∗r = 0^* + 1^* s=01∗+10∗s = 01^* + 10^* The total number of strings of length less…NAT · +2 marks · Medium
  5. Set 2 Q22Which one of the following regular expressions is equivalent to the language accepted by the DFA given below? [figure]MCQ · +1 marks · Medium
  6. Set 2 Q41Let MM be the 5-state NFA with ϵ\epsilon-transitions shown in the diagram below. [figure] Which one of the following regular expressions represents the…MCQ · +2 marks · Medium
  7. Set 2 Q52Consider a context-free grammar GG with the following 3 rules. S→aS,S→aSbS,S→cS \rightarrow aS, \quad S \rightarrow aSbS, \quad S \rightarrow c Let w∈L(G)w \in L(G). Let…MSQ · +2 marks · Medium
  8. Set 2 Q62Let L1L_1 be the language represented by the regular expression b∗ab∗(ab∗ab∗)∗b^*ab^*(ab^*ab^*)^* and L2={w∈(a+b)∗∣∣w∣≤4}L_2 = \{ w \in (a + b)^* \mid |w| \leq 4 \}, where ∣w∣|w| denotes…NAT · +2 marks · Medium

GATE CS 20236 questions

  1. Set 1 Q14Consider the Deterministic Finite-state Automaton (DFA) A\mathcal{A} shown below. The DFA runs on the alphabet {0,1}\{0, 1\}, and has the set of states…MCQ · +1 marks · Medium
  2. Set 1 Q19Consider the following definition of a lexical token id for an identifier in a programming language, using extended regular expressions: **letter**…MCQ · +1 marks · Easy
  3. Set 1 Q24Which of the following statements is/are CORRECT?MSQ · +1 marks · Easy
  4. Set 1 Q39Consider the context-free grammar GG below S→aSb∣XX→aX∣Xb∣a∣b\begin{aligned} S &\rightarrow aSb \mid X \\ X &\rightarrow aX \mid Xb \mid a \mid b \end{aligned} where SS…MCQ · +2 marks · Medium
  5. Set 1 Q40Consider the pushdown automaton (PDA) PP below, which runs on the input alphabet {a,b}\{a, b\}, has stack alphabet {⊥,A}\{\perp, A\}, and has three states…MCQ · +2 marks · Medium
  6. Set 1 Q63Consider the language LL over the alphabet {0,1}\{0, 1\}, given below: L={w∈{0,1}∗∣w does not contain three or more consecutive 1’s}L = \{w \in \{0, 1\}^* \mid w \text{ does not contain three or more consecutive 1's}\}…NAT · +2 marks · Medium

GATE CS 20225 questions

  1. Set 1 Q12Which one of the following regular expressions correctly represents the language of the finite automaton given below? [figure]MCQ · +1 marks · Medium
  2. Set 1 Q23Which of the following statements is/are TRUE?MSQ · +1 marks · Medium
  3. Set 1 Q46Which of the following is/are undecidable?MSQ · +2 marks · Medium
  4. Set 1 Q47Consider the following languages: L1={anwan∣w∈{a,b}∗}L_1 = \{a^n w a^n \mid w \in \{a, b\}^*\} L2={wxwR∣w,x∈{a,b}∗,∣w∣,∣x∣>0}L_2 = \{w x w^R \mid w, x \in \{a, b\}^*, |w|, |x| > 0\} Note that wRw^R is…MSQ · +2 marks · Hard
  5. Set 1 Q48Consider the following languages: L1={ww∣w∈{a,b}∗}L_1 = \{ww \mid w \in \{a, b\}^*\} L2={anbncm∣m,n≥0}L_2 = \{a^n b^n c^m \mid m, n \ge 0\} L3={ambncn∣m,n≥0}L_3 = \{a^m b^n c^n \mid m, n \ge 0\}…MSQ · +2 marks · Hard

GATE CS 202112 questions

  1. Set 1 Q11Suppose that L1L_1 is a regular language and L2L_2 is a context-free language. Which one of the following languages is NOT necessarily context-free?MCQ · +1 marks · Easy
  2. Set 1 Q15Consider the following statements. S1S_1: Every SLR(1) grammar is unambiguous but there are certain unambiguous grammars that are not SLR(1). S2S_2: For any…MCQ · +1 marks · Medium
  3. Set 1 Q22Let ⟨M⟩\langle M \rangle denote an encoding of an automaton MM. Suppose that Σ={0,1}\Sigma = \{0, 1\}. Which of the following languages is/are NOT recursive?MSQ · +1 marks · Medium
  4. Set 1 Q48Consider the following language. L={w∈{0,1}∗∣w ends with the substring 011}L = \{w \in \{0,1\}^* \mid w \text{ ends with the substring } 011\} Which one of the following deterministic finite…MCQ · +2 marks · Easy
  5. Set 1 Q49For a Turing machine MM, ⟨M⟩\langle M \rangle denotes an encoding of MM. Consider the following two languages.…MCQ · +2 marks · Medium
  6. Set 1 Q61In a pushdown automaton P=(Q,Σ,Γ,δ,q0,F)P = (Q, \Sigma, \Gamma, \delta, q_0, F), a transition of the form, [figure] where p,q∈Qp, q \in Q, a∈Σ∪{ϵ}a \in \Sigma \cup \{\epsilon\}, and…NAT · +2 marks · Hard
  7. Set 2 Q19Let L⊆{0,1}∗L \subseteq \{0, 1\}^* be an arbitrary regular language accepted by a minimal DFA with kk states. Which one of the following languages must necessarily…MCQ · +1 marks · Medium
  8. Set 2 Q22Let L1L_1 be a regular language and L2L_2 be a context-free language. Which of the following languages is/are context-free?MSQ · +1 marks · Medium
  9. Set 2 Q27Consider the following deterministic finite automaton (DFA). [figure] The number of strings of length 8 accepted by the above automaton is ________.NAT · +1 marks · Medium
  10. Set 2 Q46Consider the following two statements about regular languages: S1S_1: Every infinite regular language contains an undecidable language as a subset. S2S_2:…MCQ · +2 marks · Medium
  11. Set 2 Q51For a string ww, we define wRw^R to be the reverse of ww. For example, if w=01101w = 01101 then wR=10110w^R = 10110. Which of the following languages is/are…MSQ · +2 marks · Hard
  12. Set 2 Q57Which of the following regular expressions represent(s) the set of all binary numbers that are divisible by three? Assume that the string ϵ\epsilon is…MSQ · +2 marks · Hard

GATE CS 20206 questions

  1. Set 1 Q17Which one of the following regular expressions represents the set of all binary strings with an odd number of 1's?MCQ · +1 marks · Easy
  2. Set 1 Q18Consider the following statements. I. If L1∪L2L_1 \cup L_2 is regular, then both L1L_1 and L2L_2 must be regular. II. The class of regular languages is closed…MCQ · +1 marks · Medium
  3. Set 1 Q20Consider the language L={an∣n≥0}∪{anbn∣n≥0}L = \{a^n \mid n \geq 0\} \cup \{a^n b^n \mid n \geq 0\} and the following statements. I. LL is deterministic context-free. II. LL is…MCQ · +1 marks · Medium
  4. Set 1 Q36Which of the following languages are undecidable? Note that ⟨M⟩\langle M \rangle indicates encoding of the Turing machine M.…MCQ · +2 marks · Medium
  5. Set 1 Q42Consider the following languages. L1={wxyx∣w,x,y∈(0+1)+}L_1 = \{wxyx \mid w, x, y \in (0+1)^+\} L2={xy∣x,y∈(a+b)∗,∣x∣=∣y∣,x≠y}L_2 = \{xy \mid x, y \in (a+b)^*, |x| = |y|, x \neq y\} Which one of the…MCQ · +2 marks · Hard
  6. Set 1 Q61Consider the following language. L={x∈{a,b}∗∣number of a’s in x is divisible by 2 but not divisible by 3}L = \{x \in \{a, b\}^* \mid \text{number of } a\text{'s in } x \text{ is divisible by 2 but not divisible by 3}\} The…NAT · +2 marks · Medium

GATE CS 20194 questions

  1. Set 1 Q17If LL is a regular language over Σ={a,b}\Sigma = \{a, b\}, which one of the following languages is NOT regular?MCQ · +1 marks · Medium
  2. Set 1 Q25For Σ={a,b}\Sigma = \{a, b\}, let us consider the regular language L={x∣x=a2+3k or x=b10+12k,k≥0}L = \{x \mid x = a^{2+3k} \text{ or } x = b^{10+12k}, k \geq 0\}. Which one of the following…MCQ · +1 marks · Medium
  3. Set 1 Q41Which one of the following languages over Σ={a,b}\Sigma = \{a, b\} is NOT context-free?MCQ · +2 marks · Medium
  4. Set 1 Q44Consider the following sets: S1. Set of all recursively enumerable languages over the alphabet {0,1} S2. Set of all syntactically valid C programs S3. Set of…MCQ · +2 marks · Medium

Other GATE CS topics

Continue learning with Success Tracker

Keep working on Theory of Computation

Reading a solution is a useful start. In Success Tracker, you can attempt questions yourself, review mistakes and return to the topics that need another pass.

AI-powered practice· Unlimited practice on eligible plans
PYQs with solutions
Attempt available previous-year questions, then compare your reasoning with the worked solution. Coverage varies by stream.
Practice that adapts
Choose a topic, work on weaker areas and bookmark questions to revisit. Your attempts feed your progress tracking.
AI doubt support
Ask follow-up questions about a step or concept while practising, instead of stopping at the final answer.

Unlimited practice is available on eligible plans. Free practice and AI usage have limits; check the current plan allowances before choosing.

This page stays readable without an account. AI responses can be wrong; check them against the solution and source material.