GATE / CS ARCHIVE

SUBJECT COLLECTION

Theory of Computation

279 questions, newest first

Download PDF with answers Questions-only PDF

Browse topics
Topic weightage, 2017–2026

Average marks per 100-mark paper across the 15 papers of 2017–2026, with how many questions were asked in that time. Compare subjects

  1. Context-Free Grammars & Languages2.219 questions
  2. Finite Automata2.120 questions
  3. Decidability & Computability1.110 questions
  4. Regular Expressions & Languages19 questions
  5. Closure Properties & Language Hierarchy0.911 questions
  6. Pushdown Automata0.44 questions
  7. Other / Mixed Topics0.11 question
  8. Turing Machines0.11 question
  9. Complexity & Reductions Not in GATE 2027 syllabus00 questions · last asked 2015
Topic frequency by year
Questions by topic and year
Topic199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026
Finite Automata101001122243211121112212323211302332
Regular Expressions & Languages220232160120110232110114210011120220
Context-Free Grammars & Languages010121231200110423211010145111111224
Pushdown Automata000101121211002010100001110001101010
Turing Machines100000100000100000000000000000000001
Decidability & Computability000101103133411013000114132101320010
Complexity & Reductions000010000000110200000102200000000000
Closure Properties & Language Hierarchy030002103011002100011010112111201111
Other / Mixed Topics010101010001000000001002000010000000

Show
1 mark · MSQ
Report issue

Ambiguity and derivation uniqueness

Context-Free Grammars & Languages

Question 25, GATE 2026: For the grammar S→aSbS | bS | ε, decide: A the grammar is ambiguous; B abb has two distinct derivations; C abab has only one rightmost derivation; D the generated language is undecidable.
Tap to enlarge
Select all that apply
Answer & solution

Official answer: A, B, C

Givens and goal

For the grammar S→aSbS | bS | ε, decide: A the grammar is ambiguous; B abb has two distinct derivations; C abab has only one rightmost derivation; D the generated language is undecidable.

Approach

Exhibit different parse structures for the ambiguity claim, prove uniqueness for the specific other word, and use the decidability of context-free membership.

Step-by-step solution

Work with the grammar S → aSbS | bS | ε. Here ε denotes the empty string.

1. The string abb admits these two different leftmost derivations:

   - S ⇒ aSbS ⇒ abS ⇒ abbS ⇒ abb.
   - S ⇒ aSbS ⇒ abSbS ⇒ abbS ⇒ abb.
   In the first derivation, the extra b comes from the final S of the root production. In the second, it comes from the first S. Thus they represent different parse trees, not just different orders of expanding one tree. Both ambiguity (A) and the existence of two distinct derivations (B) follow.

2. For abab, the root must use aSbS because the word starts with a. Its explicit b must be the b in position 2 or position 4. Choosing position 4 would require the first S to generate ba. That is impossible: every nonempty word generated by S ends in b. To prove this invariant, bS ends in b if its child is empty or ends in b if its child does; aSbS has the same property through its explicit b and final child.
3. Consequently the explicit root b is in position 2, its first child is ε, and its final child generates ab. The latter has only the construction aSbS with both children empty. Therefore abab has exactly one parse tree and one rightmost derivation, establishing C. One rightmost derivation is S ⇒ aSbS ⇒ aSbaSbS ⇒ aSbaSb ⇒ aSbab ⇒ abab.
4. This is a context-free grammar. Membership in a context-free language is decidable, for example by converting to a suitable normal form and applying a finite parsing algorithm. Therefore the undecidability claim D is false.

Common error: Two unrestricted derivations can differ solely in expansion order. Ambiguity requires different parse trees, equivalently different leftmost derivations or different rightmost derivations; the witness above meets that stronger test.

Parse-tree distinction for abb can be made explicit by writing the root’s first and last S expansions as a pair. One tree has root a S b S with child words (ε,b); the other has child words (b,ε). Both concatenate to abb, but they attach the additional b to different children. This makes the ambiguity evidence structural, not just a consequence of expanding independent children in different orders.

Original paper, page 20 · Answer key

1 mark · MSQ
Report issue

Possible DFA sizes for a six-state NFA

Finite Automata

Question 26, GATE 2026: An NFA has six states over a finite alphabet. Which values cannot be the number of states of its minimal equivalent DFA: A 32, B 65, C 1, D 128?
Tap to enlarge
Select all that apply
Answer & solution

Official answer: B, D

Givens and goal

An NFA has six states over a finite alphabet. Which values cannot be the number of states of its minimal equivalent DFA: A 32, B 65, C 1, D 128?

Approach

Use subset construction for an upper bound and explicit languages to verify the offered feasible values.

Step-by-step solution

1. Subset construction represents each DFA state by a subset of the six NFA states. There are at most 26 = 64 such subsets, including the empty subset. Epsilon closures, if applicable, do not increase this bound.
2. Removing unreachable states and minimizing can only reduce that number. A minimal equivalent DFA therefore cannot require 65 or 128 states, establishing B and D.
3. One state is possible: a six-state NFA can accept every string. For an example with all six states reachable, use a cycle of six accepting states over a one-letter alphabet. Its language is universal and its minimal DFA has one accepting state.
4. To check that 32 is genuinely possible, use the binary language whose fifth symbol from the end is 1. A six-state NFA has one start state that loops on 0 and 1, can nondeterministically guess a 1 as that fifth-from-last symbol, and then traverses four more symbol transitions to an accepting state. A 32-state DFA stores the last five symbols, initially padded with zeros. Any distinct five-bit histories differ in some position j; appending j−1 zeros makes that position the fifth symbol from the end. The two resulting strings have different acceptance outcomes. Thus all 32 histories are distinguishable and the minimal DFA has exactly 32 states.

Common error: An upper bound alone rules out the oversized choices; an explicit witness is useful to verify that the smaller offered values really are possible.

Subset-construction interpretation: after reading a prefix, an NFA may be in several states at once. A deterministic simulator records exactly that reachable subset. With six possible states, each independently present or absent, there are 64 possible records; different prefixes need not reach all of them. This is why 64 is an upper bound, not a claim that every six-state NFA requires 64 DFA states.

Original paper, page 20 · Answer key

2 marks · MSQ
Report issue

What a regular intersection does not imply

Closure Properties & Language Hierarchy

Question 51, GATE 2026: Languages L₁ and L₂ share a finite alphabet. Both L₂ and L₁∩L₂ are regular. Which conclusions always hold: A L₁ regular; B L₁∪L₂ regular; C complement of L₂ context-free; D L₁ context-free?
Tap to enlarge
Select all that apply
Answer & solution

Official answer: C

Givens and goal

Languages L₁ and L₂ share a finite alphabet. Both L₂ and L₁∩L₂ are regular. Which conclusions always hold: A L₁ regular; B L₁∪L₂ regular; C complement of L₂ context-free; D L₁ context-free?

Approach

Use closure of regular languages under complement and their inclusion in context-free languages, then choose a regular L₂ that hides all complexity in L₁.

Step-by-step solution

1. Since L₂ is regular, its complement (relative to the shared alphabet’s full set of finite strings) is regular by closure under complement. Every regular language is context-free: for example, a finite automaton can be converted into a right-linear grammar, which is a context-free grammar. Therefore the complement of L₂ is context-free, so C must hold.
2. To test the other claims, let L₂=∅ and L₁={an bn cn:n≥0}. The alphabet {a,b,c} is finite as required.
3. The empty language is regular, and L₁∩L₂=∅ is also regular. Thus this choice satisfies both hypotheses no matter how complicated L₁ is.
4. The equal-three-block language L₁ is not context-free, hence is not regular either. The usual context-free pumping argument takes ap bp cp: a pumpable region of length at most p cannot span all three blocks, so pumping changes at most two counts or destroys the block order while at least one count remains p.
5. Therefore A and D fail. Also L₁∪L₂=L₁, so B fails for the same example.
6. Only C is guaranteed. Regularity of an intersection controls the part of L₁ inside L₂, not the potentially non-context-free part outside L₂.

Original paper, page 39 · Answer key

2 marks · MSQ
Report issue

Counting terminal-symbol invariants

Context-Free Grammars & Languages

Question 52, GATE 2026: The grammar is S→abaABA bba (spaces only separate symbols), A→aaBBA b | bB abaa, and B→aBb | ab. For a generated string s let n₁ count a’s and n₂ count b’s. Assess A: some n₁<n₂; B: always n₁≥n₂; C: some n₁>2n₂; D: always n₁≤2n₂.
Tap to enlarge
Select all that apply
Answer & solution

Official answer: B, D

Givens and goal

The grammar is S→abaABA bba (spaces only separate symbols), A→aaBBA b | bB abaa, and B→aBb | ab. For a generated string s let n₁ count a’s and n₂ count b’s. Assess A: some n₁<n₂; B: always n₁≥n₂; C: some n₁>2n₂; D: always n₁≤2n₂.

Approach

Track the pair of terminal counts through productions and prove invariant inequalities by induction rather than enumerate all words.

Step-by-step solution

Write a(w) and b(w) for the numbers of the two terminals in a generated word w.

1. Every expansion of B produces ak bk for some k≥1. Hence its two counts are equal.
2. For A's terminating alternative, a B expansion with k of each terminal gives counts a=k+3 and b=k+2. Thus b≤a≤2b.
3. Suppose a word derived from the recursive A child has counts x,y satisfying y≤x≤2y. The surrounding recursive production contributes two a terminals and one b terminal, plus two B words. If those B words together contribute K of each terminal, the new counts are x+K+2 and y+K+1. Their difference is (x−y)+1≥0. Also twice the new b count minus the new a count is (2y−x)+K≥0. Thus both inequalities are invariant under recursion.
4. The start production combines two A words, one B word and an outer string with three a terminals and three b terminals. Adding the counts preserves b≤a≤2b. Consequently every complete word satisfies the two bounds in B and D. The existential violations in A and C are impossible.

Common error: Counting only the explicitly written terminals of a production omits arbitrarily long balanced B expansions. The invariant accounts for them without enumerating strings.

Terminal-count bookkeeping

    Production component             Added a's   Added b's
    A→bB abaa, excluding B                 3           2
    A→aaBBA b, excluding B,B,A             2           1
    S→aba A B A bba, excluding A,B,A       3           3

For example, choosing B→ab and the terminating A alternative gives each A counts (4,3). The shortest choices in S therefore yield totals (3,3)+(4,3)+(1,1)+(4,3)=(12,10), consistent with both bounds. This example illustrates the invariant but the induction, not the example alone, proves it for arbitrarily deep recursion.

Original paper, page 40 · Answer key

1 mark · MCQ
Report issue

Deciding versus recognizing a language

Turing Machines

Question 13, GATE 2026: For a Turing machine M and L⊆{0,1}*, which is equivalent to M deciding L? A M halts everywhere; B M accepts all members of L; C M rejects all nonmembers; D M accepts every member and rejects every nonmember.
Tap to enlarge
Your answer
Answer & solution

Official answer: D

Givens and goal

For a Turing machine M and L⊆{0,1}*, which is equivalent to M deciding L? A M halts everywhere; B M accepts all members of L; C M rejects all nonmembers; D M accepts every member and rejects every nonmember.

Approach

A decider must be both correct and terminating on every input.

Step-by-step solution

1. A decision procedure answers the membership question for every finite binary input. When the input belongs to L the answer must be acceptance, and otherwise it must be rejection.
2. Both accepting and rejecting are halting outcomes. Thus D guarantees termination on every input as well as the correct result, and exactly captures the definition.
3. A alone permits an always-accept machine even when L is a proper subset of {0,1}*. B permits accepting nonmembers too, or failing to halt on them. C permits wrongly rejecting members or looping on them.
4. Therefore D is necessary and sufficient. A recognizer need only accept precisely the members, and may loop on nonmembers; a decider has the additional total-halting requirement.

Original paper, page 12 · Answer key

1 mark · MSQ
Report issue

Proving grammar ambiguity

Context-Free Grammars & Languages

Question 29, GATE 2026: Which grammars are ambiguous? A S→aSb|ε; B E→E+E|E*E|id; C S→aS|Sa|ε; D S→aS|ε.
Tap to enlarge
Select all that apply
Answer & solution

Official answer: B, C

Givens and goal

Which grammars are ambiguous? A S→aSb|ε; B E→E+E|E*E|id; C S→aS|Sa|ε; D S→aS|ε.

Approach

Exhibit two parse trees for ambiguous choices and explain uniqueness for the others.

Step-by-step solution

1. B generates id+id*id with root production E→E+E, whose right child expands by multiplication. It also generates the same string with root E→E*E, whose left child expands by addition. These are different tree structures, corresponding to id+(id*id) and (id+id)*id.
2. C already has two trees for the one-letter string a: use S→aS→aε, or S→Sa→εa. The root productions differ, so this is genuine ambiguity, not merely a different order of expanding independent nodes.
3. For A, every nonempty string is aⁿbⁿ. The first rule must be aSb and must be applied exactly n times, followed by ε. No alternative tree is possible for that n.
4. For D, a string aⁿ requires exactly n applications of aS followed by ε. Again the chain is unique.
5. Therefore B,C are ambiguous. The existence of an unambiguous grammar for the same language would not remove ambiguity from these particular grammars.

Original paper, page 22 · Answer key

2 marks · MSQ
Report issue

Languages of two three-step automata

Finite Automata

Question 47, GATE 2026: Transcribe the source automata as follows; s is the only start/accept state and omitted transitions reject. D1: s−0→u, s−1→v, u−0→w, u−1→z, w−0→s, w−1→s, z−0→s, v−0→t, t−1→s. D2: s−0→u, s−1→v, u−1→w, v−0→t, v−1→t and v−1→w, w−1→s, t−0→s. Select: A equal languages; B L(D1) proper subset of L(D2); C intersection {ε}; D (L(D1)∪L(D2))* is all binary strings of length divisible by 3.
Tap to enlarge
Select all that apply
Answer & solution

Official answer: C, D

Givens and goal

Transcribe the source automata as follows; s is the only start/accept state and omitted transitions reject. D1: s−0→u, s−1→v, u−0→w, u−1→z, w−0→s, w−1→s, z−0→s, v−0→t, t−1→s. D2: s−0→u, s−1→v, u−1→w, v−0→t, v−1→t and v−1→w, w−1→s, t−0→s. Select: A equal languages; B L(D1) proper subset of L(D2); C intersection {ε}; D (L(D1)∪L(D2))* is all binary strings of length divisible by 3.

Approach

Enumerate the three-edge returns to the accepting state and exploit unique block boundaries.

Step-by-step solution

1. In D1 the upper paths give 000 and 001 through u,w, and 010 through u,z. The lower path through v,t gives 101. Thus L(D1)={000,001,010,101}*, since every accepting return to s has exactly three symbols.
2. In D2 the path through u,w gives 011. Paths through v,t give 100 and 110, and the path through v,w gives 111. Hence L(D2)={011,100,110,111}*. The two transitions from v on 1 are nondeterministic alternatives, both included.
3. These two block sets are disjoint. A nonempty string of length divisible by three has a unique partition into successive three-bit blocks starting at position 1. Its first block cannot simultaneously belong to both sets, so the languages have no common nonempty word.
4. Both automata accept ε because their start state is accepting. Thus the intersection is exactly {ε}, proving C. The word 000 is accepted only by D1, refuting both equality and the claimed subset in A and B.
5. Together the two block sets contain all eight three-bit words. Kleene star of the union permits concatenations mixing blocks from either automaton, yielding every binary word of length 3k, including k=0. Conversely each concatenated component has length divisible by 3. This proves D.
6. Select C,D. The outer star in D is essential: the plain union need not accept a word whose successive blocks alternate between the two sets. Transitions were verified on the source image.

Original paper, page 33 · Answer key

2 marks · MSQ
Report issue

Context-free constraints on four blocks

Context-Free Grammars & Languages

Question 48, GATE 2026: Consider strings a^i b^j c^k d^ℓ with i,j,k,ℓ≥0. Which restrictions yield context-free languages? A i+k=j+ℓ; B i=k and j=ℓ; C i=ℓ and j=k; D i+j=k+ℓ.
Tap to enlarge
Select all that apply
Answer & solution

Official answer: A, C, D

Givens and goal

Consider strings ai bj ck d^ℓ with i,j,k,ℓ≥0. Which restrictions yield context-free languages? A i+k=j+ℓ; B i=k and j=ℓ; C i=ℓ and j=k; D i+j=k+ℓ.

Approach

Give stack constructions for the positive choices and a pumping-lemma contradiction for the crossing equalities.

Step-by-step solution

1. For A, scan the string while tracking block order a*b*c*d* in finite control. Maintain the signed difference (#a+#c)−(#b+#d). Store its sign in the finite state and its absolute value as repeated stack symbols. On a or c, add 1; on b or d, subtract 1, popping if this cancels the current sign and pushing otherwise. Accept exactly when the final difference is zero. This is a pushdown automaton, so A is context-free.
2. For D, check block order, push one marker for every a or b, and pop one for every c or d. Reject an attempt to pop an empty counter and accept exactly with zero balance at the end. This enforces i+j=k+ℓ.
3. For C the equalities are nested. The grammar S→aSd|T, T→bTc|ε generates precisely ai bj cj di: outer recursion matches a with d, inner recursion matches b with c. Hence C is context-free.
4. For B suppose a context-free pumping length p exists, and take w=ap bp cp dp. Every decomposition w=uvxyz with |vxy|≤p and |vy|>0 has its pumping window in one block or at most two adjacent blocks. It cannot reach both members of either matching pair a/c or b/d.
5. Pump v and y away, using exponent 0. At least one block count decreases, and its matching nonadjacent block is untouched. The equality i=k or j=ℓ therefore fails. This contradicts the pumping lemma for every allowed decomposition, so B is not context-free.
6. The correct selections are A,C,D. Two independent crossing counters cannot in general be handled by the single last-in-first-out store used for nested matching.

Original paper, page 34 · Answer key

1 mark · MCQ
Report issue

Deriving a grammar’s two alternatives

Context-Free Grammars & Languages

Question 19, GATE 2025: A grammar has start symbol S and productions S→aaB | Abb, A→a | aA, B→b | bB. Choose its language: A {a²b^n:n≥1}∪{a^nb²:n≥1}; B {a^nb^(2n):n≥1}∪{a^(2n)b^n:n≥1}; C {a^nb^n:n≥1}; D {a^(2n)b^(2n):n≥1}.
Tap to enlarge
Your answer
Answer & solution

Official answer: A

Approach: First identify what each helper nonterminal can generate, then substitute into each start production.
A→a is the base case. Each application of A→aA adds one a before eventually taking the base case, so A generates exactly an for n≥1. Similarly B generates exactly bn for n≥1. Neither can generate the empty string.
Taking S→aaB fixes the number of a’s at two and allows any positive number of b’s. Taking S→Abb allows any positive number of a’s and fixes the number of b’s at two. The language is the union of these alternatives, which is A.
For example aabbb is generated by the first branch, and ab b (the word abb) by the second. The grammar does not synchronize the two counts, so the equality and ratio conditions in B–D are unjustified. The common word aabb belongs to both branches but is counted just once in the language.

Original paper, page 19 · Answer key

1 mark · MSQ
Report issue

Bounding DFA states after subset construction

Finite Automata

Question 28, GATE 2025: A regular language L is accepted by an n-state NFA. Which statements are false? A L may also have an NFA with fewer than n states; B L may have a DFA with fewer than n states; C some DFA for L has at most 2^n states; D every DFA for L has more than 2^n states.
Tap to enlarge
Select all that apply
Answer & solution

Official answer: D

Approach: Apply subset construction and distinguish “may” from a guaranteed reduction.
When determinizing an NFA, a DFA state records the set of NFA states that can currently be active. An n-element set has 2n subsets, so the construction uses at most 2n states, including the empty subset if needed. Unreachable subsets can be removed. This proves C and directly contradicts D, making D the false statement.
The NFA in the premise is not required to be minimal. For example, an automaton for all strings can be padded with redundant states although a one-state accepting automaton already recognizes that language. Therefore A and B describe genuine possibilities for a nonminimal supplied NFA.
They do not assert that every n-state NFA can be reduced, nor a strict reduction at n=1 in the conventional nonempty-state model. The exponential bound is an upper bound that can be necessary for some languages, not a claim that every language needs exponentially many DFA states.

Original paper, page 28 · Answer key

2 marks · MCQ
Report issue

Separating two repeated-border languages

Regular Expressions & Languages

Question 44, GATE 2025: Over {a,b}, define L1={αβα | α∈{a,b}+ and β∈{a,b}+}, and L2={αβα | α∈{a}+ and β∈{a,b}+}. Both α and β must be nonempty. Which is correct? A both regular; B only L1 regular; C only L2 regular; D neither regular.
Tap to enlarge
Your answer
Answer & solution

Official answer: C

Approach: Simplify L2 directly, then prove L1 nonregular using intersection with a carefully chosen regular language.
Every L2 word begins and ends in a and has length at least three. Conversely any such word can use α=a and the nonempty intervening substring as β. Hence L2=a(a|b)+a, which is regular.
For L1 intersect with R={abr aabs:r,s≥1}. R is regular. A word in R has exactly three a’s. If it equals αβα, the two disjoint copies of α cannot each contain two a’s; because α starts at the initial a, it contains exactly one a. It also ends in b, and its suffix copy must start at the third a: starting at the second a would include two a’s. Thus α=abs. This is a prefix exactly when r≥s. The remaining β=br−sa is nonempty. Therefore L1∩R={abr aabs:r≥s≥1}.
If this intersection were regular with pumping length p, choose w=abp aabp. Any pumpable nonempty substring within the first p positions either includes the initial a or consists only of b’s from the first block. Pumping it down in the first case destroys the required initial a; in the second case it reduces r below s. Every permitted decomposition fails, contradicting the pumping lemma.
Regular languages are closed under intersection, so L1 cannot be regular. L2 is regular and L1 is not: C. A repeated substring does not automatically prove nonregularity; the explicit restriction and pumping argument supply the proof.

Original paper, page 44 · Answer key

2 marks · MCQ
Report issue

Comparing two three-block context-free languages

Context-Free Grammars & Languages

Question 45, GATE 2025: For m,n≥1, L1={a^m b^m c^(m+n)} and L2={a^m b^n c^(m+n)}. Which is true? A both context-free; B only L1 context-free; C only L2 context-free; D neither context-free.
Tap to enlarge
Your answer
Answer & solution

Official answer: C

Approach: Give a constructive grammar for L2 and a pumping-lemma contradiction for L1.
L2 is generated by S→aSc | aTc and T→bTc | bc. Each use of S adds one a and one trailing c, with at least one a forced before moving to T. Each T production similarly pairs a b with a c and forces at least one b. The derived words are exactly am bn cm+n, so L2 is context-free.
Suppose L1 were context-free with pumping length p. Choose w=ap bp cp+1, which is in L1 with m=p,n=1. In a pumping decomposition w=uvxyz, |vxy|≤p and |vy|>0. The window cannot touch both the a and c blocks, because it would have to span all p b’s between them.
Let Δa,Δb,Δc count those symbols in the pumped parts v and y. If pumping disrupts block order, it already leaves L1. Otherwise, if Δa≠Δb, pumping down or up breaks equality of a and b counts. If Δa=Δb>0, then Δc=0; pumping up makes the common count at least p+1 while c remains p+1, violating the strict requirement c>m. Finally if Δa=Δb=0, then Δc>0; pumping down leaves at most p c’s while a=b=p, again violating c>m.
All possibilities fail. Thus L1 is not context-free, giving C. The unrestricted extra c’s in L1 do not eliminate the need to enforce both equality and a strict count comparison.

Original paper, page 45 · Answer key

2 marks · MSQ
Report issue

Interpreting a suffix-tracking DFA

Finite Automata

Question 50, GATE 2025: A DFA over {a,b} has states q0,q1,q2,q3, start q0 and sole accepting state q3. Transitions on (a,b) are q0→(q0,q1), q1→(q2,q1), q2→(q0,q3), q3→(q2,q1). Which language does it recognize? A words with an even number of b’s; B words containing bab; C words ending in bab; D words avoiding aba.
Tap to enlarge
Select all that apply
Answer & solution

Official answer: C

Approach: Assign each state the longest suffix of the input read so far that is also a prefix of the pattern bab.
The prefixes are ε,b,ba,bab, corresponding respectively to q0,q1,q2,q3. At q0 an a leaves no nonempty matching suffix, while b starts the match. At q1 another b still leaves suffix b, while a extends it to ba. At q2, b completes bab, but a leaves no matching suffix and returns to q0.
After reaching q3, an a leaves suffix ba and returns to q2; a b leaves suffix b and returns to q1. Therefore acceptance records that the current complete word ends in bab, not merely that bab appeared at some earlier position. This proves C.
B fails because baba contains bab but ends at nonaccepting q2. A fails because the empty word has an even b-count but is rejected. D fails because a avoids aba yet is rejected.

Original paper, page 50 · Answer key

1 mark · MCQ
Report issue

Pushdown Automata

Question 24, GATE 2025: Which family is guaranteed to be accepted by deterministic pushdown automata, meaning that every language in the listed family has some DPDA?
Options: A. every regular language; B. every context-free language; C. every language accepted by an NPDA; D. every decidable language.
Tap to enlarge
Your answer
Answer & solution

Official answer: A

A DPDA can simulate a DFA: copy the DFA's finite control and transitions, and leave the stack unused except for its bottom marker. Therefore every regular language has a deterministic pushdown recognizer, establishing A.

Nondeterministic PDAs recognize exactly the context-free languages, while deterministic PDAs recognize only the deterministic context-free languages, a proper subclass. Thus B and C make the same overly broad guarantee. For example, the unrestricted palindrome language over {a,b} requires guessing the midpoint in the usual PDA construction and is not deterministic context-free; a visible midpoint marker would change the problem.

D is even broader. A decidable language such as {an bn cn:n≥0} can be decided by a Turing machine but is not context-free, so no PDA, deterministic or nondeterministic, accepts it. These statements concern existence of a suitable machine for each language, not one fixed machine that accepts every language at once. Answer: A.

Original paper, page 20 · Answer key

1 mark · MCQ
Report issue

Decidability & Computability

Question 25, GATE 2025: Given arbitrary context-free grammars G1,G2 and a regular expression R, which decision problem has an algorithm that always terminates with the correct yes/no answer?
Options: A. L(G1)=L(G2)? B. L(G1)∩L(G2)=∅? C. L(G1)=L(R)? D. L(G1)=∅?
Tap to enlarge
Your answer
Answer & solution

Official answer: D

CFG emptiness is decidable by identifying productive nonterminals, those that can derive a string containing only terminals. Start by marking a nonterminal with a production containing no nonterminals, including an epsilon production. Repeatedly mark the left side of a production whenever all nonterminals on its right side are already marked. Since there are finitely many nonterminals and marks are only added, this process terminates. The generated language is nonempty exactly when the start symbol is marked. Hence D is decidable.

General equivalence of two CFGs (A) and emptiness of the intersection of two CFLs (B) are undecidable. Do not infer B from single-CFG emptiness: CFLs are not closed under intersection, so there need not be an effectively constructed CFG for the intersection.

C is also undecidable in general despite one language being regular. If it were decidable, choose R to denote Σ*. It would then decide whether an arbitrary CFG generates every string over Σ, the undecidable CFG universality problem. The asymmetry matters: containment of a CFL in a regular language can be decided using intersection with a regular complement, but equality also requires the reverse containment. Answer: D.

Original paper, page 21 · Answer key

1 mark · MSQ
Report issue

Closure Properties & Language Hierarchy

Question 30, GATE 2025: Match language families (i) context-free, (ii) recursive/decidable, (iii) regular with properties (a) closed under union, (b) not closed under complementation, (c) closed under intersection. Select every option whose three matches are all valid.
A. i→a, ii→b, iii→c.
B. i→b, ii→a, iii→c.
C. i→b, ii→c, iii→a.
D. i→a, ii→c, iii→b.
Tap to enlarge
Select all that apply
Answer & solution

Official answer: B, C

Context-free languages are closed under union: introduce a new start symbol that chooses either grammar. They are not closed under complementation. One way to understand the latter fact is that closure under both union and complement would, by De Morgan's law, imply closure under intersection, which CFLs do not have.

Decidable languages are closed under union and intersection because both deciders halt: run them and combine their Boolean answers with OR or AND. They are closed under complement by swapping acceptance and rejection. Regular languages have all three closures: product automata handle union/intersection, and swapping accepting states in a complete DFA handles complement.

Now inspect each full option. A incorrectly assigns nonclosure under complement to decidable languages. B correctly assigns CFL nonclosure, decidable union closure, and regular intersection closure. C correctly assigns CFL nonclosure, decidable intersection closure, and regular union closure. D incorrectly denies complement closure to regular languages. Therefore B and C are correct. This is not a one-to-one matching puzzle: a family can possess more than one listed closure property.

Original paper, page 24 · Answer key

2 marks · MSQ
Report issue

Regular Expressions & Languages

Question 52, GATE 2025: Let #a(w),#b(w) count symbol occurrences. Which languages are regular?
A. {a^m b^n:m,n≥0}.
B. {a,b}* ∩ {a^m b^n c^(m−n):m≥n≥0}.
C. {w∈{a,b}*: #a(w)≡2 (mod 7), #b(w)≡3 (mod 9)}.
D. {w∈{a,b}*: #a(w)≡2 (mod 7), #a(w)=#b(w)}.
Tap to enlarge
Select all that apply
Answer & solution

Official answer: A, C

A is described by the regular expression a*b*, so it is regular. The two block lengths are independent; there is no equality constraint to remember.

For B, membership in {a,b}* excludes every c. Hence m−n=0 and the intersection is exactly {an bn:n≥0}. This is nonregular: for a pumping length p, any allowed pumping segment in the initial a-block of ap bp changes the a-count without changing the b-count.

C needs only finite modular information. A DFA state (r,s) stores #a modulo 7 and #b modulo 9. On a update r to r+1 modulo 7; on b update s to s+1 modulo 9. Start at (0,0), accept (2,3). The 7·9=63-state construction proves regularity, without claiming a state-minimality result.

For D, intersect with the regular language a*b*. If D were regular, this intersection K={ak bk:k≡2 mod 7} would also be regular. Choose an allowed k greater than a proposed pumping length. Any pumping segment within the first p positions consists only of a's; pumping it changes one count and breaks equality. Thus K, and therefore D, is nonregular. A modular restriction alone is finite-state, but it does not eliminate an unbounded equality requirement. Select A,C.

Original paper, page 40 · Answer key

2 marks · NAT
Report issue

Finite Automata

Question 60, GATE 2025: Let Σ={1,2,3,4}. For a string x, prod(x) is the product of its symbols modulo 7, with prod(ε)=1. Define L={x:prod(x)=2}. How many states does a minimum DFA for L have?
Tap to enlarge
Answer & solution

Official answer: 6

Step through it (2 parts)

No input symbol is divisible by 7, so a product can never have residue 0. A DFA can keep one of the six nonzero residues 1,…,6 as its state. Start in state 1, use transition δ(r,a)=ra mod 7 for a∈{1,2,3,4}, and accept only state 2. This proves that six states suffice.

To prove minimality, first show all six residues are reachable. Repeated input 3 gives the cycle 1→3→2→6→4→5→1, so every state is reached by some power of the string symbol 3.

Next distinguish two different residues r and s. Nonzero residues modulo the prime 7 have multiplicative inverses. Choose a suffix whose product is t=2r−1 mod 7. Such a suffix exists because powers of 3 realize every nonzero residue. Appending it to a prefix with product r yields rt=2 and is accepted. Appending it to a prefix with product s cannot yield 2: st=rt would imply s=r after cancellation. Thus every pair of reachable states has different residual languages.

By the DFA distinguishability criterion, none of these states can be merged. Exactly six are necessary and sufficient; no seventh zero-residue state is reachable or needed for this alphabet. Answer: 6.

Original paper, page 45 · Answer key

1 mark · MSQ
Report issue

Apply regular-language closure carefully

Closure Properties & Language Hierarchy

Question 23, GATE 2024: L1 and L2 are regular languages and L3 is not regular, over a common alphabet. Which statements always hold? A L1=L2 iff L1∩complement(L2)=∅. B L1∪L3 is nonregular. C complement(L3) is nonregular. D complement(L1)∪complement(L2) is regular.
Tap to enlarge
Select all that apply
Answer & solution

Official answer: C, D

Approach: Use closure under complement and union to prove universal claims, and a single legal counterexample to reject each false universal claim.
1. A is false. L1∩complement(L2)=∅ means only L1⊆L2. For instance L1=∅ and L2={a} satisfy this condition without being equal. Equality would require both inclusions.
2. B is false. Choose L1=Σ*, which is regular. Its union with any L3 is Σ*, so the union can be regular even though L3 is not.
3. C is true by contradiction. If complement(L3) were regular, complementing it again would make L3 regular, since regular languages are closed under complement. This contradicts the premise.
4. D is true because complement(L1) and complement(L2) are each regular, and their union is regular by union closure.
Answer: C and D. A nonregular input does not automatically make the result of every language operation nonregular.

Original paper, page 16 · Answer key

2 marks · MSQ
Report issue

Minimize a DFA and test distinguishability

Finite Automata

Question 50, GATE 2024: A DFA has start state 1 and only accepting state 1. For inputs (0,1), its transitions are: state 1→(2,4); state 2→(3,1); state 3→(1,2); state 4→(1,5); state 5→(4,1). Let n0(w),n1(w) count symbols. Which statements are false? A States 2 and 4 are distinguishable. B States 3 and 4 are distinguishable. C States 2 and 5 are distinguishable. D Every w with n0(w)=n1(w) is accepted.
Tap to enlarge
Select all that apply
Answer & solution

Official answer: B, C

Approach: Group states with the same future acceptance behavior, then interpret the resulting quotient machine.
1. Consider classes C0={1}, C1={2,5}, C2={3,4}. Only C0 accepts. From either member of C1, input 0 leads to C2 and input 1 to C0. From either member of C2, 0 leads to C0 and 1 to C1. From C0, 0 leads to C1 and 1 to C2.
2. This is a stable partition: members of each class have the same accepting status and transition to the same classes for each symbol. Induction on suffix length therefore proves that states 2 and 5 are equivalent, as are states 3 and 4. Claims B and C are false.
3. States 2 and 4 are distinguishable: suffix 1 sends 2 to accepting state 1 but sends 4 to nonaccepting state 5. Thus A is true.
4. Label C0,C1,C2 by residues 0,1,2. A 0 adds 1 modulo 3 and a 1 subtracts 1. Starting at residue 0, the machine accepts exactly when n0−n1 is divisible by 3. Equal counts satisfy this condition, so D is true.
Answer: B and C, because the question asks for false statements.

Original paper, page 31 · Answer key

2 marks · NAT
Report issue

Count productions in a CNF derivation

Context-Free Grammars & Languages

Question 59, GATE 2024: A context-free grammar in Chomsky Normal Form has terminals {a,b,c} and 10 variables including start symbol S. It derives w=a³⁰b³⁰c³⁰. How many rule applications occur in a derivation S⇒*w?
Tap to enlarge
Answer & solution

Official answer: 179

Approach: In Chomsky Normal Form, a nonempty derivation uses binary-variable rules A→BC and terminal rules A→a. Count each kind using the final word length.
1. The word contains 30+30+30=90 terminal symbols. Each requires exactly one terminal-producing rule application, so there are 90 such applications.
2. Initially there is one variable occurrence. Each binary rule replaces one variable with two and therefore increases the total number of current symbol occurrences by one. Terminal rules replace one symbol with one and do not change that total.
3. To grow from one symbol to a final string of 90 symbols requires exactly 89 binary-rule applications. Equivalently, the variable branching tree is full binary with 90 leaves and 89 internal branching nodes.
4. Total rule applications =90+89=179.
Answer: 179. The ten available variable names can be reused and do not bound the number of variable occurrences. Derivation order does not change these counts; the CNF epsilon exception is irrelevant to this nonempty word.

Original paper, page 34 · Answer key

2 marks · NAT
Report issue

Count the complement of two regular languages

Regular Expressions & Languages

Question 61, GATE 2024: Over {0,1}, r=0*+1* and s=01*+10*, where + means union and * means Kleene star. Count strings of length at most 5 that belong to neither language, including the empty string in the universe.
Tap to enlarge
Answer & solution

Official answer: 44

Approach: Count all short binary strings, subtract the union of the two languages, and account for their overlap.
1. There are Σ from length 0 to 5 of 2^length =1+2+4+8+16+32=63 strings. The empty string is the single length-zero string.
2. Language r contains ε and, at each positive length 1–5, the all-zero and all-one strings. Thus |r within the limit|=1+2×5=11. Count ε only once even though both starred expressions generate it.
3. Language s contains a leading 0 followed by only 1s, or a leading 1 followed by only 0s. It has two strings at each length 1–5 and none at length zero, so its count is 10.
4. The overlap is exactly {0,1}. Longer strings in s contain both symbols, so cannot be in r. Inclusion-exclusion gives union size 11+10−2=19.
5. The complement count is 63−19=44.
Answer: 44. A lengthwise check gives 0,0,0,4,12,28 excluded strings at lengths 0 through 5, again totaling 44.

Original paper, page 35 · Answer key

1 mark · MCQ
Report issue

A two-state parity automaton

Finite Automata

Question 22, GATE 2024: A DFA has start state E (nonaccepting) and state O (accepting). Input 0 loops at either state; input 1 switches E↔O. Which regex represents it? A 0*1(0+10*1)*; B 0*(10*11)*0*; C 0*1(010*1)*0*; D 0(1+0*10*1)*0*. Here + is union.
Tap to enlarge
Your answer
Answer & solution

Official answer: A

Approach: Assign a parity invariant to each state, then check the loop structure in the regex.

1. Derivation. It accepts exactly strings with an odd number of 1s. The initial 0*1 enters the accepting state; each following 0 stays there and each 10*1 makes a round trip through the other state. Therefore0*1(0+10*1)*, option A. B accepts epsilon, C cannot generate 111, and D requires an initial 0, so each differs.

2. Explanation and checks. After any prefix, E means an even number of ones and O means an odd number. In A, the leading 0*1 contributes the first one; each subsequent block contributes either zero ones or exactly two, preserving odd parity. Conversely, after the first one, any remaining ones can be paired, with intervening zeros accommodated by the blocks. The short strings ε, 111 and 1 distinguish B, C and D respectively from the required language.

Original paper, page 16 · Answer key

2 marks · MCQ
Report issue

Split an epsilon-NFA into accepting path families

Finite Automata

Question 41, GATE 2024: NFA states are 1(start),2,3,4,5, with 2 and 5 accepting. Epsilon edges: 1→2,1→4,3→5. Edges labeled 0: 2→3 and 3→2. Edges labeled 1: 4→5 and 5→4. All other transitions absent. Choose regex: A (00)*+1(11)*; B 0*+(1+0(00)*)(11)*; C (00)*+(1+(00)*)(11)*; D 0+ +1(11)*+0(11)*. Here outer + denotes union; 0+ in D means one or more zeros.
Tap to enlarge
Your answer
Answer & solution

Official answer: B

Approach: Enumerate paths ending in each accepting state and track the parity before and after the epsilon jump.

1. Derivation. The initial epsilon choice reaches state2 or 4. State2 accepts an even number of 0s; after an odd number of 0s the machine is in 3 and can take epsilon to accepting 5, after which an even number of 1s returns to 5. The direct state4 branch accepts an odd number of 1s. Thus the language is(00)* + 0(00)*(11)* + 1(11)*. The pure even/odd zero cases together equal 0*, so it can be written 0*+(1+0(00)*)(11)*, option B.

2. Explanation and checks. Staying in the upper component accepts an even zero count; reaching 3 requires an odd zero count and jumping to 5 then permits an even one count. Starting at 4 instead requires an odd one count. A misses the accepted word 0. C wrongly accepts 11 (take ε from (00)* and one pair of ones), whereas the NFA cannot accept pure even-positive ones. D misses ε, which is accepted via 1→2. These witnesses isolate B beyond merely manipulating algebraic expressions.

Original paper, page 28 · Answer key

2 marks · MSQ
Report issue

Count terminals by production applications

Context-Free Grammars & Languages

Question 52, GATE 2024: Grammar S→aS | aSbS | c generates w. Let na,nb,nc count the respective terminals in w. Which always hold? A na>nb; B na>nc−2; C nc=nb+1; D nc=2nb.
Tap to enlarge
Select all that apply
Answer & solution

Official answer: B, C

Approach: Count how each production changes both the terminal totals and the outstanding nonterminals.

1. Derivation. Let u count applications of S→aS and v count applications of S→aSbS. Then na=u+v and nb=v. A derivation starts with one S; unary rules leave the number of outstanding S unchanged, binary rules increase it by one, and S→c decreases it by one. Thus nc=v+1, proving C. Also na≥v=nc−1>nc−2, proving B. A fails for w=c, where both a and b counts are 0; D also fails for c, whose c count is 1 and b count 0.

2. Explanation and checks. Each binary rule contributes one b and creates one additional S requiring eventual termination by a c-rule. Starting with one S therefore requires exactly one more terminating c-rule than binary rules. Unary aS rules can add any extra a’s without changing b or c counts. Consequently na−nb equals their nonnegative number; it may be zero, so A’s strict inequality is too strong. In B the weaker strict bound still holds because na≥nc−1 is an integer stronger than na>nc−2.

Original paper, page 36 · Answer key

2 marks · NAT
Report issue

Count short strings with odd a-parity

Regular Expressions & Languages

Question 62, GATE 2024: L1 is described by b*ab*(ab*ab*)*. L2 contains all strings over {a,b} of length at most four. How many strings belong to both?
Tap to enlarge
Answer & solution

Official answer: 15

Approach: Interpret the regex structurally before doing a length-by-length count.

1. Derivation. The regular expression has one initial a followed by any number of pairs of a’s, with arbitrary b runs between and around them. It therefore accepts exactly the strings with an odd positive number of a’s. For any positive length ℓ exactly half of the 2^ℓ binary strings have odd a-parity, by flipping one fixed position. Lengths1 through 4 contribute 1+2+4+8=15; ε has even parity and is excluded.

2. Explanation and checks. The one initial a plus any number of pairs makes the a-count odd; the b* runs admit arbitrary b’s before, between and after those a’s. For length 3 the allowable counts are one a or three a’s, giving C(3,1)+C(3,3)=4. For length 4 they give C(4,1)+C(4,3)=8. Lengths 1 and 2 contribute one and two. The empty string has no a and cannot match the mandatory initial a.

Original paper, page 39 · Answer key

1 mark · MCQ
Report issue

Finite Automata

Question 14, GATE 2023: A DFA over {0,1} starts in s, accepts only in p, and has transitions s:0→r,1→p; p:0→p,1→q; q:0→r,1→p; r:0→r,1→r. Which expression describes its language? A 1(0*11)*; B 0(0+1)*; C 1(0+11)*; D 1(110*)*.
Tap to enlarge
Your answer
Answer & solution

Official answer: C

The initial 1 enters accepting p; an initial 0 reaches the dead state. At p, 0 loops, while 11 follows p→q→p. A0 at q is rejected, so all accepted suffixes are concatenations of 0 and 11. This gives 1(0+11)*, option C. For example 10 is accepted but not generated by A or D.

Teaching detail. Every accepting run must first consume 1 to reach p. From p there are two ways to return to p without entering the trap: consume a single 0, or consume the pair 11 through q. Any number of these complete return segments is allowed, including none, so the one-letter string 1 is accepted. A suffix ending after the first 1 of a pair stops at nonaccepting q. This run decomposition proves both that every accepted word has the expression's form and that every generated word is accepted.

Original paper, page 11 · Answer key

1 mark · MSQ
Report issue

Closure Properties & Language Hierarchy

Question 24, GATE 2023: Which language classes are closed under intersection with another language in the same class? A regular; B context-free; C recursive (decidable); D recursively enumerable (recognizable). Select all.
Tap to enlarge
Select all that apply
Answer & solution

Official answer: A, C, D

Regular intersection uses a product automaton. Decidable-language intersection runs both halting deciders and accepts iff both accept. For recursively enumerable languages, dovetail the recognizers and accept once both have accepted, giving a recognizer. CFL intersection is not closed: {aⁿbⁿcᵐ}∩{aᵐbⁿcⁿ}={aⁿbⁿcⁿ}, which is not context-free. Thus A, C, D.

Teaching detail. For regular languages, a product DFA tracks both component states and accepts only when both components accept. For decidable languages, running the two deciders sequentially terminates, whether the answer is yes or no. For recognizers, a rejecting computation might never terminate, so dovetailing makes explicit that an accepting computation in each recognizer will eventually be observed. The CFL counterexample uses one language checking equality of a's and b's and another checking equality of b's and c's; requiring both produces the standard non-CFL of three equal counts.

Original paper, page 22 · Answer key

2 marks · MCQ
Report issue

Context-Free Grammars & Languages

Question 39, GATE 2023: For grammar S→aSb|X and X→aX|Xb|a|b with start S, identify the language: A (a+b)*; B a*(a+b)b*; C a*b*(a+b); D a nonregular language.
Tap to enlarge
Your answer
Answer & solution

Official answer: B

X generates every nonempty string of the form aⁱbʲ: its alternatives prepend a or append b and terminate at a or b. These operations never introduce a b before an a. Wrapping with S→aSb preserves that form and adds no strings beyond those already generated by X. Thus L(G)=a*b* minus epsilon, equivalently a*(a+b)b*, option B. The grammar may be context-free while its generated language is regular.

Teaching detail. For completeness, any aⁱbʲ with i+j≥1 can be derived from X. If i≥1, terminate with a and use i−1 prepending steps plus j appending steps. If i=0 and j≥1, terminate with b and append j−1 further b's. Conversely every X-production preserves the a-before-b ordering and cannot create ε. The S wrapping rule also preserves this ordering and nonemptiness. Hence it neither removes any X-generated word nor introduces a word outside the claimed regular language.

Original paper, page 40 · Answer key

2 marks · MCQ
Report issue

Pushdown Automata

Question 40, GATE 2023: An empty-stack-accepting PDA starts in s with stack ⊥. In s, a/⊥/A⊥ and a/A/AA push one A. Transition s→p and the loop at p are b/A/ε. Transitions s→q and p→q are ε/A/ε. At q, ε/A/ε and ε/⊥/ε empty the stack. Describe its accepted language over {a,b}, consuming all input.
Tap to enlarge
Your answer
Answer & solution

Official answer: A

In s each a pushes A. The first b moves to p and pops A, and further b’s pop more A. Entry to the cleanup state q requires an A at the stack top and pops it, so at least one A must remain after all input has been read. Then q removes the remaining stack symbols, including the bottom marker. Consequently input is aᵐbⁿ with m≥1 and 0≤n<m, option A. Equal counts leave only the bottom symbol in s/p and cannot enter q; epsilon is not accepted.

Teaching detail. After reading m a's, the stack is Am⊥. Reading n b's pops n A's, leaving Am−n⊥. The only gateway to the cleanup state consumes one further A without consuming input, which is possible precisely when m−n≥1. Cleanup cannot read more input, so all a's and b's must already have been consumed. Pure a strings with m≥1 are accepted via s→q; the empty string is not, because no transition from s pops ⊥ directly. The strict inequality n<m, not n≤m, is therefore essential.

Original paper, page 41 · Answer key

2 marks · NAT
Report issue

Finite Automata

Question 63, GATE 2023: Find the minimum number of states of a complete DFA over {0,1} accepting strings that never contain three consecutive 1s.
Tap to enlarge
Answer & solution

Official answer: 4

Step through it (2 parts)

Use three accepting states tracking the trailing run of ones of lengths 0, 1, 2, and a rejecting trap after the third consecutive one. A zero resets each nontrap state to run length 0; a one advances the run or reaches the trap. All four states are reachable. The trap differs from the others on the empty suffix. For two run lengths i<j among 0, 1, 2, append 3-j ones: the state j rejects but state i still accepts. Thus all four are pairwise distinguishable and the DFA is minimal.

Teaching detail. Name states q0,q1,q2,dead by the count of trailing 1s until a forbidden run has occurred. On 0, q0,q1,q2 go to q0; on 1 they go to q1,q2,dead respectively. dead loops on both symbols because an earlier occurrence of 111 can never be undone by later zeros. q0,q1,q2 accept, including q0 for ε. Reachability witnesses are ε,1,11,111. A construction alone proves an upper bound of four; the distinguishability argument is required to exclude every possible smaller DFA.

Original paper, page 67 · Answer key

1 mark · MCQ
Report issue

Regular Expressions & Languages

Question 12, GATE 2022: An NFA has nonfinal start s and final states u,v. Transitions: s—a→u, s—b→v, u—b→u and s, v—a→v and s; no other transitions. Choose its regular expression (plus means union): A ab*bab*+ba*aba*; B (ab*b)*ab*+(ba*a)*ba*; C (ab*b+ba*a)*(a*+b*); D (ba*a+ab*b)*(ab*+ba*).
Tap to enlarge
Your answer
Answer & solution

Official answer: D

Each return to the nonaccepting start state consumes either ab*b through the upper accepting state or ba*a through the lower one. Any number of such excursions may occur. Finally the path must stop in an accepting state, consuming ab* or ba*. Thus the language is (ba*a+ab*b)*(ab*+ba*), D.

A useful state-elimination decomposition is a sequence of complete excursions back to s, then one final unfinished excursion into u or v. Since s is nonaccepting, the final factor must consume at least one symbol; option C incorrectly admits ε. Option B disallows mixing the two types of returning excursion before the last segment.

Original paper, page 11 · Answer key

1 mark · MSQ
Report issue

Decidability & Computability

Question 23, GATE 2022: Select true statements: A every subset of a recursively enumerable language is recursive; B if L and its complement are recursively enumerable, L is recursive; C the complement of a context-free language is recursive; D the intersection of two regular languages is deterministic context-free.
Tap to enlarge
Select all that apply
Answer & solution

Official answer: B,C,D

A is false: a recursively enumerable language such as Σ* can have a subset that is not recursive. B is true because dovetailing recognizers for a language and its complement always finds one acceptance, giving a decider. C is true because CFL membership is decidable and decidable languages are closed under complement. D is true because a DPDA can track a regular-language DFA in its finite control without losing determinism. Thus B, C, D.

For B, alternate one step of each recognizer on the same input. Exactly one must eventually accept, so the procedure always halts with the correct yes/no result. For D, regular languages are closed under intersection using a product DFA; a deterministic PDA can simulate that DFA while ignoring its stack.

Original paper, page 19 · Answer key

2 marks · MSQ
Report issue

Decidability & Computability

Question 46, GATE 2022: Select undecidable problems: A equality of languages of two given Turing machines; B whether a given TM language is regular; C whether a TM accepts all strings; D whether a given TM takes more than the fixed printed bound 1073 steps on every string.
Tap to enlarge
Select all that apply
Answer & solution

Official answer: A,B,C

Turing-machine language equivalence, regularity, and universality are undecidable semantic properties: fix one machine to recognize Σ* for an equivalence-to-universality reduction, and apply Rice’s theorem to the other two nontrivial language properties. D asks about a fixed finite time bound, printed as 1073. Simulate on the finitely many distinguishable input prefixes/end-marker cases visible within that many steps. This decides whether every input runs longer than the bound; complexity is enormous but finiteness suffices. Thus A, B, C.

A language property is nontrivial when some recognizable languages possess it and others do not. Regularity and universality satisfy this requirement, so Rice applies. Runtime within a fixed number of steps is instead a bounded execution property: only finitely many tape cells can be inspected. An astronomical fixed bound remains finite and does not become the unbounded halting problem.

Original paper, page 31 · Answer key

2 marks · MSQ
Report issue

Regular Expressions & Languages

Question 47, GATE 2022: Over Σ={a,b}, L1={a^n w a^n : w∈Σ*}, L2={w x w^R : w,x∈Σ*, |w|,|x|>0}. Select true statements: A both regular; B both context-free; C L1 regular and L2 context-free; D both context-free but neither regular. The source does not explicitly state the allowed n in L1.
Tap to enlarge
Select all that apply
Answer & solution

Official answer: A,B,C

In L1 the arbitrary middle word absorbs all content: if n=0 is allowed, L1=Σ*; if n is required positive, taking n=1 gives aΣ*a. Either reading is regular. L2 consists exactly of strings of length at least 3 whose first and last symbols agree: take w to be the first symbol and x the nonempty middle. Hence L2=aΣ+a ∪ bΣ+b is regular. Both are therefore context-free as well, so A, B, C are true and D is false.

For L2, any allowed decomposition has equal first and last symbols and at least one middle symbol. Conversely if those conditions hold, choose |w|=1 and put everything else in x. Longer equal/reversed boundary strings are optional witnesses, not extra restrictions. This existential choice is why the language is much simpler than a general palindrome language.

Original paper, page 31 · Answer key

2 marks · MSQ
Report issue

Context-Free Grammars & Languages

Question 48, GATE 2022: L1={ww:w∈{a,b}*}, L2={a^n b^n c^m:m,n≥0}, L3={a^m b^n c^n:m,n≥0}. Select FALSE claims: A L1 not context-free, L2/L3 deterministic context-free; B neither L1 nor L2 context-free; C L2,L3 and their intersection all context-free; D neither L1 nor its complement context-free.
Tap to enlarge
Select all that apply
Answer & solution

Official answer: B,C,D

The copy language L1={ww} is not context-free: intersecting with a+b+a+b+ gives {aⁱbʲaⁱbʲ: i, j>0}. For pumping length p, aᵖbᵖaᵖbᵖ has any pumping window of length at most p within at most two adjacent blocks. Pumping changes at least one block without changing its matching nonadjacent block, or creates extra alternations, contradicting this language’s form. L2 and L3 are deterministic context-free by pushing one block and matching the adjacent equal-count block; their intersection is {aⁿbⁿcⁿ}, not context-free. Thus A is true and B, C are false. D is also false because the complement of L1 is context-free: include all odd-length words, and for even length choose two different symbols in corresponding half-positions. Let Ea={uav:|u|=|v|} and Eb={ubv:|u|=|v|}; each is context-free via Sa→cS_a d | a for c, d∈Σ, and similarly Sb. E_aE_b ∪ E_bE_a describes exactly the even noncopies, since the two centers differ and are separated by half the total length. Closure under concatenation and union proves the complement claim. Select false statements B, C, D.

For the complement construction, Ea contains odd strings whose center is a and Eb those whose center is b. Concatenating lengths 2r+1 and 2s+1 puts their centers r+s+1 positions apart, exactly half the total length. Thus choosing unequal centers witnesses unequal half-positions. Conversely any mismatching pair in two equal halves determines such a split. Odd-length strings are automatically noncopies and form a regular language.

Original paper, page 32 · Answer key

1 mark · MCQ
Report issue

Closure Properties & Language Hierarchy

Question 1, GATE 2021: L1 is regular and L2 is context-free. Which language need NOT be context-free? A L1∩L2; B L1·L2 (concatenation); C L1−L2; D L1∪L2.
Tap to enlarge
Your answer
Answer & solution

Official answer: C

CFLs are closed under intersection with regular languages, concatenation with regular languages, and union with regular languages. They are not closed under complement, so choosing regular L1=Σ* makes L1−L2 the complement of a CFL, which need not be context-free. For a concrete witness, the complement of the non-context-free copy language {ww} is context-free; using that complement as L2 yields the non-CFL {ww}. Thus C.

A simpler explicit counterexample to closure under difference uses Σ={a,b,c}. Define L2=Σ*\{an bn cn:n≥0}. This is context-free: strings outside a*b*c* form a regular language; inside that regular pattern, unequal a/b counts or unequal b/c counts form a union of CFLs, each checkable by a PDA. With regular L1=Σ*, L1−L2 is the standard non-CFL {an bn cn}. For A, run the DFA alongside the PDA; for B,D, use standard CFL concatenation/union constructions because regular languages are also CFLs.

Original paper, page 12 · Answer key

1 mark · MSQ
Report issue

Decidability & Computability

Question 12, GATE 2021: For Σ={0,1} and automaton encoding ⟨M⟩, select the languages that are NOT recursive. A {⟨M⟩: M is a DFA and L(M)=∅}; B {⟨M⟩: M is a DFA and L(M)=Σ*}; C {⟨M⟩: M is a PDA and L(M)=∅}; D {⟨M⟩: M is a PDA and L(M)=Σ*}.
Tap to enlarge
Select all that apply
Answer & solution

Official answer: D

DFA emptiness is decidable by reachability of an accepting state. DFA universality is decidable by complementing the complete DFA and checking emptiness. PDA emptiness is decidable, for example by converting to a CFG and marking productive nonterminals. Universality of a general nondeterministic PDA/CFG is undecidable, so only D is not recursive.

A recursive language has an algorithm that halts on both yes and no instances. For DFA universality, first ensure the transition function is total by adding a sink if necessary, then invert final/nonfinal states and run a finite reachability test. PDA emptiness asks whether some derivation produces a terminal string, which productive-variable marking decides. PDA universality is a known undecidable CFG universality problem; enumerating accepted strings cannot certify that no unaccepted string exists.

Original paper, page 17 · Answer key

2 marks · MCQ
Report issue

Finite Automata

Question 38, GATE 2021: Which DFA recognizes exactly binary strings ending in 011? Essential transition-table descriptions of the four diagrams: all have states q0,q1,q2,q3, start q0, only q3 accepting. Common transitions: q0 on 0→q1 and on 1→q0; q1 on 0→q1 and on 1→q2; q2 on 0→q1 and on 1→q3. The differing q3 transitions (on 0,on 1) are A (q1,q3); B (q3,q3); C (q1,q2); D (q1,q0).
Tap to enlarge
Your answer
Answer & solution

Official answer: D

Label the four states by the longest suffix matching a prefix of 011: ε, 0, 01, 011. Their transitions on(0, 1) are respectively(0,ε),(0, 01),(0, 011),(0,ε). Only the 011 state accepts. These transitions are exactly D. A wrongly accepts 0111, B keeps accepting after arbitrary suffixes, and C accepts 01111 despite its final three symbols being 111.

The invariant is that the state remembers the longest suffix of the input that is also a prefix of the target 011. After reading 0111 there is no nonempty suffix that is such a prefix, so the accepting state's 1-transition must return to q0. After reading 0110, the suffix 0 remains useful, so its 0-transition must go to q1. These two checks distinguish D from the three other diagrams while the invariant proves correctness for arbitrary input lengths.

Original paper, page 32 · Answer key

2 marks · MCQ
Report issue

Decidability & Computability

Question 39, GATE 2021: For Turing-machine encodings ⟨M⟩, L1={⟨M⟩: M takes more than 2021 steps on all inputs}, L2={⟨M⟩: M takes more than 2021 steps on some input}. Which is correct? A both decidable; B L1 decidable/L2 undecidable; C L1 undecidable/L2 decidable; D both undecidable.
Tap to enlarge
Your answer
Answer & solution

Official answer: A

A computation limited to 2021 steps can inspect only finitely many input positions. Enumerate all finite relevant prefixes, including end-of-input cases, and simulate M for that fixed bound on each representative. Check whether all representatives run longer than 2021 for L1, or at least one does for L2. Both procedures terminate, despite a very large finite enumeration. Therefore both languages are decidable, A.

This is bounded-time behavior, unlike the unbounded halting problem. In 2021 steps a standard single-tape input head can visit only a bounded initial portion of the input; choose a conservative prefix bound 2022 and include all shorter words and all words of that prefix length as representatives for longer inputs. Simulate each for exactly the fixed bound, detecting whether it halts within it. The enumeration is enormous but finite, which is sufficient for decidability; no practical polynomial-time claim is made.

Original paper, page 33 · Answer key

2 marks · NAT
Report issue

Pushdown Automata

Question 51, GATE 2021: A PDA has states q0,q1,q2,q3, start q0 and only final state q3, input {a,b} and stack alphabet {#,A}. Transition label input,pop→push is used, with ε meaning no input/pop/push. Transitions: q0→q1: ε,ε→#; q1 loop: a,ε→A; q1→q2: ε,ε→ε; q2 loop: b,A→ε; q2→q3: ε,A→A. There are no other transitions. How many length-100 strings are accepted by final state?
Tap to enlarge
Answer & solution

Official answer: 50

The PDA first pushes its bottom marker, then pushes one A for each initial a. In the second phase it pops one A for each b. Reaching the final state requires an A still on top, so the language is am bn with m>n>=0. For total length 100, n can be any integer from 0 through 49, with m=100-n. Each choice determines one string, giving 50. The accepting-state transition preserves that remaining A; acceptance is by final state rather than empty stack.

While reading a's, the stack contains one A per a above #. After switching to q2, each b removes one A and no a-transition exists, enforcing the order a* b*. The final ε-transition tests and preserves an A, requiring strictly more a's than b's. For length 100, m+n=100 and m>n give 100−n>n, so n<50. Each n=0,...,49 gives one word a100−nbn, including a100; equality at n=50 is not accepted.

Original paper, page 40 · Answer key

1 mark · MCQ
Report issue

Finite Automata

Question 9, GATE 2021: A regular language L⊆{0,1}* has a minimal DFA with k states. Which language must also have a k-state minimal DFA? A L−{01}; B L∪{01}; C {0,1}*−L; D L·L.
Tap to enlarge
Your answer
Answer & solution

Official answer: C

Complement a complete minimal DFA by exchanging accepting and nonaccepting states. Reachability is unchanged, and every distinguishing suffix still distinguishes the same pair with acceptance reversed. Consequently no states merge and the minimal state count remains k. Thus the complement language, C.

For any states p,q distinguished in L by suffix w, exactly one of their w-runs ends accepting. Flipping all final-state flags preserves that exclusive difference, proving minimality rather than merely giving an upper bound of k states. Completeness matters: a missing transition must first be represented by a dead state before taking a DFA complement.

Original paper, page 59 · Answer key

1 mark · MSQ
Report issue

Closure Properties & Language Hierarchy

Question 12, GATE 2021: L1 is regular and L2 context-free. Which are necessarily context-free? A L1∩¬L2; B ¬(¬L1∪¬L2); C L1∪(L2∪¬L2); D (L1∩L2)∪(¬L1∩L2). Complements are relative to the common alphabet-star.
Tap to enlarge
Select all that apply
Answer & solution

Official answer: B; C; D

Visually reading the overbars, B is the complement of (complement L1 union complement L2), hence L1 intersection L2, which is context-free. C contains L2 union complement L2 and equals the whole alphabet-star. D is (L1 intersection L2) union (complement L1 intersection L2), hence L2. A is L1 intersection complement L2; taking L1=Σ* shows that it need not be context-free, since CFLs are not closed under complement. Thus B, C, D.

The relevant closure theorem is intersection of a CFL with a regular language, not intersection of two arbitrary CFLs. A product construction combines the CFL's PDA control with the regular DFA state without adding another stack. C and D simplify by excluded middle, so no unsupported general CFL-complement closure is used.

Original paper, page 61 · Answer key

1 mark · NAT
Report issue

Finite Automata

Question 17, GATE 2021: DFA has start q0, layer-one states u,v, layer-two states p,q and accepting f. Transitions: q0:0→u,1→v; u:0→p,1→q; v:0→p,1→q; p and q:0,1→f; f:0,1→f. Count accepted strings of length 8.
Tap to enlarge
Answer & solution

Official answer: 256

Every input follows one edge through each of the first three layers, reaching the accepting state after exactly three symbols regardless of their values. That state loops on both 0 and 1. Hence every eight-bit string is accepted, giving 2⁸=256.

The machine recognizes all binary strings of length at least three: no earlier state is accepting, and after the third transition it cannot leave f. Thus for any length n≥3 the count is 2n. The two layer-two branches must not be mistaken for missing-input transitions; each accepts both bits on the next step.

Original paper, page 64 · Answer key

2 marks · MCQ
Report issue

Decidability & Computability

Question 36, GATE 2021: S1 every infinite regular language contains an undecidable subset. S2 every finite language is regular. A only S1; B only S2; C both; D neither.
Tap to enlarge
Your answer
Answer & solution

Official answer: C

Every infinite language over a finite alphabet is countably infinite and has uncountably many subsets, whereas only countably many algorithms, hence decidable languages, exist. At least one subset is therefore undecidable, proving S1. Every finite language has a regular expression formed by union of its finitely many words, proving S2. Thus C.

The counting argument is nonconstructive: it proves an undecidable subset exists without requiring the regular language itself to encode a difficult membership test. For a finite language {w1,…,wm}, regex w1+…+wm recognizes it; the empty language is regular too. Being a subset of a decidable language does not imply decidability.

Original paper, page 76 · Answer key

2 marks · MSQ
Report issue

Context-Free Grammars & Languages

Question 41, GATE 2021: For w,x∈{0,1}*, w^R is reversal. Which languages are context-free? A {wxw^Rx}; B {ww^Rxx^R}; C {wxw^R}; D {wxx^Rw^R}. Empty w and x are allowed.
Tap to enlarge
Select all that apply
Answer & solution

Official answer: B; C; D

B concatenates two even-palindrome languages and is context-free. C is all binary strings, since w may be empty. D is exactly the even palindromes: wx xR wR=(wx)(wx)R, and x may be empty. A is not context-free. Here is a pumping argument that accounts for empty w and x rather than merely calling the dependencies crossed. Its intersection with 0+1+0+1+ consists of 0a 1b0c1d satisfying either a=c and b-d is a nonnegative even integer, or b=d and c-a is a nonnegative even integer. This follows by examining where w and x split the first half: either w=0a 1k and x=1d, or w=0a and x=1b0k. The word 0p1p0p1p belongs. A pumping window of length at most p meets at most two adjacent blocks. Pumping a piece crossing a boundary creates extra runs when repeated. Otherwise pumping changes only those adjacent block lengths. If both change, use upward pumping for blocks 1/2 or 3/4 and downward pumping for blocks 2/3 to violate both conditions. If only one changes, increase block 1 or 4, or decrease block 2 or 3. Every possible pumping decomposition thus has a failing exponent. Closure under regular intersection proves A is not context-free. Answer B, C, D.

Constructive positive proofs: let E→0E0|1E1|ε generate even palindromes. For B use start H→EE, concatenating two such words. For C use H→0H|1H|ε, since taking w=ε yields arbitrary x. For D use E again, because the concatenated first half wx is arbitrary. These grammars establish membership instead of relying only on a visual impression of symmetry; A requires the non-CFL argument above.

Original paper, page 78 · Answer key

2 marks · MSQ
Report issue

Regular Expressions & Languages

Question 47, GATE 2021: Which regexes describe binary multiples of three, allowing leading zeros and ε? A (0+1(01*0)*1)*; B (0+11+10(1+00)*01)*; C (0*(1(01*0)*1)*)*; D (0+11+11(1+00)*00)*. + denotes union.
Tap to enlarge
Select all that apply
Answer & solution

Official answer: A; B; C

Use the remainder automaton r→(2r+b) mod3, start/accept 0. A describes concatenated excursions from 0: a 0 stays at 0, while 1 enters remainder 1, any number of blocks 01*0 returns to 1 via remainder 2, and final 1 returns to 0. B describes the same excursions by separating 11 from 10(1+00)*01: at remainder 2, either 1 or 00 loops back to 2, then 01 exits to 0. C is equivalent to A because arbitrary concatenations of zeros and nonzero excursions can be grouped into runs of zeros followed by runs of excursions. D is wrong: it cannot generate 1001 (binary9); every nonempty D word beginning 1 begins 11. Thus A, B, C. Leading zeros and the empty string are allowed as stated.

The remainder transition table is 0:0→0,1→1; 1:0→2,1→0; 2:0→1,1→2. A complete path from 0 back to 0 can be decomposed at every visit to state 0. This yields the excursion regex used in A. The counterexample 1001 has numeric value 9, so rejecting it conclusively refutes D without needing exhaustive enumeration.

Original paper, page 84 · Answer key

1 mark · MCQ
Report issue

Regular Expressions & Languages

Question 7, GATE 2020: Which regular expression denotes binary strings with an odd number of 1s? Here + means union. A ((0+1)*1(0+1)*1)*10*; B (0*10*10*)*0*1; C 10*(0*10*10*)*; D (0*10*10*)*10*. The official answer is MTA, not a letter.
Tap to enlarge
Your answer
Answer & solution

Official answer: MTA

Our answer: No correct option; official MTA

Worked explanation

Checking a claimed regular expression needs both inclusions: every generated string must have odd parity, and every odd-parity string must be generated. A violates soundness because the arbitrary (0+1)* portions can introduce extra 1s: use the repeated block 111 and final 1 to generate 1111. B violates completeness on 10, because it ends in a mandatory 1. C violates completeness on 01, because its first symbol is 1. In D, zero repeated blocks give a leading 1; a positive number supplies at least two 1s before the final mandatory one, so 01 is again missing. In the corrected teaching expression 0*(10*10*)*10*, the repeated block contributes pairs of 1s and the final block contributes one; the surrounding zero runs allow arbitrary gaps and ends. This correction is explanatory only and does not replace official MTA scoring.

Derivation and answer

Each offered expression fails. A accepts 1111: choose 111 for one repeated block and the final 1, producing an even number of ones. B always ends in 1 and misses the valid string 10. C begins in 1 and misses 01. D also misses 01: zero repetitions begin with 1, while any positive repetition contributes at least two ones before the final 1. A correct expression is 0*(10*10*)*10*. The official key awards MTA, which is preserved rather than mapped to a letter.

Original paper, page 5 · Answer key

1 mark · MCQ
Report issue

Closure Properties & Language Hierarchy

Question 8, GATE 2020: Test I: if L1∪L2 is regular, both L1 and L2 must be regular. II: regular languages are closed under infinite union. Options: A I only; B II only; C both; D neither.
Tap to enlarge
Your answer
Answer & solution

Official answer: D

Worked explanation

Closure under a binary operation gives the forward implication: if both languages are regular then their union is regular. It does not give the converse. For a concrete converse counterexample choose L={an bn:n≥0} over {a,b}, and its complement. L is nonregular; its complement is nonregular because otherwise closure under complement would make L regular. Their union is the regular language {a,b}*. For infinite union, each singleton {an bn} has a finite automaton, but the union over all n is L. Finite union closure cannot be extended to countably many automata by treating an infinite construction as a finite automaton.

Derivation and answer

For I, take a nonregular language L and its complement; their union isΣ*, regular, although neither component is regular. For II, each singleton{an bn} is regular but their union over n≥0 is not. Both assertions are false, D.

Original paper, page 5 · Answer key

1 mark · MCQ
Report issue

Pushdown Automata

Question 10, GATE 2020: L={a^n:n≥0}∪{a^n b^n:n≥0}. Test I L is deterministic context-free; II L is context-free but not deterministic context-free; III L is not LL(k) for any k. Options: A I only; B II only; C I and III; D III only.
Question 10, GATE 2020: L={a^n:n≥0}∪{a^n b^n:n≥0}. Test I L is deterministic context-free; II L is context-free but not deterministic context-free; III L is not LL(k) for any k. Options: A I only; B II only; C I and III; D III only.
Tap to enlarge
Your answer
Answer & solution

Official answer: C

Worked explanation

A deterministic pushdown recognizer can use an accepting a-phase, initially with a bottom marker. Each a pushes one marker. Seeing the first b changes permanently to a b-phase and pops one marker per b; a b with no marker, or any later a, rejects. At end-of-input it accepts either the a-phase (including ε) or the b-phase with exactly the bottom marker left. This establishes I constructively and rejects II. The familiar non-LL(k) separation is a language-level result: do not infer it merely because the obvious grammar S→A|B, A→aA|ε, B→aBb|ε has a FIRST-set conflict. The shared-prefix argument below explains the obstruction; a full formal proof that no equivalent LL(k) grammar exists requires the bounded-lookahead language theorem, not just testing that one grammar. III is the standard classification used by the official answer.

Derivation and answer

A DPDA pushes while reading a symbols, then pops one per b after the first b. It accepts an all-a input by final state at end-of-input, and accepts an an bn input when the count matches, so the language is deterministic context-free. The standard strict-separation example a* union {an bn} is not an LL(k) language for any finite k: arbitrarily long common a-prefixes postpone the distinction between an unmatched all-a ending and the matching b-suffix beyond any fixed lookahead. A predictive leftmost derivation cannot use that late distinction to discharge an unbounded number of already predicted matching b obligations. This is the language-level bounded-lookahead obstruction, not merely an observation that one displayed grammar is not left-factored. Thus I and III, C.

Original paper, page 6 · Answer key

2 marks · MCQ
Report issue

Decidability & Computability

Question 26, GATE 2020: Which languages of machine encodings are undecidable? L1={⟨M⟩:L(M)=∅}; L2={⟨M,w,q⟩:M on w reaches q in exactly 100 steps}; L3={⟨M⟩:L(M) is not recursive}; L4={⟨M⟩:L(M) has at least 21 members}. A L1,L3,L4; B L1,L3; C L2,L3; D L2,L3,L4.
Tap to enlarge
Your answer
Answer & solution

Official answer: A

Worked explanation

Apply Rice’s theorem only to semantic properties of the recognized language that are neither true for every recognizable language nor false for all of them. Emptiness is nontrivial (∅ versus {ε}); nonrecursiveness is nontrivial (a recognizable undecidable language versus a finite language); at least 21 strings is nontrivial (∅ versus any 21-element finite language). Thus L1,L3,L4 qualify. L2 instead concerns a bounded computation trace. A simulator executes at most 100 transitions and checks q at the specified step, rejecting if the run ends earlier without that event. This always halts. An unbounded reachability question would be very different.

Derivation and answer

TM-language emptiness, being nonrecursive, and having at least 21 strings are each nontrivial semantic properties of recursively enumerable languages, so Rice’s theorem makes L1, L3, L4 undecidable. L2 is decidable by simulating the specified machine and input for exactly 100 steps and checking the state. Thus A.

Original paper, page 9 · Answer key

2 marks · MCQ
Report issue

Context-Free Grammars & Languages

Question 32, GATE 2020: L1={wxyx:w,x,y∈{0,1}*}; L2={xy:x,y∈{a,b}*, |x|=|y|, x≠y}. Which statement is true? A L1 regular and L2 context-free; B L1 context-free but not regular, L2 context-free; C neither context-free; D L1 context-free, L2 not context-free.
Tap to enlarge
Your answer
Answer & solution

Official answer: A

Worked explanation

Empty strings are permitted for the starred variables in L1. Setting x=y=ε produces every binary w, so repeated appearances of x impose no restriction at all. For L2, the grammar below is more informative than incorrectly invoking closure under complement of context-free languages. Write V→b|aVa|aVb|bVa|bVb in addition to the displayed U productions. U and V wrap arbitrary equal numbers of symbols around different central letters. Concatenating them makes the central positions differ by half the total length. Conversely, if unequal halves of length m differ at position r, choose first component length 2r−1 and second length 2(m−r)+1. Their centers land at r and m+r. This proves both grammar inclusions, hence context-freeness without claiming that arbitrary complements of CFLs are CFLs.

Derivation and answer

For L1 choose x=ε, y=ε and let w be any binary string; hence L1=Σ*, regular. For L2 a CFG can guess a differing position in the two equal-length halves. Explicitly let U generate all odd-length strings with central a via U→a|aUa|aUb|bUa|bUb, and V generate those with central b by the analogous rules with base b. S→UV|VU then generates exactly even-length strings whose two halves differ somewhere. If component lengths are 2i+1 and 2j+1, their differing central symbols are i+j+1 positions apart, exactly half the total length. Conversely any mismatch supplies such a split. Thus L2 is context-free and A holds.

Original paper, page 11 · Answer key

2 marks · NAT
Report issue

Finite Automata

Question 51, GATE 2020: L consists of strings over {a,b} whose number of a symbols is divisible by 2 but not by 3. Find the minimum states in a DFA for L.
Tap to enlarge
Answer & solution

Official answer: 6

Step through it (2 parts)

Worked explanation

DFA specification: states q0,…,q5; start q0; accepting q2,q4; δ(qr,a)=q((r+1) mod 6); δ(qr,b)=qr. This is a complete transition graph, with an a-cycle of length six and a b-self-loop at each vertex. Counting zero a symbols is divisible by both 2 and 3, so q0 correctly rejects. For minimality, all qr are reached by ar. The accepting suffix exponents modulo 6 for q0…q5 are respectively {2,4},{1,3},{0,2},{1,5},{0,4},{3,5}. These six sets differ pairwise. Choose an exponent in the symmetric difference to distinguish any two states, proving six inequivalent prefixes and the lower bound.

Derivation and answer

Track the number of a symbols modulo 6. On a increment the remainder, on b leave it unchanged, and accept remainders 2 and 4; these are exactly even counts not divisible by 3. All six states are reachable. From remainder r, accepting suffix lengths modulo 6 form {2-r, 4-r}. These six sets are distinct, so any pair of remainders is distinguished by some suffix ak. Myhill-Nerode therefore requires all 6 states, matching the construction.

Original paper, page 15 · Answer key

1 mark · MCQ
Report issue

Which language operation need not preserve regularity

Closure Properties & Language Hierarchy

Question 7, GATE 2019: Given a regular language L over {a,b}, compare A L·L^R, where L^R is the set of reversed words; B {ww^R : w∈L}; C Prefix(L), all prefixes of words in L; D Suffix(L), all suffixes. The source asks which is “NOT regular”; evaluate this as which operation is not guaranteed to preserve regularity.
Tap to enlarge
Your answer
Answer & solution

Official answer: B

Our answer: B under not-necessarily-regular interpretation

Method: use closure constructions for A, C, D, and a counterexample for B.

1. Regular languages are closed under reversal and concatenation. Reversing an automaton's edges and exchanging start/final roles gives an NFA for LR; concatenating automata then recognizes L·LR. Thus A is always regular. Its two factors are chosen independently.
2. For Prefix(L), take a DFA for L and mark as accepting every state from which some original accepting state is reachable. A word reaches such a state exactly when it can be extended to a word of L. Thus C is regular.
3. For Suffix(L), use an NFA whose possible initial states are all states reachable from the original start, while keeping the original accepting states. It recognizes strings that can follow some prefix to complete a word of L. Thus D is regular.
4. B requires the second half to be the reversal of the very same first half. Choose regular L = {a,b}*. B then contains precisely the even-length palindromes. If it had pumping length p, the palindrome ap bb ap would have a nonempty pumped part wholly among its first p a's. Pumping that part down shortens only the left a-run, producing a non-palindrome. This contradicts the pumping lemma.

Result: B identifies the operation that does not preserve regularity. Literally B can be regular for finite or empty L, so the unconditional wording must mean not necessarily regular. The recorded regularity-quantifier discrepancy is retained.

Original paper, page 5 · Answer key

1 mark · MCQ
Report issue

A valid pumping length for a union of residue classes

Regular Expressions & Languages

Question 15, GATE 2019: Over {a,b}, L = {a^(2+3k) : k≥0} ∪ {b^(10+12k) : k≥0}. Which offered value can be a pumping length? Choices: A 3; B 5; C 9; D 24. The question asks for a valid length, not necessarily the smallest one.
Tap to enlarge
Your answer
Answer & solution

Official answer: D

Method: use the actual pumping-lemma conditions. For every word s with |s|≥p, find s=xyz with |xy|≤p, |y|≥1, and xyiz∈L for every integer i≥0.

1. Reject p=3, 5, or 9 using s=b10, which has length at least each candidate. Any nonempty y in such a decomposition consists only of b's and has length r with 1≤r≤p≤9.
2. Pumping up once more, i=2, produces length 10+r. For this all-b word to remain in L, r would have to be a multiple of 12. No r from 1 through 9 qualifies. Thus each of those three candidates fails.
3. Now take p=24. If s=am∈L and m≥24, set x=ε and y=a³. Pumping changes m by a multiple of 3, preserving m≡2 mod 3. Even at i=0, m−3≥21, and the permitted residue makes the remaining exponent an admitted nonnegative case.
4. If s=bm∈L and m≥24, set x=ε and y=b12. The first eligible such m is 34. Pumping changes m by multiples of 12; removing one block leaves at least 22, still an admitted length 10+12k.
5. Both constructions have nonempty y and |xy| equal to 3 or 12, at most 24. They therefore satisfy all requirements for every sufficiently long word in either branch.

Result: D, 24. A pumping length is an upper threshold at which suitable repetition is guaranteed; it does not have to equal a shortest accepted word or the least possible threshold.

Original paper, page 6 · Answer key

2 marks · MCQ
Report issue

Nested versus crossing language constraints

Context-Free Grammars & Languages

Question 31, GATE 2019: Over {a,b}, choose the language that is not context-free: A {ww^R}; B {wa^n b^n w^R}; C {wa^n w^R b^n}; D {a^n b^i : i is n, 3n, or 5n}. Here w ranges over all finite binary-alphabet strings, n≥0, and w^R is reversal.
Tap to enlarge
Your answer
Answer & solution

Official answer: C

1. To distinguish these languages, separate nested matching, which a stack supports, from overlapping matching constraints. A is generated by S→aSa|bSb|ε, so it is context-free.
2. B is also nested: use S→aSa|bSb|T and T→aTb|ε. The S rules build w and its reversal around the central equal-length a/b runs. D is a union of three context-free languages; for each r in {1,3,5}, Sr→aS_r br|ε generates its fixed-ratio component. CFLs are closed under finite union.
3. For C, intersect with the regular language a+ b a+ b a+ b+. CFLs are closed under intersection with regular languages. In this pattern the two isolated b symbols force w=ai b at, and n=k, giving precisely K={ai b aj b ai bk : i,k≥1, j≥k, j−k even}, with j=2t+k.
4. Suppose K were context-free with pumping length p. Choose s=ap b ap b ap bp. In any CFL pumping decomposition s=uvxyz, |vxy|≤p and |vy|>0. The window cannot touch both the first and third a-runs, nor both the middle a-run and final b-run.
5. If v or y contains a separator b, pumping down removes a required separator and destroys the regular pattern. Otherwise, pumping any first/third-run a changes one side of their required equality without changing the other. This also leaves K.
6. The remaining possibility pumps only middle-run a's or only final-run b's. Pumping down middle a's makes j<k; pumping up final b's makes k>j. Thus every decomposition fails for some pump count, contradicting the pumping lemma. K, and hence C, is not context-free. Answer C.

Original paper, page 10 · Answer key

2 marks · MCQ
Report issue

Counting descriptions and languages

Other / Mixed Topics

Question 34, GATE 2019: Which sets are uncountable? S1: recursively enumerable languages over {0,1}; S2: syntactically valid C programs; S3: all languages over {0,1}; S4: all nonregular languages over {0,1}. Options A S1/S2, B S3/S4, C S2/S3, D S1/S4.
Tap to enlarge
Your answer
Answer & solution

Official answer: B

1. A set is countable if its members can be listed using natural-number indices. Finite strings over any finite alphabet can be listed by length and then lexicographic order, so their collection is countable.
2. Each Turing machine has a finite description. There are therefore only countably many such machines and only countably many languages they recognize. Every recursively enumerable language is recognized by a machine, so S1 is countable.
3. Each C program is also a finite string. Restricting the countable set of all strings to those obeying C syntax cannot make it uncountable, so S2 is countable.
4. The set {0,1}* of words is countably infinite, but a language is an arbitrary subset of that set. Its power set is uncountable by Cantor's theorem. Hence S3 is uncountable; confusing words with sets of words is the main trap.
5. Regular languages have finite automaton descriptions, so there are only countably many of them. If S4 were countable too, all languages would be a union of two countable sets, contradicting step 4. Thus S4 is uncountable and the answer is B.

Original paper, page 11 · Answer key

2 marks · NAT
Report issue

Minimal DFA for identity permutations

Finite Automata

Question 48, GATE 2019: The alphabet Σ consists of all bijections of {1,...,5} to itself. A word x=x1...xn denotes the composition π(x)=x1∘...∘xn; the empty composition is identity. L contains words whose composition is identity. Find the number of states in a smallest DFA recognizing L.
Tap to enlarge
Answer & solution

Official answer: 120

1. Each alphabet symbol is a permutation of five objects, so there are 5!=120 possible permutations. A prefix matters only through its accumulated composition, suggesting a state for each permutation.
2. Construct that DFA: start in the identity state; if the current state is g and the next symbol is σ, transition to g∘σ. Make identity the sole accepting state. Associativity ensures the stored state after x is exactly π(x), so this 120-state DFA recognizes L.
3. All 120 states are reachable: reading the single alphabet symbol g takes the identity start to g. Hence there are no unreachable states to discard.
4. To prove no states can be merged, take distinct permutations g and h. Append the one-letter suffix g^−1, which is available because inverses are also permutations in Σ. From g this produces g∘g^−1=id and accepts.
5. From h the same suffix produces h∘g^−1. It cannot equal id, since that would imply h=g after composing with g. Thus it rejects, so the two states are distinguishable.
6. Every pair is distinguishable, proving a lower bound of 120 states. Combined with the construction, the minimum is exactly 120. Merely counting symbols would not prove minimality without the reachability and distinguishing-suffix arguments.

Original paper, page 14 · Answer key

1 mark · MCQ
Report issue

NFA to minimal DFA state bound

Finite Automata

Question 6, GATE 2018: An NFA has n states. Its equivalent minimal DFA has k states. Which is always true? A k≥2^n; B k≥n; C k≤n²; D k≤2^n.
Tap to enlarge
Your answer
Answer & solution

Official answer: D

Method

A DFA must remember the entire set of NFA states that could currently be active. There are 2n subsets of an n-element set. Some subsets may be unreachable and some reachable ones may be equivalent, so both reachability pruning and minimization can reduce this bound. There is no general lower bound k≥n: an NFA can contain many redundant states while accepting a language recognized by one DFA state. Some NFA families require exponentially many DFA states, ruling out a universal quadratic bound.

Solution

Subset construction represents each DFA state by a subset of the NFA’s n states, so at most 2n states are needed, including a possible empty subset. Minimization cannot increase that count. Thus k≤2n, D.

Original paper, page 5 · Answer key

1 mark · MCQ
Report issue

Closure of recognizable languages

Closure Properties & Language Hierarchy

Question 7, GATE 2018: For recursively enumerable languages, choose the true statement: A closed under complement; B closed under intersection; C all are recursive; D there are uncountably many.
Tap to enlarge
Your answer
Answer & solution

Official answer: B

Method

A recognizer may run forever when the input is not in its language. For intersection, sequential simulation is sufficient: run the first recognizer and, if it accepts, run the second and accept only if it also accepts. An input in both languages reaches both acceptances; if the first simulation loops, that input is outside the intersection, where looping is permitted. Dovetailing is another valid construction, not a requirement here. Unlike intersection, union requires avoiding a loop in one recognizer that hides acceptance by the other. Finite machine descriptions are countable, and recognizable but undecidable languages refute C.

Solution

To recognize the intersection of two recursively enumerable languages, dovetail their recognizers on the same input and accept when both accept. Hence intersection closure holds. Complement closure would make every recognizable language decidable, which is false; encodings of recognizers are countable. Thus B.

Original paper, page 5 · Answer key

2 marks · MCQ
Report issue

Which counting languages are context-free

Context-Free Grammars & Languages

Question 35, GATE 2018: Over words a^m b^n c^p d^q, with all exponents nonnegative, define I m+p=n+q; II m=n and p=q; III m=n=p and p≠q; IV mn=p+q. Which are context-free? A I,IV; B I,II; C II,III; D II,IV.
Tap to enlarge
Your answer
Answer & solution

Official answer: B

Method

One stack can track a single signed difference, so the crossed-looking equality in I is still manageable; a finite-state component checks block order. II has grammar S→AB, A→aAb|ε, B→cBd|ε. For III, restricting to positive a,b,c blocks and no d leaves the standard non-CFL equal-three-count language. For IV, the multiplication constraint cannot be reduced to one additive counter. The pumping argument below makes this precise, including decompositions that cross a block boundary rather than assuming where the pumped substrings lie.

Solution

I is context-free: a PDA tracks the signed running difference(#a+#c)−(#b+#d) with one stack symbol for positive excess and another for negative excess, canceling opposite contributions; finite control enforces a*b*c*d* order. II is the concatenation{an bn}{cp dp}, a CFL. For III, intersect with a+b+c+ (no d); the result is{an bn cn: n≥1}, not context-free. For IV, suppose pumping length p and take ap bp cp². Pumping up either disrupts block order or adds α a symbols, β b symbols and γ c symbols, with α+β+γ≤p and at least one added symbol. If α+β=0, the product stays p² but γ>0. Otherwise the required increase in c is p(α+β)+αβ≥p, while actual γ≤p−α−β<p. In every case the equality mn=p+q fails (here the fourth-block length remains 0). Thus only I and II are CFL, B.

Original paper, page 14 · Answer key

2 marks · MCQ
Report issue

Undecidability versus regular simulation

Decidability & Computability

Question 36, GATE 2018: Classify: I membership w∈L(G) for unrestricted G; II whether a TM language is regular; III equality of languages of two unrestricted/general grammars; IV whether an NFA language has an equivalent deterministic PDA. Options A only I,II undecidable; B only III; C only II,IV; D only I,II,III.
Tap to enlarge
Your answer
Answer & solution

Official answer: D

Method

Rice’s theorem applies to nontrivial properties of the recognized language, not to arbitrary syntactic machine properties. Regularity is nontrivial because some recognizable languages are regular and some are not. Equivalence of general grammars includes comparing a grammar to one generating the empty language, already an undecidable emptiness problem. IV is different: every regular language has a DFA, and a deterministic PDA can simulate a DFA while leaving its stack unchanged. Therefore IV is a constant-yes decision problem.

Solution

I is the undecidable membership problem for unrestricted grammars/Turing-recognizable languages. II is a nontrivial semantic property of a TM language, hence undecidable by Rice’s theorem. III, equivalence of general grammars, is undecidable (even equivalence of CFGs is undecidable). IV always has answer yes: convert the NFA to a DFA and view that DFA as a DPDA that does not use its stack. Hence only I, II, III are undecidable, D. If III were restricted to regular grammars it would be decidable, but no such restriction is stated.

Original paper, page 14 · Answer key

2 marks · NAT
Report issue

Order of a unary language

Finite Automata

Question 52, GATE 2018: Define L^0={ε}, L^(i+1)=L^iL; order is least k with L^k=L^(k+1). The unary DFA has accepting start q0, accepting q1, rejecting q2, and transitions q0−0→q1, q1−0→q2, q2−0→q1. Find order of its language.
Tap to enlarge
Answer & solution

Official answer: 2

Method

A path of length 0 accepts, and positive path lengths accept exactly when odd. Concatenation over a unary alphabet adds lengths. Every positive even length 2m can be decomposed as 1+(2m−1), both positive odd, so two language factors suffice for every even length as well. Zero and odd lengths use ε in one factor. To prove the least order, explicitly exclude k=0 and k=1: length 1 distinguishes L0 from L, and length 2 distinguishes L from L².

Solution

The start state is accepting. After one 0 the automaton enters an accepting state alternating with a nonaccepting state, so L1 contains epsilon and precisely the positive odd-length unary words. L1 squared contains every unary word: odd lengths use one odd word and epsilon, while any positive even length is the sum of two positive odd lengths. Hence L1²=0* and L1³=0*. But L10 differs from L1, and L1 differs from L1² because length 2 is absent from L1. The smallest equality index is therefore 2.

Original paper, page 21 · Answer key

1 mark · MCQ
Report issue

Context-Free Grammars & Languages

Question 10, GATE 2017: Grammar: S→abScT | abcT; T→bT | b. Which language? A {(ab)^n(cb)^n:n≥1}; B {(ab)^n c b^m1 c b^m2 ... c b^mn:n,m1,...,mn≥1}; C {(ab)^n(cb^m)^n:m,n≥1}; D {(ab)^n(cb^n)^m:m,n≥1}.
Tap to enlarge
Your answer
Answer & solution

Official answer: B

1. T→bT|b generates bm for any m≥1. Different occurrences of T are expanded independently.

2. After k applications of S→abScT and then S→abcT, there are k+1 leading ab pairs and k+1 trailing cT groups. Put n=k+1≥1.

3. Replace each T by its own positive b count. The result is (ab)n cbm1 ... cbmn, B. Options A and C unnecessarily force all b blocks to have equal size.

Original paper, page 6 · Answer key

1 mark · NAT
Report issue

Finite Automata

Question 22, GATE 2017: For L described by (a+b)*b(a+b) over {a,b}, find the smallest number of states in a deterministic finite automaton accepting L.
Tap to enlarge
Answer & solution

Official answer: 4.0

Our answer: 4

Step through it (2 parts)

1. The expression allows any prefix, then b, then exactly one final symbol. Thus acceptance depends on whether the second-last symbol is b, and words shorter than two are rejected.

2. Use states aa,ab,ba,bb representing the last two symbols, padding the initial short prefix on the left with a. Start at aa; on input z shift xy to yz. Accept ba and bb. All four states are reachable.

3. Two states with different first symbols have different acceptance immediately. If their first symbols agree but second symbols differ, append a; their new first symbols then differ. Every pair is distinguishable, proving the four-state construction minimal.

Original paper, page 11 · Answer key

2 marks · MCQ
Report issue

Context-Free Grammars & Languages

Question 34, GATE 2017: Grammar S→SaS | aSb | bSa | SS | ε. Which string is NOT generated? A abab; B aaab; C abbaa; D babba.
Tap to enlarge
Your answer
Answer & solution

Official answer: D

Step through it (4 derivations)

1. Use the invariant #a−#b≥0. ε starts at zero; SaS increases it by one; aSb and bSa preserve it; SS adds two nonnegative differences. All generated strings satisfy the invariant.

2. babba has two a’s and three b’s, violating it, so D cannot be generated. To ensure it is the only excluded option, exhibit constructions for the others.

3. For abab, use S⇒SS⇒aSb aSb⇒abab. For aaab, use S⇒aSb⇒aSaSb⇒aaSb⇒aaSaSb⇒aaaSb⇒aaab. For abbaa, concatenate ab,ba,a using SS, using S⇒aSb⇒ab, S⇒bSa⇒ba, and S⇒SaS⇒a (ε reductions are implicit). Thus A,B,C are generated.

Original paper, page 15 · Answer key

2 marks · MCQ
Report issue

Context-Free Grammars & Languages

Question 37, GATE 2017: G1: S→aSb | T, T→cT | ε. G2: S→bSa | T, T→cT | ε. Classify L(G1)∩L(G2): A finite; B infinite regular; C context-free but not regular; D recursive but not context-free.
Tap to enlarge
Your answer
Answer & solution

Official answer: B

1. Applying G1’s outer production n times wraps n a’s before and n b’s after T. T supplies any cm, so L(G1)={an cm bn:n,m≥0}.

2. Similarly L(G2)={bn cm an:n,m≥0}. Any G1 word with n>0 starts with a, while any G2 word with positive outer count starts with b. Such words cannot agree.

3. Common words must have zero outer count in both grammars, leaving exactly c*. This contains ε,c,cc,..., so it is infinite and regular. Answer B.

Original paper, page 17 · Answer key

2 marks · MCQ
Report issue

Closure Properties & Language Hierarchy

Question 38, GATE 2017: L1={a^n b^n c^m:m,n≥0}, L2={a^m b^n c^n:m,n≥0}. Which are context-free? I L1∪L2; II L1∩L2. A I only; B II only; C both; D neither.
Tap to enlarge
Your answer
Answer & solution

Official answer: A

1. L1 is context-free: a stack can match a’s with b’s and then ignore a trailing c block. L2 is likewise context-free by ignoring the initial a block and matching b’s with c’s.

2. Context-free languages are closed under union: a new start symbol can choose either constituent grammar. Therefore I holds.

3. Intersection forces #a=#b=#c and preserves block order, giving {an bn cn}. For pumping length p, a pump window of length at most p in ap bp cp touches at most two blocks. Pumping changes some count but leaves a third unchanged, or breaks the block order. Thus it is not context-free; answer A.

Original paper, page 17 · Answer key

2 marks · MCQ
Report issue

Decidability & Computability

Question 39, GATE 2017: A,B are finite alphabets and # belongs to neither. f:A*→B* is total; computable means a Turing machine halts on every x with f(x) on tape. Lf={x#f(x):x∈A*}. A f computable iff Lf recursive; B f computable iff Lf recursively enumerable; C computability implies recursive graph but not conversely; D computability implies RE graph but not conversely. This is printed as a single-choice question.
Tap to enlarge
Your answer
Answer & solution

Official answer: A

Our answer: A and B both valid for total f

1. If f is computable, first reject strings not of form x#y with x∈A*,y∈B*. Otherwise compute f(x), which halts by totality, and compare it with y. This is a decider for Lf, so the graph is recursive and hence RE.

2. Conversely suppose only an RE recognizer for Lf is available. List all y∈B* and simulate the recognizer on x#y in dovetailed rounds, giving every candidate increasingly many steps. Do not run one candidate to completion: a nonmember may loop forever.

3. Because f is total, one candidate y=f(x) exists and will eventually be accepted; function uniqueness ensures it is the right output. This procedure halts for every x and computes f. Thus an RE graph already suffices, and a recursive graph certainly suffices. Both A and B are mathematically true; the protected official single-choice answer A is retained, not treated as eliminating B.

Original paper, page 17 · Answer key

1 mark · MCQ
Report issue

Closure Properties & Language Hierarchy

Question 4, GATE 2017: Let L1,L2 be arbitrary context-free languages and R an arbitrary regular language. Which claims always hold? I:L1∪L2 is context-free. II:complement(L1) is context-free. III:L1−R is context-free. IV:L1∩L2 is context-free. A:I,II,IV. B:I,III. C:II,IV. D:I only.
Tap to enlarge
Your answer
Answer & solution

Official answer: B

1. I holds: take disjoint copies of the two grammars and add a new start production S→S1|S2. The resulting CFG generates their union.

2. III also holds because L1−R=L1∩complement(R). Regular languages are closed under complement, and a PDA for L1 can be combined with a finite automaton for complement(R). Thus the intersection remains context-free.

3. IV fails in general: {an bn cm} and {am bn cn} are CFLs, but their intersection {an bn cn} is not. II cannot hold for all CFLs either, since closure under both complement and union would imply intersection closure by De Morgan's law. Only I and III are guaranteed, B.

Original paper, page 3 · Answer key

1 mark · MCQ
Report issue

Context-Free Grammars & Languages

Question 16, GATE 2017: Start variable S has grammar S→XY, X→aX|a, Y→aYb|ε. Which language is generated? A:{a^m b^n | m≥n,n>0}. B:{a^m b^n | m≥n,n≥0}. C:{a^m b^n | m>n,n≥0}. D:{a^m b^n | m>n,n>0}.
Tap to enlarge
Your answer
Answer & solution

Official answer: C

1. X contributes at least one a: using aX k-1 times and then a gives ak for every k≥1. It cannot derive ε.

2. Y contributes matched numbers of a and b. Applying aYb n times and then ε gives an bn for every n≥0. Therefore XY yields ak+nbn, so m=k+n>n and n may be zero.

3. Conversely, if m>n≥0, choose k=m-n≥1 in X and n matching pairs in Y to derive the desired string. The characterization is exact, C. For example a is generated, ruling out options requiring n>0; equal counts are impossible because X supplies extra a symbols.

Original paper, page 7 · Answer key

1 mark · NAT
Report issue

Finite Automata

Question 25, GATE 2017: Find the minimum number of states of a complete DFA accepting L={w1 a w2 | w1,w2∈{a,b}*, |w1|=2, |w2|≥3}.
Tap to enlarge
Answer & solution

Official answer: 8.0

Our answer: 8

Step through it (2 parts)

1. The first two symbols may be arbitrary, the third must be a, and at least three further symbols must follow. Thus accepted strings have length at least 6 and third symbol a.

2. Construct three states for having read 0,1,2 prefix symbols. From the third of these, a enters a suffix-count state and b enters a rejecting dead state. Use four suffix states for 0,1,2,at least 3 symbols after the required a. The last is accepting and loops on both symbols; the dead state also loops on both. Total: 3+4+1=8 states.

3. To prove minimality, the seven nondead states have distinct shortest accepting continuation lengths 6,5,4,3,2,1,0. For two states, a shortest accepting suffix from the one with smaller required length is too short from the other, distinguishing them. The dead state has no accepting continuation at all. All eight are necessary.

Original paper, page 10 · Answer key

2 marks · MCQ
Report issue

Finite Automata

Question 39, GATE 2017: An ε-NFA has transition table (ε,a,b): q0→({q2},{q1},{q0}); q1→({q2},{q2},{q3}); q2→({q0},∅,∅); q3→(∅,∅,{q2}). Compute the extended transition from q2 on aba. A:∅. B:{q0,q1,q3}. C:{q0,q1,q2}. D:{q0,q2,q3}.
Tap to enlarge
Your answer
Answer & solution

Official answer: C

Step through it (4 steps)

1. Begin with ε-closure({q2}), not just {q2}. The ε edge reaches q0, whose ε edge returns to q2, so the starting set is {q0,q2}.

2. Read the first a: only q0 has an a transition, to q1. The ε-closure of q1 adds q2 and q0, giving {q0,q1,q2}. Read b next: q0 goes to q0 and q1 to q3; q2 has no b move. Closing {q0,q3} under ε adds q2, giving {q0,q2,q3}.

3. Read the final a: only q0 contributes q1. Its ε-closure is again {q0,q1,q2}, option C. Applying ε-closure both before input and after every consumed symbol is essential; ε transitions do not consume letters of aba.

Original paper, page 15 · Answer key

2 marks · MCQ
Report issue

Context-Free Grammars & Languages

Question 40, GATE 2017: L1={a^p | p prime}; L2={a^n b^m c^(2m) | n,m≥0}; L3={a^n b^n c^(2n) | n≥0}; L4={a^n b^n | n≥1}. Which claims hold? I:L1 is CFL but not regular. II:L2 is not CFL. III:L3 is not CFL but recursive. IV:L4 is deterministic CFL. A:I,II,IV. B:II,III. C:I,IV. D:III,IV.
Tap to enlarge
Your answer
Answer & solution

Official answer: D

1. I is false. If L1 were context-free, choose a prime q above its pumping length. Any pumping decomposition increases the unary length by a positive d when pumped once extra. Pumping q extra copies gives length q+qd=q(1+d), a composite number, contradicting membership.

2. II is false: a CFG for L2 is S→aS|B and B→bBcc|ε. It independently generates any number of a symbols, then matches each b with two c symbols.

3. III is true. L3 is decidable by checking symbol order and counting the three runs. If it were CFL, inverse homomorphism under h(a)=a,h(b)=b,h(c)=cc would make {an bn cn} context-free, a contradiction to that standard non-CFL result. IV is true: a deterministic PDA pushes for a symbols, switches on the first b and pops for each b, accepting exactly matching positive counts. Therefore III and IV, D.

Original paper, page 15 · Answer key

2 marks · MCQ
Report issue

Decidability & Computability

Question 41, GATE 2017: Which problems are undecidable? I:given regular expression R and string w, test w∈L(R). II:given CFG G, test L(G)=∅. III:given CFG G over Σ, test L(G)=Σ*. IV:given Turing machine M and string w, test w∈L(M). A:I,IV. B:II,III. C:II,III,IV. D:III,IV.
Tap to enlarge
Your answer
Answer & solution

Official answer: D

1. I is decidable: convert the regular expression to a finite automaton and simulate it on the finite input string. The simulation terminates after processing the input.

2. II is decidable: repeatedly mark CFG variables that can derive terminal strings, beginning with terminal-only or ε productions. Because there are finitely many variables the marking reaches a fixed point. The language is nonempty exactly when the start variable is marked.

3. III is the general CFG universality problem, which is undecidable. IV is Turing-machine acceptance, also undecidable: simulation may run forever on a rejected/nonaccepted input, so it is only a recognizer, not a decider. Thus the undecidable pair is III and IV, D. Do not confuse decidable CFG membership or emptiness with universality.

Original paper, page 16 · Answer key

1 mark · MCQ
Report issue

Context-Free Grammars & Languages

Question 16, GATE 2016: Which language is generated by S→aS | bS | ε? A: {a^n b^m:n,m≥0}. B: All words over {a,b} with equal numbers of a and b. C: {a^n:n≥0} union {b^n:n≥0} union {a^n b^n:n≥0}. D: {a,b}*.
Tap to enlarge
Your answer
Answer & solution

Official answer: D

At every step S can emit either a or b and recurse, then terminate with epsilon. Every finite binary-alphabet word, including epsilon, is generated, giving {a, b}*, D.

For any desired word w, choose the production beginning with its next character repeatedly, then use S→ε after its final character. For example baba follows S⇒bS⇒baS⇒babS⇒babaS⇒baba. Conversely, every production emits only a or b, so no other alphabet symbols can appear. This two-direction argument proves equality with {a,b}*, rather than merely showing a few example strings are generated. The ε production explicitly includes the empty word.

Original paper, page 8 · Answer key

1 mark · MCQ
Report issue

Decidability & Computability

Question 17, GATE 2016: Which decision problems are undecidable? I: Given NFAs N1,N2, is L(N1) intersection L(N2) empty? II: Given CFG G and string x, is x in L(G)? III: Given CFGs G1,G2, are their languages equal? IV: Given Turing machine M, is L(M) empty? A: I,IV. B: II,III. C: III,IV. D: II,IV.
Tap to enlarge
Your answer
Answer & solution

Official answer: C

NFA intersection emptiness is decidable by product-automaton reachability. CFG membership is decidable by parsing. Equivalence of arbitrary CFGs is undecidable, and TM-language emptiness is a nontrivial semantic property covered by Rice’s theorem. Thus III and IV, C.

For I, the product automaton accepts exactly the intersection, and finite graph search checks whether an accepting state is reachable. For II, a finite input can be handled by a terminating CFG parsing algorithm. Neither argument extends to III: comparing all words of two arbitrary CFGs is an undecidable equivalence problem. For IV, empty-language and nonempty-language Turing machines both exist, making emptiness a nontrivial property of recognized languages and hence undecidable by Rice's theorem.

Original paper, page 9 · Answer key

1 mark · MCQ
Report issue

Regular Expressions & Languages

Question 18, GATE 2016: Let Σ={0,1}; + denotes union and * Kleene star. Which regex specifies strings containing both 00 and 11 as substrings? A: Σ*0011Σ*+Σ*1100Σ*. B: Σ*(00Σ*11+11Σ*00)Σ*. C: Σ*00Σ*+Σ*11Σ*. D:00Σ*11+11Σ*00.
Tap to enlarge
Your answer
Answer & solution

Official answer: B

A word must contain both a 00 occurrence and a 11 occurrence, in either order, with an arbitrary middle substring and arbitrary prefix/suffix. They cannot overlap because their symbols differ. Hence Σ*(00Σ*11+11Σ*00)Σ*, B. A forces adjacent blocks, C requires only one, and D disallows arbitrary outside context.

Take the earlier of a 00 occurrence and a 11 occurrence. Their positions cannot overlap, so one appears before the other with some possibly empty substring between them. This establishes the two alternatives in B. As a diagnostic example,001011 has both required pairs separated by 10, so it is valid but A rejects it. C incorrectly accepts 00 alone; D rejects valid words with extra prefix or suffix. Arbitrary prefix, middle and suffix are all needed.

Original paper, page 9 · Answer key

2 marks · MCQ
Report issue

Context-Free Grammars & Languages

Question 42, GATE 2016: Consider grammars G1:S→aS|B, B→b|bB; and G2:S→aA|bB, A→aA|B|ε, B→bB|ε. All options describe languages {a^m b^n} with nonnegative integer exponents. Which pair of constraints corresponds to G1,G2 respectively? A:(m>0 or n>0),(m>0 and n>0). B:(m>0 and n>0),(m>0 or n≥0). C:(m≥0 or n>0),(m>0 and n>0). D:(m≥0 and n>0),(m>0 or n>0).
Tap to enlarge
Your answer
Answer & solution

Official answer: D

G1 emits any number of initial a symbols, then at least one b, so its language is am bn with m≥0, n>0. G2 chooses an initial a or b, then permits all remaining a symbols before its b symbols; it generates every nonempty am bn and not epsilon. Thus m>0 or n>0, giving D.

In G1 the only way to eliminate S is to enter B, and B has no ε rule, so a b is compulsory. In G2 the first production emits a or b, ruling out ε; after that, ε rules allow stopping. Once a derivation enters B, it emits only b symbols, so neither grammar can place an a after a b. Witnesses distinguish boundaries: b is in both languages, a is in G2 only, and ε is in neither. These tests select the inequalities in D.

Original paper, page 16 · Answer key

2 marks · MCQ
Report issue

Pushdown Automata

Question 43, GATE 2016: A PDA over input {a,b}, stack {X,Z}, starts with stack Z. Its start state q0 and state q2 are accepting; q1 is not. q0 loops on a,X/XX and a,Z/XZ; q0→q1 is b,X/ε; q1 loops on b,X/ε; q1→q2 is ε,Z/Z. There are no other transitions. Acceptance is by final state after consuming the whole input. Which statement is true? A:L={a^n b^n:n≥0}, not finite-automaton recognizable. B:L=a* union {a^n b^n:n≥0}, not accepted by any deterministic PDA. C:L is not accepted by any Turing machine halting on all inputs. D:L=a* union {a^n b^n:n≥0}, and is deterministic context-free.
Tap to enlarge
Your answer
Answer & solution

Official answer: D

The initial state is accepting, so epsilon and every a-only word are accepted while pushing one X per a. On the first b the machine moves to the middle state and pops one X per b; it reaches the final accepting state only when the stack returns to Z. Therefore the additional accepted words are an bn. The displayed machine is deterministic: at each state/stack combination the input transitions do not compete with epsilon transitions. The language is a* union {an bn: n≥0}, a deterministic CFL, D.

Final-state acceptance does not require an empty stack. This is why an all-a input is accepted in q0 even with X symbols left above Z, and why the double circle on the start state matters. Once a b occurs the machine cannot return to q0 or read further a symbols. It can reach q2 exactly after the number of b symbols matches the pushed X count. At q1, b-transitions require top X whereas the ε-transition requires top Z, so they are never simultaneously enabled; determinism is preserved.

Original paper, page 17 · Answer key

2 marks · MCQ
Report issue

Decidability & Computability

Question 44, GATE 2016: X is recursive; Y is recursively enumerable but not recursive. There are computable many-one reductions complement(Y)≤m W and Z≤m complement(X). Which conclusion is correct? A:W can be recursively enumerable and Z is recursive. B:W can be recursive and Z is recursively enumerable. C:W is not recursively enumerable and Z is recursive. D:W is not recursively enumerable and Z is not recursive. The complement bars are part of the printed source, although plain PDF extraction omits them.
Tap to enlarge
Your answer
Answer & solution

Official answer: C

The source has complement bars: complement(Y) reduces to W, and Z reduces to complement(X). Since Y is RE but not recursive, complement(Y) cannot be RE, otherwise dovetailing the two recognizers would decide Y. RE languages are closed under computable many-one preimages, so W cannot be RE. X recursive implies complement(X) recursive, and its computable preimage Z is recursive. Hence C.

The direction of the reduction is crucial. To recognize complement(Y) from a recognizer for W, compute the reduction image and run that recognizer. Thus if W were RE, complement(Y) would be RE, contradicting the fact that an RE language with an RE complement is decidable. For Z, compute its reduction image and run the decider for complement(X), which halts on all inputs. This closure argument proves Z recursive without assuming anything about its syntax or structure.

Original paper, page 17 · Answer key

1 mark · NAT
Report issue

Finite Automata

Question 16, GATE 2016: How many states does a minimum DFA need for (0+1)*(0+1)(0+1)*, where + denotes union?
Tap to enlarge
Answer & solution

Official answer: 2.0 : 2.0

Our answer: 2

Step through it (2 parts)

The expression Σ*ΣΣ* is exactly the nonempty binary strings. Use a nonaccepting start state and one accepting state reached by either symbol, with both loops on the latter. The empty string differs from every nonempty word, so at least two states are necessary.

The mandatory middle (0+1) contributes at least one symbol, while the starred parts may be empty. The transition table is start:0→accept,1→accept; accept:0→accept,1→accept. The empty suffix distinguishes start from accept because only one is accepting, establishing minimality rather than merely constructing a two-state automaton.

Original paper, page 29 · Answer key

1 mark · MCQ
Report issue

Context-Free Grammars & Languages

Question 17, GATE 2016: L1 has grammar S1→aS1b|ε, and L2 has S2→abS2|ε. P: L1 is regular; Q: L2 is regular. A both; B P only; C Q only; D neither.
Tap to enlarge
Your answer
Answer & solution

Official answer: C

L1={an bn: n≥0}, nonregular by pumping/distinguishable prefixes. L2=(ab)* is regular. Therefore P false, Q true, C.

Each use of S1→aS1b adds one a and one b at opposite ends; ε stops the derivation. Pumping an a-prefix of ap bp changes only the a count, proving nonregularity. In contrast, S2 repeatedly appends the fixed block ab; a three-state complete DFA can check alternating a,b blocks and reject violations.

Original paper, page 29 · Answer key

1 mark · MCQ
Report issue

Closure Properties & Language Hierarchy

Question 18, GATE 2016: L1 is regular, L2 context-free, L3 recursive and L4 recursively enumerable. Which are always true? I ¬L3∪L4 is RE; II ¬L2∪L3 is recursive; III L1*∩L2 is context-free; IV L1∪¬L2 is context-free. Complements use the common alphabet-star. A I only; B I,III; C I,IV; D I,II,III.
Tap to enlarge
Your answer
Answer & solution

Official answer: D

The source complement bars matter. I: complement(L3) is recursive and its union with RE L4 is RE. II: every CFL is recursive, so complement(L2) and its union with recursive L3 are recursive. III: L1* is regular and its intersection with a CFL is CFL. IV is not guaranteed because taking L1 empty leaves complement(L2), and CFLs are not closed under complement. Thus I, II, III, D.

Do not confuse “not context-free” with “undecidable.” Every CFL has a terminating membership algorithm, so its complement is decidable even though it may cease to be context-free. For III, run a finite automaton for L1* alongside a pushdown automaton for L2. The finite control adds no second stack, preserving context-freeness.

Original paper, page 30 · Answer key

2 marks · MCQ
Report issue

Finite Automata

Question 42, GATE 2016: I: If all NFA states accept, its language is Σ*. II: There exists a regular language A for which A∩B is regular for every language B. A I only; B II only; C both; D neither.
Tap to enlarge
Your answer
Answer & solution

Official answer: B

An NFA can have missing transitions. One accepting start state with no transitions accepts only epsilon, not Σ* for a nonempty alphabet, disproving I. For II choose the regular language A=empty set; its intersection with every B is empty and hence regular. Thus only II, B.

Acceptance by an NFA requires at least one complete run consuming the entire word. An accepting state alone cannot consume an unavailable transition; for the one-state counterexample any nonempty word has no run. II is existential in A but universal in B, so choosing a fixed empty A handles even nonregular or undecidable B at once.

Original paper, page 37 · Answer key

2 marks · MCQ
Report issue

Context-Free Grammars & Languages

Question 43, GATE 2016: L1={a^n b^m c^(n+m):m,n≥1}; L2={a^n b^n c^(2n):n≥1}. A both context-free; B only L1; C only L2; D neither.
Tap to enlarge
Your answer
Answer & solution

Official answer: B

L1 is generated by S→aSc|aBc and B→bBc|bc: each a or b adds one trailing c, with positive counts of both. Thus L1 is context-free. If L2 were context-free, its inverse image under h(a)=a, h(b)=b, h(c)=cc would be {an bn cn: n≥1}, which is not context-free by the pumping lemma. CFL closure under inverse homomorphism therefore proves L2 non-context-free. Answer B.

A pushdown intuition for L1 pushes one marker per a or b and pops one per c, with finite control enforcing the a-then-b-then-c phases. L2 must enforce three linked quantities. Under h(c)=cc, an input an bn cn maps exactly to an bn c2n, transferring the known non-CFL obstruction through inverse homomorphism.

Original paper, page 37 · Answer key

2 marks · MCQ
Report issue

Decidability & Computability

Question 44, GATE 2016: Let L1={⟨M⟩:M takes at least 2016 steps on some input}, L2={⟨M⟩:M takes at least 2016 steps on all inputs}, L3={⟨M⟩:M accepts ε}. Which are recursive? A only L1; B only L2; C L1 and L2 only; D all three.
Tap to enlarge
Your answer
Answer & solution

Official answer: C

Whether a machine takes at least 2016 steps depends only on its first 2016-step computation prefix. In that time its input head can inspect only a bounded initial segment, so finitely many representative inputs suffice: all short inputs and one representative extension for each sufficiently long prefix. Simulate each for the fixed bound and test whether any (L1) or every (L2) representative survives that many steps. Both tests halt. Acceptance of epsilon (L3) is undecidable by the standard reduction that builds a machine ignoring its input and simulating an arbitrary machine/input pair. Hence C.

The constant 2016 is essential: this is bounded simulation, not the general halting problem. A machine cannot inspect arbitrarily far into its input in a fixed number of steps. For L3, given M,w, construct N that ignores its own input and simulates M on w, accepting iff M accepts w. Deciding whether N accepts ε would decide the undecidable acceptance problem.

Original paper, page 38 · Answer key

1 mark · MCQ
Report issue

Closure Properties & Language Hierarchy

Question 28, GATE 2015: L1 is context-free; L2 is recursively enumerable but not recursive. Which must hold? I complement(L1) is recursive; II complement(L2) is recursive; III complement(L1) is context-free; IV complement(L1)∪L2 is recursively enumerable. A I only; B III only; C III and IV; D I and IV.
Tap to enlarge
Your answer
Answer & solution

Official answer: D

A CFL has a terminating membership algorithm, so it and its complement are recursive. If complement(L2) had a decider, exchanging accept/reject would decide L2, a contradiction. CFL closure under complement fails in general, so III is not necessary. For IV, first decide whether the input is outside L1; accept if so, otherwise run the recognizer for L2. That algorithm recognizes the union and may loop only for nonmembers.

Solution: Every CFL is decidable, so complement(L1) is recursive. The complement of nonrecursive L2 cannot be recursive, because recursive languages are closed under complement. CFLs are not closed under complement. Since complement(L1) is recursive and L2 is RE, their union is RE by dovetailing recognizers. Hence I and IV, D.

Original paper, page 11 · Answer key

2 marks · NAT
Report issue

Finite Automata

Question 49, GATE 2015: Two complete DFAs over {a,b} each have start nonfinal state 0 and final state 1. M: on a, either state goes to 1; on b, either goes to 0. N: on a, either goes to 0; on b, either goes to 1. Find states in a minimal DFA for L(M)∩L(N).
Tap to enlarge
Answer & solution

Official answer: 1

M records whether the most recent symbol is a; N records whether it is b. Empty input is rejected by both initial states. A nonempty string cannot end in both symbols, so no string belongs to the intersection. Although a mechanical product construction offers up to four states, minimization merges all reachable states into one rejecting sink because every continuation is rejected. A DFA still requires its start state, so the answer is not zero.

Solution: The first DFA accepts exactly strings ending in a, and the second exactly strings ending in b. Their intersection is empty. The minimal complete DFA for the empty language is one nonaccepting state with loops on both symbols, so 1.

Original paper, page 18 · Answer key

2 marks · MCQ
Report issue

Pushdown Automata

Question 50, GATE 2015: NPDA states q0(start),q1,q2(final), stack bottom ⊥. At q0 read b∈{0,1} and push b; transition to q1 may consume 0,1,or ε without changing stack. At q1 read 0 and pop 1, or read 1 and pop 0. With only ⊥ left, ε-pop it and enter q2. Which suffix appended to 101100 is accepted? A 10110; B 10010; C 01010; D 01001.
Tap to enlarge
Your answer
Answer & solution

Official answer: B

The push phase remembers a prefix in reverse order; the pop phase checks its complemented reverse. Thus accepted strings have form w z complement(reverse(w)), where z is empty or one symbol. Every listed concatenation has eleven symbols, forcing |w|=5 and one middle symbol. Here w=10110, middle=0, and reverse(w)=01101. Complementing gives 10010. The nondeterministic phase switch is constrained by total length, so one cannot push all six supplied prefix bits.

Solution: The NPDA pushes a prefix, optionally consumes a middle symbol while changing phase, then pops only on the complementary symbol. The full listed strings have length 11, so the first five symbols 10110 are pushed and the sixth 0 is the middle. The remaining five must be the complement of the reversed prefix: reverse 10110=01101, complement 10010. Thus B.

Original paper, page 18 · Answer key

1 mark · MCQ
Report issue

Decidability & Computability

Question 20, GATE 2015: Assess I complement of every decidable language is decidable; II some language is in NP but undecidable; III every NP language is decidable. A II only; B III only; C I and II; D I and III.
Tap to enlarge
Your answer
Answer & solution

Official answer: D

A decider halts on every input, so exchanging accept and reject decides the complement. An NP computation has a finite polynomially bounded certificate/search tree, which a deterministic machine can exhaust, so every NP language is decidable. I and III hold, II fails: D.

A language in NP has a polynomially bounded certificate verifier. A deterministic decider can enumerate every certificate up to that finite bound and run the verifier, halting with yes if one works and no otherwise. This may be exponential but still terminates, so III is true and II is false. A decider for a complement simply reverses the yes/no outcomes of a halting decider, so I is also true. Distinguish decidability from efficient decidability.

Original paper, page 33 · Answer key

1 mark · MCQ
Not in GATE 2027 syllabusReport issue

Complexity & Reductions

Question 26, GATE 2015: Q1≤p3-SAT≤pQ2. Which is “consistent” with this? A Q1 in NP, Q2 NP-hard; B Q2 in NP, Q1 NP-hard; C both in NP; D both NP-hard. Official choice interprets the question as what is necessarily implied.
Tap to enlarge
Your answer
Answer & solution

Official answer: A

Our answer: A is guaranteed; all choices can be consistent

A polynomial reduction Q1≤p3-SAT implies Q1∈NP, by composing the reduction with a 3-SAT verifier. The reduction 3-SAT≤pQ2 makes Q2 NP-hard. Thus A is necessarily implied. The literal word consistent is weaker: taking Q1=Q2=3-SAT satisfies all four options simultaneously. The key A requires reading the question as asking what is guaranteed, not merely possible.

A reduction from Q1 to 3-SAT converts a Q1 instance in polynomial time and lets an NP verifier check the resulting formula certificate, so Q1 belongs to NP. A reduction in the other direction from an NP-complete problem to Q2 shows Q2 is at least as hard as every NP problem, so it is NP-hard; it need not belong to NP. These are directional implications, not equivalence. Literal consistency is weaker than logical entailment: choosing both problems equal to 3-SAT makes every listed classification possible, which is why the source wording is explicitly qualified.

Original paper, page 34 · Answer key

2 marks · NAT
Report issue

Finite Automata

Question 45, GATE 2015: How many states does the minimal DFA for(0+1)*(10)have?
Tap to enlarge
Answer & solution

Official answer: 3

Step through it (2 parts)

The language consists of binary strings ending 10. Track no matching suffix, suffix 1, and suffix 10 (accepting). On0 the transitions are q0, q2, q0; on 1 all go to q1. These three states are distinguishable: q2 accepts empty suffix, and suffix 0 distinguishes q1 from q0. Thus 3.

Track the longest suffix that is also a prefix of target 10: empty, 1, and 10. Reading 1 always leaves suffix 1. Reading 0 moves from suffix 1 to accepting 10, and otherwise to empty. These three states suffice. They are also necessary: accepting 10 differs from both nonaccepting states on ε, and suffix 1 differs from empty on continuation 0. This distinguishability proof prevents merely guessing the count from the pattern length.

Original paper, page 41 · Answer key

2 marks · MCQ
Report issue

Regular Expressions & Languages

Question 46, GATE 2015: Which languages are regular? L1={wxw^R:w, x∈{a, b}*, |w|, |x|>0}; L2={a^n b^m:m≠n, m, n≥0}; L3={a^p b^q c^r:p, q, r≥0}. A L1, L3; B L2 only; C L2, L3; D L3 only.
Tap to enlarge
Your answer
Answer & solution

Official answer: A

L1 consists exactly of length≥3 strings with equal first/last symbols: choose the one-symbol w and nonempty interior x. Its regex is a(a+b)(a+b)*a + b(a+b)(a+b)*b, so regular. If L2 were regular, subtracting it from a*b* would make{an bn} regular, contradiction. L3=a*b*c* is regular. Thus L1, L3, A.

In L1, the first and last symbols must agree because w and its reversal surround x. Conversely, any length≥3 string with equal ends can choose a one-symbol w and the nonempty middle as x, so that simple description is exact and regular. L2 is the unequal-count complement within a*b*. If it were regular, subtracting it from regular a*b* would make the equal-count language regular, contradicting its pumping argument. L3 has the direct regular expression a*b*c*. Thus A contains exactly the regular choices.

Original paper, page 41 · Answer key

2 marks · MCQ
Report issue

Regular Expressions & Languages

Question 60, GATE 2015: Solve language equations X0=1X1, X1=0X1+1X2, X2=0X1+{ε}, where concatenation and union have their regular-expression meanings. Determine X0; option C is 1(0+10)*1. Options: A 10(0*+(10)*)1; B 10(0*+(10)*)*1; C 1(0+10)*1; D 10(0+10)*1+110(0+10)*1.
Tap to enlarge
Your answer
Answer & solution

Official answer: C

Substitute X2=0X1+{epsilon} into X1=0X1+1X2 to obtain X1=(0+10)X1+1. Since the repeated-prefix language excludes epsilon, Arden’s lemma gives X1=(0+10)*1. Then X0=1X1=1(0+10)*1, C. The source’s X2 right side is 0X1, not 0X2.

Substitute X2 into X1: X1=0X1+1(0X1+ε)=(0+10)X1+1. Arden’s lemma says X=AX+B has unique solution A*B when ε is not in A. Here A={0, 10} excludes ε, giving X1=(0+10)*1. Prefixing the initial equation by 1 yields X0=1(0+10)*1. This expression includes 11 via zero repetitions and may add either 0 or 10 in the middle; using the wrong variable in the X2 equation would yield a different language.

Original paper, page 49 · Answer key

1 mark · MCQ
Report issue

Finite Automata

Question 32, GATE 2015: Let Σ={0,1} and L be the language of the regular expression Σ*0011Σ*. What is the minimum number of states in a DFA recognizing the complement of L? Options: (A) 4; (B) 5; (C) 6; (D) 8.
Tap to enlarge
Your answer
Answer & solution

Official answer: B

1. Writing states as matched-prefix lengths 0..4, transitions on (0,1) are 0→(1,0), 1→(2,0), 2→(2,3), 3→(1,4), 4→(4,4). For pattern containment only state 4 accepts; for its complement states 0..3 accept. For any i<j, the suffix completing prefix length j reaches state 4 from j but not from i, proving distinguishability.

2. A DFA tracks the longest suffix matching a prefix of 0011: lengths 0, 1, 2, 3, 4, with 4 an absorbing found-pattern state. These five states are pairwise distinguishable by completing the pattern; flipping accepting states recognizes avoidance of 0011 without changing minimal state count. Thus5, B.

Original paper, page 64 · Answer key

2 marks · MCQ
Not in GATE 2027 syllabusReport issue

Complexity & Reductions

Question 41, GATE 2015: Suppose L1 is polynomial-time reducible to L2, L3 is polynomial-time reducible to L2, and L2 is polynomial-time reducible to L4. Which statements follow? I: If L4∈P, then L2∈P. II: If L1∈P or L3∈P, then L2∈P. III: L1∈P iff L3∈P. IV: If L4∈P, then L1∈P and L3∈P. Options: (A) II only; (B) III only; (C) I and IV only; (D) I only.
Tap to enlarge
Your answer
Answer & solution

Official answer: C

1. The reductions are L1≤pL2, L3≤pL2, L2≤pL4.

2. If L4∈P, compose reductions with its decider to place L2, L1, L3 in P. Thus I and IV. Easy source languages do not imply an easy target; L1 and L3 need not share complexity. For example choose one empty and the other a non-P language reducing to the common target. Hence C.

Original paper, page 67 · Answer key

2 marks · MCQ
Report issue

Context-Free Grammars & Languages

Question 44, GATE 2015: Which languages are context-free? L1={a^m b^n a^n b^m | m,n≥1}; L2={a^m b^n a^m b^n | m,n≥1}; L3={a^m b^n | m=2n+1}. Exponents denote nonnegative integer counts unless constrained otherwise. Options: (A) L1 and L2 only; (B) L1 and L3 only; (C) L2 and L3 only; (D) L3 only.
Tap to enlarge
Your answer
Answer & solution

Official answer: B

1. L1=am bn an bm has nested dependencies: S→aSb|aTb and T→bTa|ba generates m, n≥1, so it is CFL.

2. L3 is generated by U→aaUb|a for n≥0. L2=am bn am bn is not CFL: for pumping length p, choose ap bp ap bp. The pumping window of length≤p touches at most two adjacent blocks, so pumping changes at least one block but cannot change its corresponding nonadjacent equal block; if a pumped piece crosses a boundary, pumping can also destroy the four-block form. Thus pumping fails. L1, L3 only, B.

Original paper, page 68 · Answer key

1 mark · MCQ
Report issue

Regular Expressions & Languages

Question 15, GATE 2014: Which language is regular? A: {aⁿbⁿ:n≥0}. B: {aⁿ:n is prime}. C: {w over {a,b}: w contains 3k+1 occurrences of b for some k∈ℕ}. D: {ww:w∈{0,1}*}.
Tap to enlarge
Your answer
Answer & solution

Official answer: C

1. Method and setup. Finite-state memory can retain a count modulo a fixed constant, but cannot in general remember arbitrary equal block lengths, primality of unbounded lengths, or an arbitrary string for exact copying. For C, use states representing residues 0,1,2 of the b-count; a leaves the state unchanged and b advances it cyclically.

2. Work through the result and its assumptions. A DFA can count b symbols modulo 3 while ignoring a, accepting the residue 1 class; if natural k excludes 0, a finite initial-count adjustment still makes it regular. The equal-count language is nonregular by pumping; unary prime lengths are not ultimately periodic. The copy language is nonregular: intersection with 0*1*0*1* yields 0i1j0i1j, whose equal nonadjacent blocks defeat pumping on 0p1p0p1p. Thus only C.

Original paper, page 10 · Answer key

1 mark · MCQ
Report issue

Finite Automata

Question 16, GATE 2014: An NFA starts at q₀ and has accepting state q₃. Its transitions are q₀→q₀ on 0 or 1; q₀→q₁ on 1; q₁→q₂ on 0 or 1; q₂→q₂ on 1; q₂→q₃ on 0 or 1. There are no other transitions. Which states are reachable after reading 0011? A: {q₀,q₁,q₂}. B: {q₀,q₁}. C: {q₀,q₁,q₂,q₃}. D: {q₃}.
Tap to enlarge
Your answer
Answer & solution

Official answer: A

1. Method and setup. Track a set of active states after each symbol; an NFA can follow several transitions at once. Each update uses only the states active before that symbol, so a newly reached q₂ cannot immediately take another transition on the very same input symbol. Acceptance is separate from the requested reachable-state set.

2. Work through the result and its assumptions. Starting at{q0}, the two zeros leave{q0}. The first 1 yields{q0, q1}; the second 1 yields{q0, q1, q2}. No q2 was reached early enough to enter q3. Thus A.

Original paper, page 11 · Answer key

2 marks · MCQ
Report issue

Decidability & Computability

Question 35, GATE 2014: Let L̅ be the complement of language L. Which situation is impossible? A: Neither L nor L̅ is recursively enumerable (r.e.). B: One is r.e. but nonrecursive and the other is not r.e. C: Both are r.e. but nonrecursive. D: Both are recursive.
Tap to enlarge
Your answer
Answer & solution

Official answer: C

1. Method and setup. A recognizer may loop forever on a nonmember, whereas a decider must halt on every input. If recognizers exist for both complementary sides, simulate their steps alternately. Every input belongs to exactly one side, so one simulation eventually accepts, allowing a halting membership decision.

2. Work through the result and its assumptions. If both a language and its complement have recognizers, dovetail them on the input; exactly one eventually accepts, deciding membership. Both would therefore be recursive. Hence both being r.e. but nonrecursive is impossible, C. The other possibilities occur, including non-r.e./non-co-r.e. languages.

Original paper, page 16 · Answer key

2 marks · MCQ
Report issue

Finite Automata

Question 36, GATE 2014: A two-state DFA over {0,1} starts in nonaccepting state u and has accepting state v. Transitions are u--0→u, u--1→v, v--0→u, v--1→v. Which expressions describe its language? I: 0*1(1+00*1)*. II: 0*1*1+11*0*1. III: (0+1)*1. Here + is union. A: I,II only. B: I,III only. C: II,III only. D: all three.
Tap to enlarge
Your answer
Answer & solution

Official answer: B

1. Method and setup. Read the invariant of the DFA: after any nonempty input, v means the latest symbol was 1, and u means it was 0. The empty word is rejected. Test the expressions against this exact language, not just a few accepted examples; one accepted word missing from II disproves equivalence.

2. Work through the result and its assumptions. The two-state DFA accepts precisely strings ending 1. Expression III states this directly. In I, an initial 0*1 is followed by repetitions of either 1 or a nonempty block of zeros followed by 1, so it describes exactly the same strings. II omits 0101, which the DFA accepts. Thus I and III, B.

Original paper, page 16 · Answer key

2 marks · MCQ
Not in GATE 2027 syllabusReport issue

Complexity & Reductions

Question 38, GATE 2014: Suppose a polynomial-time algorithm finds a largest clique in any graph. Which Venn diagram then describes P, NP and NP-complete (NPC)? A: NP is an outer region containing disjoint P and NPC regions. B: P and NP partially overlap, with NPC in their intersection. C: P=NP is the outer region and NPC is a proper inner subset. D: P=NP=NPC is one region.
Tap to enlarge
Your answer
Answer & solution

Official answer: D

Our answer: C under standard many-one completeness; official D simplifies away trivial languages

1. Method and setup. The optimization algorithm decides whether a clique of size at least k exists, placing the NP-complete decision problem CLIQUE in P. Hence every NP problem becomes polynomial-time decidable. The remaining question is whether all members of P qualify as NP-complete under the chosen reduction convention; trivial languages are the important exception.

2. Work through the result and its assumptions. A polynomial maximum-clique algorithm decides CLIQUE in polynomial time, so NP-completeness implies P=NP. Every nontrivial language in P is then NP-complete: decide an NP source and map yes/no instances to fixed yes/no target strings. But ∅ and Σ* are in P and cannot be NP-hard under many-one reductions because a nontrivial language cannot reduce to either. Thus NPC is a proper subset of P=NP, diagram C. Official D is valid only after excluding these trivial languages or changing the reduction convention; keep this discrepancy explicit.

Original paper, page 17 · Answer key

1 mark · MCQ
Report issue

Regular Expressions & Languages

Question 15, GATE 2014: Let L1={a^n:n≥0} and L2={b^n:n≥0}. Statements: I L1·L2 is regular; II L1·L2={a^n b^n:n≥0}. Which are correct? A only I; B only II; C both; D neither.
Tap to enlarge
Your answer
Answer & solution

Official answer: A

1. Set up the reasoning. The variable n in each set definition is locally bound. Concatenation independently chooses any word from L1 and any word from L2, so it does not require their lengths to agree.

2. Derive the result. The concatenation is a*b*: choose the number of a symbols and the number of b symbols independently. This is regular, but it includes ab² and so is not the equal-count language. Only I holds, A.

3. Check the interpretation. The regular expression a*b* describes the concatenation. The witness abb belongs to it but not to the equal-count language in II, immediately separating the two claims.

Original paper, page 32 · Answer key

1 mark · MCQ
Report issue

Decidability & Computability

Question 16, GATE 2014: Write A≤mB for a computable many-to-one reduction from language A to B. Which claim is false? A If A≤mB and B is recursive, A is recursive. B If A≤mB and A is undecidable, B is undecidable. C If A≤mB and B is recursively enumerable, A is recursively enumerable. D If A≤mB and B is not recursively enumerable, A is not recursively enumerable.
Tap to enlarge
Your answer
Answer & solution

Official answer: D

1. Set up the reasoning. A reduction f satisfies x∈A iff f(x)∈B and halts on every input. Compose f with a decider or recognizer for B to transfer positive algorithmic properties backward to A.

2. Derive the result. A computable mapping followed by a decider or recognizer for B supplies the corresponding algorithm for A, proving A and C; B is the contrapositive of A. D reverses this implication. For example, an empty decidable language can reduce by a constant map to a fixed nonmember of a non-r.e. language. Thus D is false.

3. Check the interpretation. Hardness transfers forward: if A is undecidable then B cannot be decidable. It does not transfer backward from a hard B to an easy A. For D, choose A empty and map every input to one fixed nonmember of a non-r.e. B.

Original paper, page 32 · Answer key

2 marks · MCQ
Report issue

Decidability & Computability

Question 35, GATE 2014: Let ⟨M⟩ be a binary encoding of a Turing machine. Define L={⟨M⟩:M accepts at least one string of length 2014}. What is L? A decidable and recursively enumerable; B undecidable but recursively enumerable; C undecidable and not recursively enumerable; D decidable but not recursively enumerable.
Tap to enlarge
Your answer
Answer & solution

Official answer: B

1. Set up the reasoning. Although there are finitely many length-2014 inputs, a simulation on one may never halt. To recognize L, interleave steps of all 22014 simulations rather than running them to completion one at a time.

2. Derive the result. Dovetail M on all finitely many binary strings of length 2014; accept its encoding when any simulation accepts, so L is r.e. It is undecidable: from machine N and input w, build M that on one fixed 2014-bit string simulates N(w), accepting iff that simulation accepts, and rejects all other inputs. A decider for L would decide acceptance. Thus B.

3. Check the interpretation. Finiteness of the input set does not decide nonacceptance. For undecidability, encode an arbitrary acceptance problem into a machine that simulates that problem on one fixed length-2014 word and rejects other words. A decision procedure for L would decide the original acceptance problem.

Original paper, page 39 · Answer key

2 marks · MCQ
Report issue

Regular Expressions & Languages

Question 36, GATE 2014: L1 consists of binary strings with at least as many occurrences of substring 110 as 011. L2 consists of binary strings with at least as many occurrences of 000 as 111. Which is true? A L1 regular, L2 not; B L2 regular, L1 not; C both regular; D neither regular.
Tap to enlarge
Your answer
Answer & solution

Official answer: A

1. Set up the reasoning. Count overlapping occurrences. For L1, examine maximal runs of at least two 1s: an entering 0 produces one 011 and a leaving 0 produces one 110. Every internal run contributes one of each.

2. Derive the result. For each maximal run of at least two 1s, an entering 0 contributes one 011 and a leaving 0 contributes one 110. Internal runs cancel; hence #110−#011 equals the indicator that the string starts 11 minus the indicator that it ends 11. A finite automaton can track these boundary facts, so L1 is regular. Intersect L2 with 0³0*1³1*: the resulting language is{0m1n: m≥n≥3}, because occurrences number m−2 and n−2. This is not regular: pumping down a zero in 0p1p violates m≥n. Thus L2 is not regular, A.

3. Check the interpretation. Only boundary runs can leave an imbalance, requiring finite memory. For L2, intersect with the regular pattern 0m1n, m,n≥3; counts become m-2 and n-2, demanding the unbounded comparison m≥n. Pumping zeros down from 0p1p contradicts regularity.

Original paper, page 39 · Answer key

2 marks · NAT
Report issue

Other / Mixed Topics

Question 37, GATE 2014: For A="qpqrr" and B="pqprqrp", let x be the length of a longest common subsequence, not necessarily contiguous, and y the number of distinct such longest subsequence strings. Find x+10y. The source says “number of such longest common subsequences”; the distinct-string convention is used by the keyed result.
Tap to enlarge
Answer & solution

Official answer: 34

Step through it (37 steps)

1. Set up the reasoning. Try to embed the entire five-letter A in B first. After choosing q,p,q in order in B, only one trailing r remains, so no length-five common subsequence exists. Then enumerate the distinct strings obtained by deleting one character from A.

2. Derive the result. The longest common subsequence length for qpqrr and pqprqrp is 4. The distinct length 4 common strings are pqrr, qpqr, qprr. The entire 5-letter first string is not a subsequence of the second, so no longer one exists. Therefore x+10y=4+30=34, counting distinct subsequence strings rather than embeddings.

3. Check the interpretation. Deleting the first, second, or third character gives pqrr, qqrr, qprr; deleting either final r gives qpqr. Of these, qqrr is not a subsequence of B, leaving three distinct length-four strings. Repeated embeddings of one string are not counted separately.

Original paper, page 39 · Answer key

1 mark · NAT
Report issue

Regular Expressions & Languages

Question 15, GATE 2014: Over alphabet {a,b}, consider the regular expression a*b*(ba)*a*. What is the length of a shortest string outside its language?
Tap to enlarge
Answer & solution

Official answer: 3

Step 1: A shortest counterexample requires checking every shorter length. The empty string is obtained by choosing zero repetitions everywhere; a and b are generated by their star factors. Step 2: All length-two strings occur: aa from a*, ab from a*b*, bb from b*, and ba from (ba)*. Step 3: The length-three word bab is absent. Without any ba pair, a*b*a* cannot switch back to b after a trailing a. If a ba pair is used, the remaining final b cannot be produced by the final a*, and extra pairs are too long. Step 4: Hence no shorter string is missing, while bab is missing, so the answer is 3.

Original paper, page 56 · Answer key

1 mark · MCQ
Report issue

Other / Mixed Topics

Question 16, GATE 2014: For a finite nonempty alphabet Σ, let Σ* be all finite strings and 2^(Σ*) its power set. Which is true? A both countable; B power set countable and Σ* uncountable; C power set uncountable and Σ* countable; D both uncountable.
Tap to enlarge
Your answer
Answer & solution

Official answer: C

Step 1: For each length k there are finitely many strings, |Σ|^k. Listing by increasing length and lexicographically within a length enumerates every finite string. Thus Σ* is countably infinite, including when Σ has only one symbol. Step 2: Cantor’s theorem states that the power set of any set has strictly larger cardinality than that set. The power set of a countably infinite set is uncountable. Step 3: Therefore C holds. A language is a subset of Σ*, and there are uncountably many such languages despite only countably many strings.

Original paper, page 56 · Answer key

2 marks · MCQ
Report issue

Decidability & Computability

Question 35, GATE 2014: Which problem is undecidable for arbitrary context-free grammars? A whether a grammar is ambiguous; B whether it generates a given string; C whether its language is empty; D whether its language is finite.
Tap to enlarge
Your answer
Answer & solution

Official answer: A

Step 1: Membership is decidable by a general CFG parsing algorithm, so B is not the answer. Step 2: Emptiness is decidable by marking nonterminals that can derive terminal strings and checking the start symbol. Finiteness is decidable by analyzing useful recursive growth, so C and D are also decidable. Step 3: There is no algorithm deciding ambiguity for every CFG: whether some string has multiple parse trees is an undecidable property of arbitrary grammars. Thus A. This does not say that ambiguity cannot be demonstrated for a particular grammar by an explicit witness.

Original paper, page 60 · Answer key

2 marks · MCQ
Report issue

Pushdown Automata

Question 36, GATE 2014: Over Σ={0,1,c}, define L1={0ⁿ1ⁿ:n≥0}, L2={wcwʳ:w∈{0,1}*}, L3={wwʳ:w∈{0,1}*}, with wʳ the reversal of w. Which languages are deterministic context-free? A none; B only L1; C only L1,L2; D all three.
Tap to enlarge
Your answer
Answer & solution

Official answer: C

Step 1: For L1, a deterministic pushdown automaton pushes one marker per 0 and switches to popping when the first 1 appears. The input symbol change identifies the phase boundary; accept when the counts match. Step 2: For L2, push the first binary word, then the marker c deterministically signals the switch to matching and popping its reverse. Step 3: In L3 there is no midpoint marker. An arbitrary binary even palindrome requires a nondeterministic choice of when to switch, and this unmarked palindrome language is a standard CFL that is not deterministic context-free. Therefore C. The final claim is the known non-DCFL result, not a claim that every language with an unmarked midpoint is automatically nondeterministic.

Original paper, page 61 · Answer key

2 marks · MCQ
Not in GATE 2027 syllabusReport issue

Complexity & Reductions

Question 38, GATE 2014: 2CNFSAT asks whether a CNF propositional formula with at most two literals per clause is satisfiable; for example (x1∨x2)∧(x1∨¬x3)∧(x2∨x4). Classify it. A NP-complete; B polynomial-time solvable via directed graph reachability; C constant-time solvable because every instance is satisfiable; D NP-hard but not NP-complete.
Tap to enlarge
Your answer
Answer & solution

Official answer: B

Step 1: Translate every clause (a∨b) into implications ¬a→b and ¬b→a. Treat a unit clause as (a∨a). This gives a directed implication graph with one vertex per literal. Step 2: If x reaches ¬x and ¬x reaches x, they lie in one strongly connected component, so either truth assignment forces a contradiction. Conversely, if no variable shares an SCC with its negation, the SCC ordering yields a satisfying assignment. Step 3: SCCs and reachability are computable in polynomial time (linear time suffices for SCCs), establishing B. C is false, as clauses x and ¬x form an unsatisfiable instance.

Original paper, page 61 · Answer key

1 mark · MCQ
Report issue

Empty-language concatenation and star

Regular Expressions & Languages

Question 8, GATE 2013: Let L1=∅ and L2={a}. Evaluate L1 L2* ∪ L1*. A{ε}; B∅; C a*; D{ε, a}.
Tap to enlarge
Your answer
Answer & solution

Official answer: A

The concatenation of the empty language with any language is empty. Meanwhile ∅*={ε}. Therefore the displayed union is{ε}, A.

Language concatenation requires one word from each operand. Since L1 contains no word at all, L1 L2* contains none, irrespective of L2*. A Kleene star always includes the concatenation of zero words, namely ε. With an empty base language there are no positive-length concatenations, so L1* contains exactly ε. Taking the union of ∅ with{ε} yields{ε}; do not confuse ∅ with the singleton language containing the empty word.

Original paper, page 3 · Answer key

1 mark · MCQ
Report issue

Recognizable-language closure

Closure Properties & Language Hierarchy

Question 17, GATE 2013: Which statements are false?1 Every nondeterministic TM has an equivalent deterministic TM.2 Recognizable languages are closed under union and complement.3 Decidable languages are closed under intersection and complement.4 Recognizable languages are closed under union and intersection. A1, 4; B1, 3; C2 only; D3 only.
Tap to enlarge
Your answer
Answer & solution

Official answer: C

Nondeterministic Turing machines can be simulated deterministically by dovetailing. Recognizable languages are closed under union and intersection by dovetailing recognizers, but not generally under complement. Decidable languages are closed under intersection and complement. Therefore only statement 2 is false, C.

A deterministic simulator explores a nondeterministic computation tree fairly, preventing an infinite branch from starving an accepting finite branch; this establishes 1. To recognize a union, interleave two recognizers and accept if either accepts. For intersection, interleave and accept after both have accepted, establishing 4. A recognizer may run forever on a rejected input, so simply swapping accept/reject does not recognize its complement; statement 2 is false. A decider always halts, so complementing its result and combining two runs both work, establishing 3.

Original paper, page 4 · Answer key

2 marks · MCQ
Report issue

Regular and unequal-block languages

Context-Free Grammars & Languages

Question 32, GATE 2013: Let L1={0^p1^q0^r:p, q, r≥0} and L2={0^p1^q0^r:p, q, r≥0, p≠r}. Which is false? A L2 is context-free. B L1∩L2 is context-free. C complement(L2) is recursive. D complement(L1) is context-free but not regular.
Tap to enlarge
Your answer
Answer & solution

Official answer: D

L1=0*1*0* is regular. L2, whose outer zero-block counts differ, is context-free: split into more leading zeros or more trailing zeros and use a pushdown comparison. Since L2⊆L1, their intersection is L2 and context-free. L2 is decidable by finite examination of the block counts (including the possible zero middle block), so its complement is recursive. The complement of regular L1 is regular and consequently context-free. Thus option D, which says this last complement is context-free but not regular, has a false not-regular clause. It is regular and therefore context-free; D is the requested false statement.

For the decisive option D, L1 is represented directly by 0*1*0*, hence is regular. Complement a complete DFA by swapping accepting and nonaccepting states; this proves its complement is regular as well. Being regular implies context-free, but it contradicts the extra words “not regular.” For L2, a pushdown machine can compare the first and final zero blocks when a nonempty middle 1block separates them; the all-zero case can be treated separately. A finite input can also be tested by enumerating its finitely many possible block splits, giving decidability without needing a closed form.

Original paper, page 7 · Answer key

2 marks · MCQ
Report issue

DFA language and equivalent states

Finite Automata

Question 33, GATE 2013: A DFA starts in nonaccepting s; s--1→t and s--0→f. Nonaccepting t loops on 1 and goes to f on 0. Accepting f loops on 0, 1. Which claims are false?1 complement of its language is context-free.2 its language has regex(11*0+0)(0+1)*0*1*.3 this three-state DFA is minimal.4 it accepts every binary string of length≥2. A1, 3; B2, 4; C2, 3; D3, 4.
Tap to enlarge
Your answer
Answer & solution

Official answer: D

The accepting state is reached once a 0 occurs and then loops on both symbols. The language is all binary strings containing at least one 0. Its complement is 1*, hence context-free. The given regular expression describes that same language: its leading component reaches a first 0 and the remaining factors allow arbitrary continuation. The two nonaccepting states have identical future acceptance behavior, so the three-state DFA is not minimal. It does not accept 11. Thus statements 1 and 2 are true and statements 3 and 4 are false. The question asks for the false statements, so the pair 3 and 4 gives option D.

Before the first 0, the machine is in s or t; after the first 0 it stays in accepting f forever. Thus its language is 1*0(0+1)*. The regex’s first factor(11*0+0) is precisely 1*0, and its trailing 0*1* can always be empty, so the expression describes the same language. States s and t accept exactly the same suffixes (those containing a0), hence can be merged. Finally11 is a length 2counterexample to claim 4. Therefore claims 3and4, and only those, are false.

Original paper, page 7 · Answer key

2 marks · MCQ
Report issue

Decidable and undecidable language properties

Decidability & Computability

Question 41, GATE 2013: Which problems are undecidable?1 CFG emptiness L(G)=∅;2 CFG universality L(G)=Σ*;3 regularity of the language of a TM;4 equality of a DFA language with an NFA language. A3 only; B3, 4; C1, 2, 3; D2, 3.
Tap to enlarge
Your answer
Answer & solution

Official answer: D

Statement 1 is decidable: repeatedly mark CFG variables that can derive terminal strings; L(G) is nonempty exactly when the start variable becomes marked. Statement 2, universality of a general CFG (whether L(G)=Σ*), is undecidable. Statement 3 is undecidable by Rice’s theorem: regularity is a nontrivial property of the language recognized by a Turing machine, since some recognizable languages are regular and some are not. Statement 4 is decidable: determinize the NFA, form the product automaton for the symmetric difference with the DFA, and test whether any accepting product state is reachable. Thus only 2 and 3 are undecidable, option D.

Separate finite-state and general-machine questions. DFA/NFA equivalence remains decidable even if determinization is exponentially expensive: decidability requires termination, not efficiency. CFG emptiness is a finite fixed-point computation over its nonterminals. In contrast, general CFG universality is a standard undecidable property. TM language regularity is semantic and nontrivial, so Rice’s theorem applies; regular and nonregular recognizable languages both exist. These distinctions leave exactly 2and3.

Original paper, page 9 · Answer key

1 mark · MCQ
Not in GATE 2027 syllabusReport issue

NP-completeness assuming P differs from NP

Complexity & Reductions

Question 4, GATE 2012: Assuming P ≠ NP, which of the following is TRUE?
       (A) NP-complete = NP                                  (B) NP-complete ∩ P = ∅
       (C) NP-hard = NP                                      (D) P = NP-complete
Tap to enlarge
Your answer
Answer & solution

Official answer: B

If an NP-complete language belonged to P, every language in NP could be reduced to it in polynomial time and then decided in polynomial time. This would imply P=NP, contrary to the premise. Thus NP-complete∩P=∅, B. In particular, NP-complete cannot equal NP because P is a nonempty subset of NP.

Check: NP-completeness combines membership in NP with polynomial reductions from every NP language. The contradiction uses both properties: a polynomial algorithm for one complete problem would compose with those reductions to solve all NP problems.

Original paper, page 2 · Answer key

1 mark · MCQ
Report issue

Complement of an epsilon-NFA language

Finite Automata

Question 12, GATE 2012: Over Σ={a}, an epsilon-NFA has states s (initial, nonaccepting), t (accepting), and u (nonaccepting). Its only transitions are s --a--> t, t --ε--> u, u --ε--> s. What is the complement of its accepted language within Σ*?
(A) ∅ (B) {ε} (C) a* (D) {a,ε}.
Tap to enlarge
Your answer
Answer & solution

Official answer: B

The initial state is nonaccepting. A single a reaches the only accepting state, and two epsilon transitions return from that state through the third state to the initial state. Thus each traversal consumes one a and any positive number of a symbols is accepted; epsilon is not. The language is a⁺ and its complement within {a}*=Σ* is {ε}, B.

Check: The initial epsilon-closure is just {s}; no epsilon move leaves s. Therefore the empty input is rejected. After one a reaches t, epsilon moves can return to s, allowing any further a and accepting again at t.

Original paper, page 3 · Answer key

1 mark · MCQ
Report issue

Decidability and language complementation

Decidability & Computability

Question 24, GATE 2012: Which problems are decidable? (1) Does a given program ever produce an output? (2) Given a context-free language L, is its complement also context-free? (3) Given a regular language L, is its complement also regular? (4) Given a recursive language L, is its complement also recursive?
(A) 1,2,3,4 (B) 1,2 (C) 2,3,4 (D) 3,4. Complements, shown by overbars in the original, are essential.
Tap to enlarge
Your answer
Answer & solution

Official answer: D

The overbars in statements 2–4 are essential: each asks about the complement of L. Regular languages are closed under complementation (complete a DFA and exchange accepting/nonaccepting states), and recursive languages are closed under complementation (swap the outcomes of a halting decider), so 3 and 4 always answer yes. Whether an arbitrary program ever outputs is undecidable by simulating a machine and printing only if it halts. For a context-free input language, deciding whether its complement is context-free is an undecidable grammar-property problem; lack of closure alone would not suffice to prove undecidability. Thus the intended decidable entries are 3 and 4, D. For a reduction justifying statement 2, fix a CFL H over a separate alphabet Γ whose complement is the non-CFL {ak bk ck: k≥0}; H is context-free by expressing unequal counts and malformed strings as a union of CFLs. Given a CFG language L over Σ, construct the CFL K consisting of L#Γ*, Σ*#H, and all malformed strings outside Σ*#Γ*. Its complement is (Σ*−L)#(Γ*−H). If L=Σ*, this is empty and context-free. Otherwise, choosing w∉L and intersecting with regular w#Γ* leaves w#(Γ*−H), which is not context-free (remove the fixed prefix by left quotient). Therefore a test for context-freeness of complements would decide the undecidable CFG-universality problem.

Check: A closure fact gives a constant yes-answer for promises 3 and 4, hence a decider exists. For promise 2, nonclosure alone merely says some answers are no; the reduction is necessary to establish that no algorithm can decide all such instances.

Original paper, page 5 · Answer key

1 mark · MCQ
Report issue

Concatenations in a finite language star

Regular Expressions & Languages

Question 25, GATE 2012: Given the language L = {ab, aa, baa}, which of the following strings are in L*?

                    1)   abaabaaabaa
                    2)   aaaabaaaa
                    3)   baaaaabaaaab
                    4)   baaaaabaa
        (A) 1, 2 and 3                                   (B) 2, 3 and 4
        (C) 1, 2 and 4                                   (D) 1, 3 and 4







Q. 26 to Q. 55 carry two marks each.
Tap to enlarge
Your answer
Answer & solution

Official answer: C

The blocks ab, aa and baa have distinct forced beginnings: at a, the next character decides ab versus aa; at b, only baa is possible. String 1 factors as ab·aa·baa·ab·aa; string 2 as aa·aa·baa·aa; and string 4 as baa·aa·ab·aa. For string 3, baaaaabaaaab, the forced parse is baa·aa·ab·aa·aa followed by a lone b, which is not a block. Its reachable complete-block prefix lengths are 0, 3, 5, 7, 9, 11, but its full length is 12. Thus exactly strings 1, 2, 4 belong to L*, C.

Check: Because no listed block is a prefix of another listed block, greedy block recognition cannot discard an alternative valid segmentation. This prefix-code property makes the forced parse failure of string 3 decisive rather than just one unsuccessful guess.

Original paper, page 5 · Answer key

2 marks · MCQ
Report issue

Complete DFA avoiding three consecutive zeros

Finite Automata

Question 46, GATE 2012: Complete a DFA for binary strings in which every length-three substring has at most two zeros (so 000 is forbidden). All strings shorter than three are accepted. States ε (initial),0,1,00,01,10,11 are accepting; q is rejecting. Existing transitions: ε--0→0, ε--1→1, 0--0→00, 0--1→01, 1--0→10, 1--1→11, 01--0→10, 10--1→01, 11--1→11, q--0,1→q. Which list supplies the missing arcs? Each triple means (source,input,target).
(A) (00,1,00),(00,0,01),(01,1,11),(10,0,00),(11,0,10).
(B) (00,0,01),(00,1,q),(01,1,01),(10,0,11),(11,0,01).
(C) (00,1,01),(00,0,q),(01,1,01),(10,0,10),(11,0,01).
(D) (00,1,01),(00,0,q),(01,1,11),(10,0,00),(11,0,10).
Tap to enlarge
Your answer
Answer & solution

Official answer: D

The forbidden length-three substring is exactly 000. The two-symbol states retain the last two symbols until the rejecting sink q is reached. Missing transitions are δ(00, 0)=q, δ(00, 1)=01, δ(01, 1)=11, δ(10, 0)=00, and δ(11, 0)=10. These are precisely table D. Every nonsink state accepts, including the states for strings shorter than three symbols.

Check: Appending 0 to suffix 00 creates forbidden 000, requiring the sink. Appending 1 to 00 leaves suffix 01; appending 1 to 01 leaves 11; appending 0 to 10 leaves 00; appending 0 to 11 leaves 10. This derives every missing arc rather than matching only one table entry.

Original paper, page 11 · Answer key

1 mark · MCQ
Report issue

Determinism and language expressive power

Other / Mixed Topics

Question 8, GATE 2011: Which pair of computational models has DIFFERENT expressive power?

(A) DFA and NFA
(B) Deterministic PDA and nondeterministic PDA
(C) Deterministic single-tape Turing machine and nondeterministic single-tape Turing machine
(D) Single-tape and multitape Turing machines
Tap to enlarge
Your answer
Answer & solution

Official answer: B

DFA and NFA recognize exactly the regular languages. Deterministic/nondeterministic and single/multitape Turing machines recognize the same class, though their efficiencies can differ. DPDAs recognize only deterministic CFLs, a proper subclass of the CFLs recognized by NPDAs. Hence B.

Expressive power asks which languages can be recognized, not how many states are needed or how fast a simulation runs. Subset construction turns an NFA into a DFA, possibly increasing its size. Turing machines can simulate nondeterministic branches by systematic exploration and can simulate extra tapes. A single stack plus deterministic choices is more restrictive: some context-free languages require the nondeterministic choice of how to parse or where to change phases.

Original paper, page 3 · Answer key

1 mark · MCQ
Report issue

Regular-language complement guarantee

Closure Properties & Language Hierarchy

Question 24, GATE 2011: P is regular and Q is context-free with Q a subset of P. For example, P=p*q* and Q={p^n q^n : n is natural}. Which language is ALWAYS regular, over alphabet Σ?

(A) P intersect Q
(B) P minus Q
(C) Σ* minus P
(D) Σ* minus Q
Tap to enlarge
Your answer
Answer & solution

Official answer: C

Regular languages are closed under complement, so Σ*−P is always regular. P∩Q=Q may be nonregular. If P−Q were always regular, Q=P−(P−Q) would always be regular, a contradiction; likewise regularity of Σ*−Q would imply regularity of Q. Therefore only C is guaranteed.

A counterexample is permitted because the question asks what is guaranteed for all P,Q. Choose P=0*1* and Q={0n1n}. Then P∩Q=Q is nonregular. If P−Q were regular, subtracting it from regular P would recover nonregular Q, contradicting closure of regular languages under difference. If the complement of Q were regular, complementing again would make Q regular. In contrast, a complete DFA for P can always have its accepting and rejecting states swapped to recognize its complement.

Original paper, page 6 · Answer key

2 marks · MCQ
Report issue

Equal three-block language is not context-free

Context-Free Grammars & Languages

Question 26, GATE 2011: Let L1={0^p1^q : p,q in N}, L2={0^p1^q : p=q in N}, and L3={0^p1^q0^r : p=q=r in N}. Which statement is NOT TRUE?

(A) A PDA can recognize L1 and L2
(B) L1 is regular
(C) All three languages are context-free
(D) Turing machines can recognize all three languages
Tap to enlarge
Your answer
Answer & solution

Official answer: C

L1=0*1* is regular and hence recognizable by a PDA; L2 matches two block lengths and is context-free. L3={0n1n0n} is not context-free: for pumping length p, choose 0p1p0p. A pumping window of length≤p cannot reach both outer zero blocks. Pumping a nonempty part therefore changes at most two blocks while leaving another unchanged, or destroys the block order, so equality of all three counts fails. All three are decidable by a Turing machine. Thus the claim that all three are context-free is false, C.

A PDA for L2 pushes one marker per initial 0 and pops one per following 1, rejecting if lengths differ or block order is wrong. L1 does not even need the stack. L3 requires coordinating three unbounded block lengths, and the pumping argument establishes the failure of context-freeness rather than merely asserting that a particular PDA design fails. A Turing machine can repeatedly mark one symbol in each block, so the failure is specific to context-free recognition, not computability.

Original paper, page 7 · Answer key

2 marks · MCQ
Report issue

Positive multiples of a fixed unary length

Finite Automata

Question 42, GATE 2011: Over alphabet {a}, let L={a^(nk): k>0}, where n is a fixed positive integer. What is the minimum number of states in a DFA recognizing L?

(A) k+1
(B) n+1
(C) 2^(n+1)
(D) 2^(k+1)
Tap to enlarge
Your answer
Answer & solution

Official answer: B

The language is {ank: k>0}, where n is a fixed positive integer; epsilon is excluded. Use a separate nonaccepting start state, then an n-state cycle that records the positive input length modulo n, accepting the residue-zero state. This uses n+1 states. For minimality, the n positive residue classes are pairwise distinguishable by an extension that makes exactly one length divisible by n. The empty prefix is distinguished from a positive multiple of n by the empty suffix, and from each other positive residue by a suffix that completes that residue to a multiple of n. Thus all n+1 classes are necessary, option B.

An explicit construction uses start z and cycle states r0,...,r(n-1). The first a moves z to r(1 mod n); each subsequent a advances the residue by one modulo n; only r0 is accepting. z must reject epsilon whereas r0 accepts it, so the usual n-state modulo counter cannot merge these two states. For n=1 the result is two states, recognizing a+ rather than a*, which also checks the boundary case.

Original paper, page 11 · Answer key

2 marks · MCQ
Report issue

Minimizing a five-state DFA

Finite Automata

Question 45, GATE 2011: DFA D has alphabet {a,b}, start p, accepting states s,t, and transitions p:a→s,b→q; q:a→t,b→r; r:a,b→r; s:a,b→s; t:a,b→t. Which supplied machine is an equivalent minimal DFA? Unlisted states in the alternatives are nonaccepting.

(A) Start p; final s; p:a→s,b→q; q:a→s,b→r; r:a,b→r; s:a,b→s
(B) Start p; finals q,r; p:a,b→q; q:a→r,b→s; r:a,b→r; s:a,b→s
(C) Start p; final q; p:a,b→q; q:a,b→q and also q:b→r; r:a,b→r
(D) Start p; final s; p:a→s,b→q; q:a→s,b→q; s:a,b→s
Tap to enlarge
Your answer
Answer & solution

Official answer: A

The accepting states s and t both loop on a and b, so their right languages are identical and they merge. The other states p, q and r remain distinct: p versus q is distinguished by suffix ba, since p accepts ba while q reaches the dead state; q versus r is distinguished by a; p versus r is also distinguished by a. Any accepting state differs from these nonaccepting states on epsilon. All four resulting classes are reachable. The minimal DFA has classes {p}, {q}, {r}, {s, t}, with p --b--> q --b--> r, r a/b-loops, and a-transitions from p and q to the accepting sink. This is option A.

All five original states are reachable: epsilon reaches p, b reaches q, bb reaches r, a reaches s, and ba reaches t. Initially separate accepting {s,t} from rejecting {p,q,r}; r differs because its a-transition stays rejecting, and then p differs from q because their b-transitions lead to different classes. Alternative B wrongly accepts b, C has two b-transitions from q and is not deterministic, and D accepts bba although the original reaches r on bb and must reject every continuation.

Original paper, page 12 · Answer key

1 mark · MCQ
Report issue

Differences of recursive and enumerable languages

Closure Properties & Language Hierarchy

Question 17, GATE 2010: L₁ is recursive. L₂ and L₃ are recursively enumerable but not recursive. Which statement is not necessarily true?
Options: (A) L₂−L₁ is recursively enumerable; (B) L₁−L₃ is recursively enumerable; (C) L₂∩L₃ is recursively enumerable; (D) L₂∪L₃ is recursively enumerable.
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

L₂−L₁=L₂∩complement(L₁) is recursively enumerable because L₁ is decidable and its complement is decidable. Recursively enumerable languages are also closed under union and intersection, proving C and D. But take L₁=Σ* and L₃ an undecidable recursively enumerable language: L₁−L₃ is its complement and cannot be recursively enumerable, or L₃ would be decidable by dovetailing both recognizers. Therefore B is not necessarily true.

To recognize an intersection of two recursively enumerable languages, simulate both recognizers in parallel and accept only after both accept; for a union accept after either does. For L₂−L₁, first decide nonmembership in L₁, then run the L₂ recognizer. This construction fails for L₁−L₃ because nonmembership in undecidable L₃ cannot generally be recognized.

Original paper, page 4

2 marks · MCQ
Report issue

Regular expression for even parity

Regular Expressions & Languages

Question 39, GATE 2010: Let L be all binary strings with an even number of 1s, including zero 1s. Which regular expression represents L? Concatenation is implicit and * denotes Kleene star.
Options: (A) (0*10*1)*; (B) 0*(10*10*)*; (C) 0*(10*1)*0*; (D) 0*1(10*1)*10*.
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

A binary string with an even number of 1s can be decomposed into initial zeros followed by zero or more pairs of 1s, with any number of zeros after each 1. This is exactly 0*(10*10*)*, option B. Each repeated block contributes two 1s, while any string with 2k ones can be split into k such blocks. The outer star includes the zero-ones case, including epsilon.

Why the alternatives fail: A cannot generate a nonempty all-zero string; C cannot generate 11011, whose zero separates two adjacent pairs of ones; D always has at least its two explicit outer ones and therefore misses epsilon and all-zero strings. B allows arbitrary zeros before, between and after every pair, and its repetition count can be zero.

Original paper, page 9

2 marks · MCQ
Report issue

Context-free linear counting constraints

Context-Free Grammars & Languages

Question 40, GATE 2010: For nonnegative integers i,j, let L₁={0^i1^j:i≠j}, L₂={0^i1^j:i=j}, L₃={0^i1^j:i=2j+1}, L₄={0^i1^j:i≠2j}. Which statement is true?
Options: (A) Only L₂ is context-free; (B) Only L₂ and L₃ are context-free; (C) Only L₁ and L₂ are context-free; (D) All are context-free.
Tap to enlarge
Your answer
Answer & solution

Answer: D (no official key was published)

All four languages are context free, D. L₂ has grammar S→0S1|ε. L₃ has S→00S1|0. For L₁, split into i>j and i<j: matched pairs 0j1j can have a nonempty zero prefix or nonempty one suffix, respectively, and CFLs are closed under concatenation with regular languages and finite union. For L₄, let E={02j1j}, generated by S→00S1|ε. The part i>2j is 0⁺E. For i<2j, even i gives E1⁺, while odd i gives 0E1⁺. These are all CFLs by the same closure properties, proving the claim without incorrectly invoking closure of CFLs under complement.

For the strict-inequality cases, the closure argument is constructive. L₁=0⁺{0j1j} ∪ {0i1i}1⁺. For L₄, write E={02j1j}; the cases i>2j, i<2j with i even, and i<2j with i odd are respectively 0⁺E, E1⁺ and 0E1⁺. This separates the arithmetic conditions without relying on the generally false statement that context-free languages are closed under complement.

Original paper, page 10

2 marks · MCQ
Report issue

Minimum NFA for all substrings

Finite Automata

Question 41, GATE 2010: Let w be any binary string of length n, and L the set of all substrings of w. What is the minimum number of states in a nondeterministic finite automaton accepting L?
Options: (A) n−1; (B) n; (C) n+1; (D) 2^(n−1).
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

The answer is n+1. For a lower bound, take an accepting computation for w, which has n consuming transitions. If a state repeats at two different consumed-input positions, the nonempty intervening loop can be pumped, accepting a string longer than n. That contradicts the definition of L. Hence at least n+1 states occur. For an upper bound, use states q0,…,qn, all accepting, with q0 initial. For every j=1,…,n add q0 --w[j]--> qj, and for i=1,…,n−1 add qi --w[i+1]--> q(i+1). Every nonempty accepted string follows a contiguous segment of w, and every substring has such a run. Making q0 accepting includes the empty substring. This construction uses one initial state and no epsilon moves; C.

The lower bound applies even when w contains repeated symbols, because the finite language contains w itself but no string longer than n. Pumping a repeated state on that accepting computation would violate this maximum length. In the upper-bound construction, choosing q0→qj chooses the starting position of a substring; continuing along successive positions preserves contiguity, and accepting at any state permits any ending position.

Original paper, page 10

1 mark · MCQ
Report issue

Odd-palindrome grammar

Context-Free Grammars & Languages

Question 12, GATE 2009: For grammar S→aSa|bSb|a|b over {a, b}, identify the language: A all palindromes; B odd-length palindromes; C all strings beginning and ending with the same symbol; D even-length palindromes.
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

The base productions produce a single a or b. Every recursive production adds the same symbol at both ends, preserving the palindrome property and odd length. Conversely strip matching outer pairs from any odd palindrome until one central symbol remains, yielding a derivation. Thus exactly all odd-length palindromes, B.

Every derivation starts from a one-symbol base a or b and adds matching symbols around the outside. Length therefore remains odd and the string remains a palindrome. Conversely, removing the equal end symbols from any odd palindrome repeatedly reaches its one-symbol centre, giving a reverse derivation. Even palindromes are excluded because no ε base exists; a string such as aabba begins/ends alike but is not generated.

Original paper, page 3

1 mark · MCQ
Report issue

Regular expression with two distinguished zeros

Regular Expressions & Languages

Question 15, GATE 2009: Describe (0+1)*0(0+1)*0(0+1)*: A strings containing 00; B at most two zeros; C at least two zeros; D strings beginning and ending with either 0 or 1.
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

Each starred(0+1) factor permits any binary string, but the two explicit 0 symbols must occur in order. Hence the expression accepts exactly strings with at least two zeros, not necessarily adjacent, C.

Each explicit 0 in the expression must consume a separate symbol, so every generated string contains at least two zeros. The three starred factors can contain arbitrary binary strings, including more zeros, and may be empty. Conversely, choose any two zeros in a string and assign the prefix, intervening segment and suffix to the three starred factors. The zeros need not be adjacent, so 010 is accepted despite lacking substring 00. Hence C.

Original paper, page 3

1 mark · MCQ
Report issue

False claim about pushdown determinism

Pushdown Automata

Question 16, GATE 2009: Which is false? A each regular language has a unique minimal DFA (up to renaming); B each NFA has an equivalent PDA; C the complement of every CFL is recursive; D every NPDA has an equivalent DPDA.
Tap to enlarge
Your answer
Answer & solution

Answer: D (no official key was published)

Minimal DFAs are unique up to state renaming; an NFA can be simulated by a PDA that ignores its stack. Every CFL is decidable, so its complement is recursive. But deterministic PDAs recognize a proper subclass of the CFLs recognized by NPDAs. Thus the universal conversion in D is false.

A PDA can simulate an NFA without using its stack. Context-free membership is decidable, so complementing that decision gives a decider for the complement. Minimal DFAs are unique up to state renaming. Deterministic PDAs, however, recognize a proper subset of context-free languages; nondeterminism cannot always be eliminated. For instance, unmarked palindromes need a nondeterministic guess of the midpoint. Thus D is the false universal claim.

Original paper, page 3

2 marks · MCQ
Report issue

Intersection leaves an equal-block prefix

Context-Free Grammars & Languages

Question 40, GATE 2009: L1={a^m b^m c a^n b^n:m, n≥0}; L2={a^i b^j c^k:i, j, k≥0}; L=L1∩L2. Classify: A not recursive; B regular; C context-free but nonregular; D RE but not context-free.
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

L1 contains exactly one c between am bm and an bn. For membership in L2=a*b*c*, no a or b may follow that c, so n=0. Thus the intersection is{am bm c:m≥0}. A grammar for it is S→Tc, T→aTb|ε. The language is context-free and nonregular: removing its fixed final c by regular right quotient would otherwise make{am bm} regular. Therefore C.

L2 permits only a block of a’s, then b’s, then c’s. A word of L1 has one central c, so its trailing an bn must be empty to fit L2. Thus L={am bm c:m≥0}. The grammar S→Tc and T→aTb|ε proves context-freeness. For nonregularity, removing the final fixed c from a hypothetical finite automaton would recognize the classic nonregular language am bm. Hence C, not the much stronger undecidability alternatives.

Original paper, page 9

2 marks · MCQ
Report issue

DFA accepting a two-zero suffix

Finite Automata

Question 41, GATE 2009: A DFA starts q0, accepts only q2. On 0, q0→q1→q2→q2; on 1, all states go q0. What does it accept? A strings beginning 0 or 1; B ending 0; C ending 00; D containing 00.
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

The states record zero, one, or at least two consecutive zeros at the end. Every 1 returns to the start state; 0 advances to the accepting state after the second consecutive zero, where further zeros loop. Hence exactly strings ending 00 are accepted, C, rather than all strings that merely contain 00 somewhere.

The state records the length of the current suffix of consecutive zeros, capped at 2. Reading 1 resets that suffix to length 0. Reading a second consecutive 0 reaches q2; additional zeros stay accepting. A string such as 001 contains 00 but ends in 1 and is rejected, separating C from D. A single 0 reaches q1 and is rejected, separating C from B.

Original paper, page 9

1 mark · MCQ
Report issue

Unary prime-length language

Context-Free Grammars & Languages

Question 9, GATE 2008: Which statement holds for {a^p | p is prime}?

(A) Not accepted by a Turing machine
(B) Regular but not context-free
(C) Context-free but not regular
(D) Neither regular nor context-free, but accepted by a Turing machine
Tap to enlarge
Your answer
Answer & solution

Answer: D (no official key was published)

1. Primality of the input length is decidable, so a Turing machine accepts the language. It is not regular: if a pumping length is p, choose prime q>p; a pumpable nonempty segment has length d≤p, and pumping it q+1 times changes length to q+qd=q(1+d), composite.
2. Every unary context-free language is regular (its length set is ultimately periodic/semilinear), so this language is not context-free either. Therefore D.

Original paper, page 3

1 mark · MCQ
Report issue

Decidability questions about automata and grammar

Decidability & Computability

Question 10, GATE 2008: Which are decidable? I: whether the intersection of two regular languages is infinite. II: whether a given context-free language is regular. III: whether two pushdown automata accept the same language. IV: whether a given grammar is context-free.

(A) I and II
(B) I and IV
(C) II and III
(D) II and IV
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

1. For I, construct a product DFA for the intersection and test whether a reachable cycle can reach an accepting state; this decides infinitude. IV is a syntactic check of the grammar’s productions: every left side must be a single nonterminal.
2. Regularity of an arbitrary CFL and equivalence of arbitrary nondeterministic PDAs are undecidable. Thus I and IV, B.
3. IV asks whether the presented grammar is context-free in form, not whether an arbitrary grammar’s language happens to be a CFL.

Original paper, page 3

1 mark · MCQ
Report issue

Recognizable language and recognizable complement

Decidability & Computability

Question 13, GATE 2008: If both L and its complement are recursively enumerable, L is necessarily:

(A) Regular
(B) Context-free
(C) Context-sensitive
(D) Recursive
Tap to enlarge
Your answer
Answer & solution

Answer: D (no official key was published)

1. Run recognizers for L and its complement in dovetailing fashion, alternating simulation steps so neither can prevent the other from progressing.
2. Every input lies in exactly one of the two languages, so exactly one recognizer eventually accepts. Accept if it is the L recognizer and reject otherwise.
3. This constructed decider halts on every input, making L recursive, D. Nothing here guarantees regularity, context-freeness or a linear-space bound.

Original paper, page 3

2 marks · MCQ
Report issue

False claim about recursively enumerable subsets

Decidability & Computability

Question 48, GATE 2008: Which statement is false?

(A) Every NFA has an equivalent DFA
(B) Every nondeterministic TM has an equivalent deterministic TM
(C) Every regular language is context-free
(D) Every subset of a recursively enumerable set is recursive
Tap to enlarge
Your answer
Answer & solution

Answer: D (no official key was published)

1. D is false. The set Σ* is recursive and hence recursively enumerable, but it contains nonrecursive subsets, including an encoding of the halting language.
2. Even a recursively enumerable set itself need not be recursive. A holds by the subset construction for NFAs.
3. B holds because a deterministic Turing machine can dovetail the finitely branching computation tree of a nondeterministic machine, accepting exactly when an accepting branch is found. C holds because a finite automaton can be converted to a right-linear context-free grammar.

Original paper, page 8

2 marks · MCQ
Report issue

Product automaton transition-table discrepancy

Finite Automata

Question 49, GATE 2008: DFA Y has start 1, final 2, and transitions on (a,b): 1→(1,2), 2→(2,1). DFA Z has start 1, final 2: 1→(2,2), 2→(1,1). Which printed table is their intersection product Z×Y? In every offered table P is initial, R is the only final state, and each row below lists its (a,b) destinations.

(A) P:(S,R), Q:(R,S), R:(Q,P), S:(Q,P)
(B) P:(S,Q), Q:(R,S), R:(Q,P), S:(P,Q)
(C) P:(Q,S), Q:(R,S), R:(Q,P), S:(Q,P)
(D) P:(S,Q), Q:(S,R), R:(Q,P), S:(Q,P)
Tap to enlarge
Your answer
Answer & solution

Answer: None (no official key was published)

1. There is no correct option as printed. Let product states be P=(1,1), Q=(1,2), R=(2,2), S=(2,1), in (Z,Y) order. P is initial and R is the sole accepting state.
2. Applying both component transitions gives the rows (a,b): P=(S,R), Q=(R,S), R=(Q,P), S=(P,Q). Option A agrees in its first three rows but prints S=(Q,P), not (P,Q). Options B, C and D send the initial state on b to a nonfinal state, whereas b is accepted by both Y and Z and must be accepted by their intersection product.
3. Thus none represents the product, even after renaming. A would be correct if its final row were repaired. No official key is available to determine how the examination treated the printing defect.

Original paper, page 9

2 marks · MCQ
Report issue

Grammar transformations and normal-form trees

Context-Free Grammars & Languages

Question 50, GATE 2008: Which statements are true? I: every left-recursive grammar can be converted to a right-recursive grammar and vice versa. II: all ε-productions can be removed from any CFG by suitable transformations. III: a CFG with only X→w or X→wY, where w is a terminal string and Y a nonterminal, always generates a regular language. IV: derivation trees for a CFG in Chomsky normal form are always binary trees.

(A) I,II,III,IV
(B) II,III,IV only
(C) I,III,IV only
(D) I,II,IV only
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

1. Under the conventional grammar-transformation interpretation, I, III and IV are true, giving C. I refers to eliminating left recursion using right-recursive auxiliaries and the symmetric transformation for right recursion; it does not mean every context-free grammar becomes a right-linear regular grammar.
2. II is false as stated: if ε belongs to the language, removing every ε-production cannot preserve that language, since no nonempty sentential form can derive the empty string without one. III is a right-linear grammar, possibly with multi-terminal labels; expanding labels into paths yields a finite automaton, so its language is regular.
3. IV is true in the at-most-two-children sense of binary tree: CNF uses A→BC or A→a (and possibly the special start ε-rule), so no derivation-tree node has more than two children.

Original paper, page 9

2 marks · MCQ
Report issue

Matching language patterns to compiler requirements

Context-Free Grammars & Languages

Question 51, GATE 2008: Match E: checking identifiers are declared before use; F: agreement of numbers of formal and actual function parameters; G: arithmetic expressions with matched parentheses; H: palindromes. Models: P={a^n b^m c^n d^m | n,m≥1}; Q: X→XbX|XcX|dXf|g; R={wcw | w∈{a,b}*}; S: X→bXb|cXc|ε.

(A) E–P,F–R,G–Q,H–S
(B) E–R,F–P,G–S,H–Q
(C) E–R,F–P,G–Q,H–S
(D) E–P,F–R,G–S,H–Q
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

1. The matching is E–R, F–P, G–Q, H–S, option C. E requires the same identifier string in declaration and use, modeled by the copy language wcw.
2. F matches counts of formal and actual parameters; an bm cn dm models the two cross-referenced counts. G is modeled by X→XbX | XcX | dXf | g: b and c act as binary operators, d/f as matched opening/closing parentheses, and g as an operand.
3. H is modeled by X→bXb | cXc | ε, which generates even-length palindromes. These are structural analogies, not claims that the small grammars capture every feature of a programming language or all odd-length palindromes.

Original paper, page 9

2 marks · MCQ
Report issue

Matching four NFAs to regular expressions

Regular Expressions & Languages

Question 52, GATE 2008: Match four NFAs to regular expressions. Each NFA has lower state L (initial and accepting), upper-left A and upper-right B. Unlisted transitions are absent. P: L−0→A, A−0→L and B, B−1→A and B; B is also accepting. Q: L−0→A, A−0→L, A−1→B, B−1→A, B−0→B; only L accepts. R: L−0→A, A−1→L and B, B−1→A, B−0→B; only L accepts. S has R’s transitions with both L and B accepting. Expressions: 1: ε+0(01*1+00)*01*; 2: ε+0(10*1+00)*0; 3: ε+0(10*1+10)*1; 4: ε+0(10*1+10)*10*.

(A) P–2,Q–1,R–3,S–4
(B) P–1,Q–3,R–2,S–4
(C) P–1,Q–2,R–3,S–4
(D) P–3,Q–2,R–1,S–4
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

1. Name the lower start state L, upper-left state A and upper-right state B. Every automaton accepts ε at L; every nonempty accepted path begins with 0 from L to A. In P, cycles from A back to A are 00 via L or 01*1 via B, and a finishing path to either accepting state is represented by 01*.
2. Hence P matches expression 1: ε+0(01*1+00)*01*. In Q, the A-cycles are 00 or 10*1, with final 0 to L, giving expression 2. In R, the A-cycles are 10 or 10*1, with final 1 to L, giving expression 3.
3. In S, the same cycles apply but B is also accepting, so a final 10* covers both possible accepting destinations, giving expression 4. Thus P–1,Q–2,R–3,S–4, option C.

Original paper, page 10

2 marks · MCQ
Report issue

Regularity of four language families

Regular Expressions & Languages

Question 53, GATE 2008: Which sets are regular? I: {a^n b^(2m) | n,m≥0}. II: {a^n b^m | n=2m}. III: {a^n b^m | n≠m}. IV: {xcy | x,y∈{a,b}*}.

(A) I and IV only
(B) I and III only
(C) I only
(D) IV only
Tap to enlarge
Your answer
Answer & solution

Answer: A (no official key was published)

1. I and IV are regular, giving A. I has expression a*(bb)*: n and m are independent and only the parity of the b-count is restricted.
2. IV has expression (a|b)*c(a|b)* because x and y need not be equal. II is {a2mbm}; applying the pumping lemma to a2pbp pumps only a symbols and destroys the required 2:1 relation.
3. III is not regular: if it were, subtracting it from the regular language a*b* would make {an bn} regular by closure under difference, a contradiction.

Original paper, page 10

1 mark · MCQ
Report issue

Undecidable grammar ambiguity

Decidability & Computability

Question 6, GATE 2007: Which decision problem is undecidable?
Options:
(A) Membership for context-free grammars
(B) Ambiguity for context-free grammars
(C) Finiteness for finite-state automata
(D) Equivalence for finite-state automata
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

1. Approach. Distinguish a property of a particular input string from a property of all derivations of a grammar. Parsing decides membership; finite automata allow finite graph algorithms.

2. Derivation and interpretation. CFG membership is decidable by parsing. Finite-automaton finiteness is decided by useful-cycle detection, and equivalence by symmetric-difference reachability. Ambiguity of an arbitrary CFG is undecidable, so B.

Original paper, page 2

1 mark · MCQ
Report issue

Finite subsets are regular

Regular Expressions & Languages

Question 7, GATE 2007: Which statement about regular languages is true?
Options:
(A) Every subset of a regular set is regular
(B) Every finite subset of a nonregular set is regular
(C) The union of two nonregular sets is nonregular
(D) An infinite union of finite sets is regular
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

1. Approach. A finite language is described by a finite union of its individual words. Closure under finite union does not imply closure under an arbitrary infinite union.

2. Derivation and interpretation. Every finite language is regular, regardless of the parent set, so B. A fails because nonregular languages are subsets ofΣ*. C fails by taking a nonregular language and its nonregular complement, whose union is Σ*. D fails because any nonregular language is an infinite union of singleton finite languages.

Original paper, page 3

2 marks · MCQ
Report issue

Minimal DFA for two modular counts

Finite Automata

Question 29, GATE 2007: What is the number of states in a minimum DFA for L={w∈{0,1}*: the number of 0s is divisible by 3 and the number of 1s is divisible by 5}?
Options:
(A) 15
(B) 11
(C) 10
(D) 9
Tap to enlarge
Your answer
Answer & solution

Answer: A (no official key was published)

Step through it (2 parts)

1. Approach. Use a product state (i,j) recording the two remainders. On 0 update i modulo 3; on 1 update j modulo 5. Minimality requires distinguishability, not merely constructing a 15-state DFA.

2. Derivation and interpretation. Track the number of zeros modulo 3 and ones modulo 5, giving 3×5=15 states; accept residue (0,0). Every residue pair is reachable. Any two different pairs are distinguished by appending zeros and ones that bring one pair to (0,0), leaving the other nonzero in at least one coordinate. Thus 15 states are necessary and sufficient, A.

Original paper, page 6

2 marks · MCQ
Report issue

Equal blocks separated by a marker

Pushdown Automata

Question 30, GATE 2007: Classify L={0^i 2 1^i:i≥0} over alphabet {0,1,2}.
Options:
(A) Not recursive
(B) Recursive and deterministic context-free
(C) Regular
(D) Context-free but not deterministic context-free
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

1. Approach. The marker 2 identifies exactly when to switch from pushing zeros to matching ones. Unlike an unmarked palindrome, there is no need to guess the midpoint.

2. Derivation and interpretation. A deterministic PDA pushes for each initial 0, switches phase at the unique marker 2, and pops once per 1, accepting exactly when the counts match and input ends. Membership is also decidable. The language is not regular because matching unbounded block lengths requires memory. Hence it is recursive and deterministic context-free, B, including the string 2 for i=0.

Original paper, page 7

2 marks · MCQ
Report issue

Regular language among palindrome-based forms

Regular Expressions & Languages

Question 31, GATE 2007: Which language is regular? In all options w and x are nonempty binary strings, w^R is the reversal of w, and Σ={0,1}.
Options:
(A) {ww^R:w∈Σ+}
(B) {ww^R x:w,x∈Σ+}
(C) {wxw^R:w,x∈Σ+}
(D) {xww^R:w,x∈Σ+}
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

1. Approach. The existential decomposition matters: for option C, w can always be chosen to have length one. This removes the apparent need to remember an arbitrarily long prefix. A direct regular expression is 0(0|1)+0 | 1(0|1)+1.

2. Derivation and interpretation. In C, every string wxwR has the same first and last symbol and length at least 3. Conversely any binary string of length≥3 with equal endpoints has such a representation by choosing w to be its first single symbol and x its nonempty middle. Thus C equals 0(0+1)+0 ∪1(0+1)+1 and is regular. A is the nonempty even-palindrome language and nonregular. For B, intersect with the regular language 0(11)*1 00 (11)*1 01. The result is{0 1k 00 1k 01:k positive odd}: the only possible even-palindrome prefix must match the two odd-length 1 blocks. This equality language is nonregular by pumping the first block. Hence B is nonregular. D is the reversal of B and is likewise nonregular.

Original paper, page 7

2 marks · MCQ
Report issue

Language of finite-state automaton

Regular Expressions & Languages

Question 74, GATE 2007: A DFA over {a,b} has start state q0, accepting states q1,q2 and nonaccepting states q0,q3. Its complete transition table is: q0: a→q1,b→q0; q1: a→q2,b→q1; q2: a→q1,b→q2; q3: a→q1,b→q2.
Which regular expression denotes its language? Here + denotes union.
Options:
(A) b*ab*ab*ab*
(B) (a+b)*
(C) b*a(a+b)*
(D) b*ab*ab*
Question 74, GATE 2007: A DFA over {a,b} has start state q0, accepting states q1,q2 and nonaccepting states q0,q3. Its complete transition table is: q0: a→q1,b→q0; q1: a→q2,b→q1; q2: a→q1,b→q2; q3: a→q1,b→q2.
Which regular expression denotes its language? Here + denotes union.
Options:
(A) b*ab*ab*ab*
(B) (a+b)*
(C) b*a(a+b)*
(D) b*ab*ab*
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

1. Approach. Before the first a the machine stays in nonaccepting q0. Once an a occurs, every later transition stays within the accepting pair q1,q2. q3 cannot affect strings read from the start state.

2. Derivation and interpretation. The start state q0 loops on b and is not accepting. Its first a enters accepting q1. Thereafter a alternates between q1 and q2 and b loops in either accepting state, so every suffix over {a,b} is accepted. q3 is unreachable from q0. Thus exactly the strings containing at least one a are accepted: b*a(a+b)*, option C.

Original paper, page 19

2 marks · MCQ
Report issue

Minimum equivalent DFA size

Finite Automata

Question 75, GATE 2007: A DFA over {a,b} has start state q0, accepting states q1,q2 and nonaccepting states q0,q3. Its complete transition table is: q0: a→q1,b→q0; q1: a→q2,b→q1; q2: a→q1,b→q2; q3: a→q1,b→q2.
How many states does a minimum equivalent DFA have?
Options:
(A) 1
(B) 2
(C) 3
(D) 4
Question 75, GATE 2007: A DFA over {a,b} has start state q0, accepting states q1,q2 and nonaccepting states q0,q3. Its complete transition table is: q0: a→q1,b→q0; q1: a→q2,b→q1; q2: a→q1,b→q2; q3: a→q1,b→q2.
How many states does a minimum equivalent DFA have?
Options:
(A) 1
(B) 2
(C) 3
(D) 4
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

1. Approach. First remove unreachable states, then partition the remaining states by whether any suffix distinguishes their acceptance. q1 and q2 have identical future acceptance behavior even though their names differ.

2. Derivation and interpretation. Delete unreachable q3. States q1 and q2 are equivalent: both accept, b leaves each in the accepting class, and a switches within that class. Merge them. The remaining nonaccepting q0 and accepting merged state are distinguishable by the empty suffix, so two states are necessary and sufficient. Answer B.

Original paper, page 19

2 marks · MCQ
Report issue

String generated by equal-count grammar

Context-Free Grammars & Languages

Question 78, GATE 2007: A context-free grammar has nonterminals {S,A,B}, terminals {a,b}, start S, and productions S→aB | bA; B→b | bS | aBB; A→a | aS | bAA. Which string is generated?
Options:
(A) aaaabb
(B) aabbbb
(C) aabbab
(D) abbbba
Question 78, GATE 2007: A context-free grammar has nonterminals {S,A,B}, terminals {a,b}, start S, and productions S→aB | bA; B→b | bS | aBB; A→a | aS | bAA. Which string is generated?
Options:
(A) aaaabb
(B) aabbbb
(C) aabbab
(D) abbbba
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

Step through it (4 derivations)

1. Approach. Track the invariant #a−#b for strings derived from each nonterminal: it is 0 from S, +1 from A and −1 from B. Reject options violating the invariant, then construct a derivation for the survivor.

2. Derivation and interpretation. Every S-derived string has equal numbers of a and b; A-derived strings have one more a, and B-derived strings one more b. These invariants follow directly from all eight productions. Only aabbab among the four options has equal counts. It is generated by S => aB => aaBB => aabB => aabbS => aabbaB => aabbab. Thus C.

Original paper, page 20

2 marks · MCQ
Report issue

Number of parse trees for aabbab

Context-Free Grammars & Languages

Question 79, GATE 2007: A context-free grammar has nonterminals {S,A,B}, terminals {a,b}, start S, and productions S→aB | bA; B→b | bS | aBB; A→a | aS | bAA. For aabbab, the answer string to linked Q78, how many distinct derivation trees exist?
Options:
(A) 1
(B) 2
(C) 3
(D) 4
Question 79, GATE 2007: A context-free grammar has nonterminals {S,A,B}, terminals {a,b}, start S, and productions S→aB | bA; B→b | bS | aBB; A→a | aS | bAA. For aabbab, the answer string to linked Q78, how many distinct derivation trees exist?
Options:
(A) 1
(B) 2
(C) 3
(D) 4
Question 79, GATE 2007: A context-free grammar has nonterminals {S,A,B}, terminals {a,b}, start S, and productions S→aB | bA; B→b | bS | aBB; A→a | aS | bAA. For aabbab, the answer string to linked Q78, how many distinct derivation trees exist?
Options:
(A) 1
(B) 2
(C) 3
(D) 4
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

Step through it (2 derivations)

1. Approach. The first two a symbols force S→aB→aaBB. Enumerate how the remaining bbab splits between the two B subtrees. Count trees, not different orders of expanding the same tree.

2. Derivation and interpretation. The first two terminals aa force S -> aB and B -> aBB. The remaining bbab must split between the two B children. Each child has one more b than a. Exactly two splits work: b | bab and bba | b. For the first, the right child uniquely derives bab via B -> bS -> baB -> bab. For the second, the left child uniquely derives bba via B -> bS -> bbA -> bba. The single b children use B -> b. Thus there are 2 parse trees, option B; different orders of expanding a fixed tree do not count as additional trees.

Original paper, page 20

1 mark · MCQ
Not in GATE 2027 syllabusReport issue

Reductions to and from an NP-complete problem

Complexity & Reductions

Question 16, GATE 2006: S is NP-complete. Q and R are problems not initially known to belong to NP. Q is polynomial-time reducible to S and S is polynomial-time reducible to R. Which statement necessarily follows?
Options:
(A) R is NP-complete
(B) R is NP-hard
(C) Q is NP-complete
(D) Q is NP-hard
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

1. Every NP language reduces to S, and S reduces to R, so transitivity makes R NP-hard. R need not belong to NP and therefore need not be NP-complete.

2. Q reducing to S does place Q in NP, but does not make Q NP-hard. Thus B.

3. Teaching check: Reduction direction matters: if A reduces to B, a solver for B can solve A. Thus hardness flows from S toward R. Membership in NP does not automatically flow in that direction, which is why NP-hard is justified but NP-complete is not.

Original paper, page 2

1 mark · MCQ
Report issue

Context-free block-count languages

Context-Free Grammars & Languages

Question 19, GATE 2006: For n,m≥0 define L₁={0^(n+m)1^n0^m}, L₂={0^(n+m)1^(n+m)0^m}, and L₃={0^(n+m)1^(n+m)0^(n+m)}. Which languages are not context-free?
Options:
(A) L₁ only
(B) L₃ only
(C) L₁ and L₂
(D) L₂ and L₃
Tap to enlarge
Your answer
Answer & solution

Answer: D (no official key was published)

1. L1={0n+m1n0m} is context-free: S→0S0|T and T→0T1|ε generates it. Write L2={0k1k0m:0≤m≤k}.

2. It is not context-free: apply the CFL pumping lemma to 0p1p0p. A pump confined to one block breaks either equality of the first two block lengths or the last≤first inequality (choose pumping direction accordingly).

3. A pump crossing one boundary cannot touch all three blocks; preserving the first two lengths while pumping down makes the third too long, while other changes break equality or block order. L3 is{0k1k0k:k≥0}, also non-context-free by the usual three-block pumping argument.

4. Hence L2 and L3, D.

5. Teaching check: For L₂ the two equal leading block lengths and the upper bound on the final block are linked. A pumping window of length p cannot span all three p-length blocks in 0p1p0p. Even if it changes the first two blocks equally, pumping down leaves the untouched third block too long.

Original paper, page 3

2 marks · MCQ
Report issue

Bounded final count imbalance

Regular Expressions & Languages

Question 29, GATE 2006: For binary string s, let n₀(s),n₁(s) count zeros and ones. Which language is not regular?
Options:
(A) {s:n₀(s) is a three-digit prime}
(B) {s:for every prefix t of s, |n₀(t)−n₁(t)|≤2}
(C) {s:|n₀(s)−n₁(s)|≤4}
(D) {s:n₀(s) mod 7=0 and n₁(s) mod 5=0}
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

1. A is regular because the permitted zero counts are finitely many three-digit primes; count zeros up to the maximum with an overflow state. B tracks prefix imbalance in{−2,−1,0,1,2}, rejecting immediately outside that range.

2. D tracks zero count modulo 7 and one count modulo 5. C only bounds the final imbalance and allows arbitrarily large intermediate imbalance.

3. Intersect C with 0*1* and pump 0p1p: pumping a nonempty block of initial zeros sufficiently many times makes the final difference exceed 4. Hence C is not regular.

4. Teaching check: A bound on every prefix permits a finite-state machine to reject immediately when its imbalance leaves a fixed range. A bound only on the final string allows arbitrarily large positive imbalance followed by enough ones to cancel it. Tracking this unbounded debt cannot be done with finitely many states.

Original paper, page 4

2 marks · MCQ
Report issue

Binary numerical residue constraints

Regular Expressions & Languages

Question 30, GATE 2006: For a binary string s let d(s) be its numerical value, for example d(101)=5. Classify L={s:d(s) mod 5=2 and d(s) mod 7≠4}.
Options:
(A) Recursively enumerable but not recursive
(B) Recursive but not context-free
(C) Context-free but not regular
(D) Regular
Tap to enlarge
Your answer
Answer & solution

Answer: D (no official key was published)

1. A finite automaton stores the current binary value modulo 35. Reading bit b replaces residue r by(2r+b) mod35.

2. Accept precisely residues r with r mod5=2 and r mod7≠4. This recognizes the language, so it is regular, D; leading zeros do not affect the construction.

3. Teaching check: The joint modulus 35 suffices because both congruence tests depend only on the value modulo 35. Starting at residue zero, scan bits left to right and update r←(2r+b) mod 35. A 35-state DFA with appropriate accepting residues is a constructive regularity proof.

Original paper, page 4

2 marks · MCQ
Not in GATE 2027 syllabusReport issue

Hamiltonian cycles on a multiple of three vertices

Complexity & Reductions

Question 31, GATE 2006: Restrict undirected graphs G=(V,E) to |V| divisible by 3. SHAM₃ is the problem of finding a Hamiltonian cycle; DHAM₃ asks whether one exists. Which statement is true?
Options:
(A) Both DHAM₃ and SHAM₃ are NP-hard
(B) SHAM₃ is NP-hard but DHAM₃ is not
(C) DHAM₃ is NP-hard but SHAM₃ is not
(D) Neither is NP-hard
Tap to enlarge
Your answer
Answer & solution

Answer: A (no official key was published)

1. The vertex-count restriction does not remove NP-hardness. Reduce an undirected Hamiltonian-cycle instance by replacing each original vertex with a three-vertex path.

2. For each original edge uv, connect each endpoint of u’s path to each endpoint of v’s path. The middle vertices have degree 2, so any Hamiltonian cycle must traverse each replacement path; contracting the paths recovers a Hamiltonian cycle of the original graph.

3. Conversely any original cycle expands through all paths. The new graph has 3|V| vertices.

4. Therefore decision DHAM3 is NP-hard; a polynomial search algorithm that returns a cycle or reports none would decide it, so SHAM3 is NP-hard as well, A.

5. Teaching check: The middle vertex in each three-vertex replacement path has degree two, forcing both its incident edges into any Hamiltonian cycle. Hence the whole path acts as one original vertex when contracted. This gives an explicit polynomial reduction rather than assuming a divisibility restriction preserves hardness.

Original paper, page 4

2 marks · MCQ
Report issue

Ambiguous grammar for a regular language

Context-Free Grammars & Languages

Question 32, GATE 2006: Grammar G has productions S→SS | ab | ba | ε. Consider I: G is ambiguous; II: G generates every string with equal counts of a and b; III: the language of G can be accepted by a deterministic PDA. Which statements are true?
Options:
(A) I only
(B) I and III only
(C) II and III only
(D) I, II and III
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

1. The grammar generates exactly(ab+ba)*: SS concatenates its two-letter blocks and ε contributes nothing. It is ambiguous, for example ab has both S→ab and S→SS→abS→ab, with different parse trees.

2. It does not generate aabb, although that string has equal a/b counts. The generated language is regular and therefore accepted by a deterministic PDA (even a DFA).

3. Statements1 and 3 hold, B; the PDA accepts the language, not the grammar object.

4. Teaching check: Equal counts are necessary for this grammar but not sufficient: concatenating ab and ba blocks cannot produce aabb. The ε production together with S→SS also allows redundant decompositions, so even a very short generated word has multiple parse trees.

Original paper, page 4

2 marks · MCQ
Report issue

Closure with a nonrecursive enumerable language

Closure Properties & Language Hierarchy

Question 33, GATE 2006: L₁ is regular, L₂ is deterministic context-free, and L₃ is recursively enumerable but not recursive. Which universal closure assertion is false?
Options:
(A) L₁∩L₂ is deterministic context-free
(B) L₃∩L₁ is recursive
(C) L₁∪L₂ is context-free
(D) L₁∩L₂∩L₃ is recursively enumerable
Tap to enlarge
Your answer
Answer & solution

Answer: B as a non-guaranteed assertion (no official key was published)

1. Regular∩deterministic-CFL is deterministic context-free; regular∪CFL is context-free. Intersecting the two decidable languages with a recursively enumerable language remains recursively enumerable.

2. But L3∩L1 need not be recursive: take L1=Σ*, giving L3 itself. Thus B is the false universal closure assertion.

3. It can nevertheless be recursive for some choices, such as L1=∅; it is not false for every instance.

4. Teaching check: To refute a universal closure claim, choose an extreme regular language. Taking L₁=Σ* preserves all of L₃ under intersection, so undecidability remains. Taking L₁=∅ illustrates why the false assertion is “always recursive,” not “never recursive.”

Original paper, page 5

2 marks · MCQ
Report issue

Unary lengths generated by three and five

Finite Automata

Question 34, GATE 2006: Over the unary alphabet {1}, what is the smallest number of states in a DFA for (111+11111)*, where + denotes union?
Options:
(A) 3
(B) 5
(C) 8
(D) 9
Tap to enlarge
Your answer
Answer & solution

Answer: D over the unary alphabet (no official key was published)

Step through it (2 parts)

1. The possible lengths are 3a+5b, a,b≥0:0,3,5,6 and all integers≥8. The missing nonnegative lengths are 1,2,4,7.

2. A unary DFA counts lengths 0 through 7, then enters an accepting sink at 8, using 9 states. For any 0≤i<j≤8, append 7−i symbols: the first length becomes 7 and is rejected, while the second exceeds 7 and is accepted.

3. Thus all nine states are distinguishable and D is minimal. This treats the stated expression as a language over{1}; a larger alphabet would require a rejecting sink for other symbols.

4. Teaching check: Lengths 0,3,5,6 and all lengths at least eight are accepted; 1,2,4,7 are rejected. Build states recording exact lengths below eight, followed by one accepting sink. Distinguishability proves this nine-state construction minimal, rather than merely establishing an upper bound.

Original paper, page 5

2 marks · MCQ
Report issue

Grammar for unequal a and b counts

Context-Free Grammars & Languages

Question 84, GATE 2006: Which grammar generates precisely {a^i b^j:i,j≥0 and i≠j}? ε denotes the empty string.
Options:
(A) S→AC|CB; C→aCb|a|b; A→aA|ε; B→Bb|ε
(B) S→aS|Sb|a|b
(C) S→AC|CB; C→aCb|ε; A→aA|ε; B→Bb|ε
(D) S→AC|CB; C→aCb|ε; A→aA|a; B→Bb|b
Tap to enlarge
Your answer
Answer & solution

Answer: D (no official key was published)

1. In D, C→aCb|ε generates balanced ak bk. A→aA|a adds a positive number of a symbols, so S→AC generates all i>j.

2. B→Bb|b adds a positive number of b symbols, so S→CB generates all j>i. Together these are precisely ai bj with i≠j.

3. A permits cancellation of C’s ±1 imbalance by the other nonterminal: for example S⇒AC⇒aC⇒ab. B also generates ab.

4. C allows A/B→ε and therefore generates equal counts, including ε. Only D excludes every equal-count string while covering every unequal-count string.

5. Teaching check: C supplies equal counts, while A supplies at least one extra a or B at least one extra b. Because A and B cannot derive ε in D, every generated string has unequal counts. Conversely any unequal pair of nonnegative counts decomposes into a common balanced part and one positive excess.

Original paper, page 13

2 marks · MCQ
Report issue

Derivation length for unequal counts

Context-Free Grammars & Languages

Question 85, GATE 2006: Using grammar S→AC|CB, C→aCb|ε, A→aA|a, B→Bb|b, count the production applications in a derivation from S of a^l b^m, with l,m≥0 and l≠m. GFG prints the same expression in A and D; GateForum D instead has +3.
Options:
(A) max(l,m)+2
(B) l+m+2
(C) l+m+3
(D) max(l,m)+2 [GFG]; max(l,m)+3 [GateForum]
Question 85, GATE 2006: Using grammar S→AC|CB, C→aCb|ε, A→aA|a, B→Bb|b, count the production applications in a derivation from S of a^l b^m, with l,m≥0 and l≠m. GFG prints the same expression in A and D; GateForum D instead has +3.
Options:
(A) max(l,m)+2
(B) l+m+2
(C) l+m+3
(D) max(l,m)+2 [GFG]; max(l,m)+3 [GateForum]
Tap to enlarge
Your answer
Answer & solution

Answer: max(l,m)+2 (options A and D are printed identically) (no official key was published)

1. For l>m use S→AC (1 step), expand C by C→aCb exactly m times and then C→ε (m+1 steps), and derive al−m from A using l−m productions (l−m−1 recursive steps and one terminal step). Total=1+(m+1)+(l−m)=l+2.

2. For m>l the CB branch gives m+2. Thus the length is max(l,m)+2, regardless of the order in which independent nonterminals are expanded.

3. Both A and D visibly print this same expression, so no unique option letter is supported.

4. Teaching check: Count production applications, including C→ε and the initial S choice. For l=3,m=1, use S→AC, A→aA→aa, C→aCb→ab: five applications, equal to max(3,1)+2. Interleaving A and C expansions does not alter the number of productions used.

Original paper, page 13

2 marks · MCQ
Report issue

Reduction direction and undecidability

Decidability & Computability

Question 45, GATE 2005: P1 is decidable, P2 undecidable. Which is true? A P3 decidable if P1 reduces to P3; B P3 undecidable if P3 reduces to P2; C P3 undecidable if P2 reduces to P3; D P3 decidable if P3 reduces to its complement.
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

If undecidable P2 reduces effectively to P3, a decider for P3 would decide P2 by applying the reduction first. Therefore P3 is undecidable (C). Reducing a decidable problem to P3 says nothing about P3; reducing P3 to an undecidable target also gives no such conclusion.

A reduction converts an instance of its source problem into a target instance while preserving the yes/no answer. If undecidable P2 reduces to P3 and P3 had a decider, their composition would decide P2, a contradiction. Thus C. Reduction direction matters: mapping an easy problem into a hard one does not make the easy problem hard, nor does it make the target easy.

Original paper, page 5

2 marks · MCQ
Report issue

Language of a DFA

Finite Automata

Question 53, GATE 2005: A deterministic machine over {a, b} starts at nonfinal q0. It has q0−b→q0, q0−a→q1, q1−b→q2, q2−b→q3, with final q3, q3−b→q3 and q3−a→q1; omitted transitions reject. Identify its language. Offered B describes every a being followed by at least two b symbols. Determine whether that wording is exact, including empty and b-only strings. Other choices: A every a followed by exactly two b symbols; C strings containing abb; D strings not containing aa.
Question 53, GATE 2005: A deterministic machine over {a, b} starts at nonfinal q0. It has q0−b→q0, q0−a→q1, q1−b→q2, q2−b→q3, with final q3, q3−b→q3 and q3−a→q1; omitted transitions reject. Identify its language. Offered B describes every a being followed by at least two b symbols. Determine whether that wording is exact, including empty and b-only strings. Other choices: A every a followed by exactly two b symbols; C strings containing abb; D strings not containing aa.
Tap to enlarge
Your answer
Answer & solution

Answer: No exact option; B if at least one a is required (no official key was published)

The start state has a b-loop but is not accepting. An a starts a required pair of b transitions, after which the accepting state permits more b symbols or another a followed by at least two b symbols. Hence the exact language is b*(abb b*)+ = b*(ab{2,})+. All words have at least one a, and every a is followed by at least two consecutive b symbols. Option B omits the at-least-one-a condition and therefore includes ε and every b-only word by vacuous truth, all rejected by the depicted machine. The paper shows the nonaccepting start state. B describes the intended restriction only if the domain excludes b*; there is no literally exact offered answer. Diagram and options continue on page 7.

Trace complete trips from the start to the final state. Initial b symbols can be arbitrary, but they never reach a final state. The first a must be followed by two b transitions to enter q3; additional b symbols may follow, and each later a begins another mandatory two-b segment. Thus at least one ab{2,} block is required. Checking ε or b provides immediate counterexamples to the broad offered description: its universal condition is vacuously true while the machine rejects. Do not silently mark the intended option as an exact language equality.

Original paper, page 6

2 marks · MCQ
Report issue

Determinism in finite and pushdown automata

Pushdown Automata

Question 54, GATE 2005: Let Df, Nf, Dp, Np denote languages accepted by deterministic finite, nondeterministic finite, deterministic pushdown and nondeterministic pushdown automata. Determine the equality/proper-inclusion relationships. The intended option D is Df=Nf and Dp properly contained in Np. Other options: A both inclusions proper; B Df proper subset Nf and Dp=Np; C both pairs equal.
Tap to enlarge
Your answer
Answer & solution

Answer: D (no official key was published)

Subset construction converts any NFA into a DFA, so Df=Nf. A DPDA is a restricted NPDA, and the inclusion Dp⊊Np is strict, for example unmarked even palindromes require nondeterministic midpoint choice. Thus D. The printed subset symbol is interpreted as proper inclusion.

For finite automata, a DFA state can represent the full subset of possible NFA states after each prefix, so nondeterminism does not increase language expressive power. For pushdown automata, deterministic computation cannot generally guess an unmarked midpoint while preserving the necessary stack comparison. Every deterministic machine is a special nondeterministic one, but some CFLs such as unmarked even palindromes are not deterministic CFLs. Hence the first pair is equal and the second inclusion is strict.

Original paper, page 7

2 marks · MCQ
Report issue

Intersection of two context-free languages

Closure Properties & Language Hierarchy

Question 55, GATE 2005: L1={a^n b^n c^m:n, m>0}, L2={a^n b^m c^m:n, m>0}. Identify the false claim among: A their intersection is context-free; B their union is context-free; C both individual languages are context-free; D their intersection is context-sensitive.
Tap to enlarge
Your answer
Answer & solution

Answer: A (no official key was published)

L1={an bn cm:n, m>0} and L2={an bm cm:n, m>0} each need only one stack comparison, hence are CFLs. CFLs are closed under union. Their intersection is {ak bk ck:k>0}, which is not context-free (standard CFL pumping argument) but is context-sensitive by linear-space counting. The false assertion is A.

Each individual language compares only two adjacent block counts and allows the remaining block freely, which a PDA can handle. Closure under union proves the union claim. In the intersection, the first language forces #a=#b and the second forces #b=#c, hence all three counts coincide. The standard pumping argument prevents a single stack from enforcing these three blocks: a short pumped region cannot cover all three, so pumping changes only one or two counts or disrupts the block order. Linear-space checking still recognizes the intersection, establishing context sensitivity.

Original paper, page 7

2 marks · MCQ
Report issue

Complements of recursive and enumerable languages

Closure Properties & Language Hierarchy

Question 56, GATE 2005: L1 is recursive; L2 is recursively enumerable but not recursive. Which is true of their complements? A complement L1 recursive and complement L2 RE; B complement L1 recursive and complement L2 not RE; C both complements RE; D complement L1 RE and complement L2 recursive.
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

A recursive language has a halting decider, whose accept/reject outputs can be swapped to decide its complement. If both L2 and its complement were recursively enumerable, dovetailing their recognizers would decide L2, contradicting its nonrecursive premise. Thus complement(L1) is recursive and complement(L2) is not recursively enumerable, B.

A decider always halts, so swapping its accept/reject outcomes gives a complement decider. A recognizer need not halt on nonmembers, so that swap does not work for an arbitrary RE language. If both L2 and its complement had recognizers, run them in alternating steps on any input. Exactly one must eventually accept, deciding which side the input belongs to. That would contradict the given nonrecursive status. Thus B, with the nonhalting possibility explaining the distinction.

Original paper, page 7

2 marks · MCQ
Report issue

Marked palindromes versus copying

Pushdown Automata

Question 57, GATE 2005: For binary w, L1={wwᴿ}, L2={w#wᴿ} with special delimiter#, L3={ww}. Which is true? A L1 deterministic CFL; B L2 deterministic CFL; C L3 CFL but not deterministic; D L3 deterministic CFL.
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

For L2={w#wR}, a DPDA pushes before # and then deterministically pops and compares after #; it accepts exactly upon a complete match. L1={wwR} has no delimiter and is context-free but not deterministic context-free. L3={ww} is not context-free. Therefore B.

For the delimited language, # tells the PDA exactly when to switch from pushing to comparing/popping. Every decision is determined by current input and stack top, so the recognizer is deterministic. Without the delimiter, a palindrome PDA must in general choose the midpoint nondeterministically. The duplicated-word language requires preserving the same order twice, not the reverse stack order, and is not CFL. These distinctions are about whole language classes, not whether some individual examples can be recognized.

Original paper, page 7

1 mark · MCQ
Not in GATE 2027 syllabusReport issue

Complexity of two-SAT and three-SAT

Complexity & Reductions

Question 30, GATE 2004: Which complexity classification applies to 3-SAT and 2-SAT respectively?
Options:
(A) Both in P
(B) Both NP-complete
(C) NP-complete and in P
(D) Undecidable and NP-complete
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

Step 1: 3-SAT is NP-complete.2-SAT is decidable in polynomial time, for example by strongly connected components of its implication graph, so C. These classifications are established without assuming P≠NP; saying 3-SAT is NP-complete is not a proof that it lies outside P.

Step 2: Teaching check: For 2-SAT, clause (u∨v) adds implications ¬u→v and ¬v→u. The formula is unsatisfiable exactly when some variable and its negation occupy one strongly connected component. This polynomial algorithm is why one cannot extend the 3-SAT hardness conclusion to two literals.

Original paper, page 4

2 marks · MCQ
Report issue

Product automaton for counts modulo three and two

Finite Automata

Question 86, GATE 2004: A DFA has six states arranged as top row t0,t1,t2 and bottom row b0,b1,b2. Initial and sole accepting state is t0. On 1, each row cycles left-to-right: t0→t1→t2→t0 and b0→b1→b2→b0. On 0, each column toggles tj↔bj. Which condition on (#1,#0) describes the accepted strings?
Options:
(A) Divisible by 3 and 2 respectively
(B) Odd and even respectively
(C) Even and odd respectively
(D) Divisible by 2 and 3 respectively
Tap to enlarge
Your answer
Answer & solution

Answer: A (no official key was published)

1. Label each of the three columns by the count of ones modulo 3, from left to right 0,1,2; label upper and lower rows by the count of zeros modulo 2, 0 and 1. Each 1 edge advances one column cyclically without changing row, and each 0 edge toggles the row without changing column.

2. The initial upper-left state is the only accepting state. Hence acceptance requires #1≡0 mod3 and #0≡0 mod2, option A, including the empty string.

3. Teaching check: The two counters are independent: reading 1 changes the column but not the row, and reading 0 changes the row but not the column. Returning to t0 requires both modular counts to return to zero. The empty word is accepted because the start state is accepting.

Original paper, page 12

2 marks · MCQ
Report issue

Classify a language with additive block counts

Context-Free Grammars & Languages

Question 87, GATE 2004: Classify L={a^m b^n c^(m+n):m,n≥1}.
Options:
(A) Regular
(B) Context-free but not regular
(C) Context-sensitive but not context-free
(D) Type-0 but not context-sensitive
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

1. For L={am bn cm+n:m,n≥1}, a context-free grammar is S→aSc | aTc and T→bTc | bc. The outer recursion supplies matching a/c pairs and the inner recursion matching b/c pairs, so it generates exactly L.

2. It is not regular: for a putative pumping length p, use ap b cp+1. Any pumpable segment within the first p symbols consists only of a characters; pumping changes the a count without changing the c count, violating the defining equality.

3. Therefore context-free but not regular, B.

4. Teaching check: A pushdown automaton can push one marker for each a and b, then pop one for each c, while tracking the required block order and nonempty a,b blocks. A finite automaton cannot maintain the unbounded count equality; the pumping argument makes this limitation rigorous.

Original paper, page 12

2 marks · MCQ
Report issue

Right-linear grammar counts a modulo three

Regular Expressions & Languages

Question 88, GATE 2004: Grammar G has S→bS | aA | b; A→bA | aB; B→bB | aS | a. Na(w),Nb(w) count a,b symbols. Which describes L(G) within {a,b}^+ (nonempty words)?
Options:
(A) {w:Na(w)>3Nb(w)}
(B) {w:Nb(w)>3Na(w)}
(C) {w:Na(w)=3k, k∈{0,1,2,…}}
(D) {w:Nb(w)=3k, k∈{0,1,2,…}}
Question 88, GATE 2004: Grammar G has S→bS | aA | b; A→bA | aB; B→bB | aS | a. Na(w),Nb(w) count a,b symbols. Which describes L(G) within {a,b}^+ (nonempty words)?
Options:
(A) {w:Na(w)>3Nb(w)}
(B) {w:Nb(w)>3Na(w)}
(C) {w:Na(w)=3k, k∈{0,1,2,…}}
(D) {w:Nb(w)=3k, k∈{0,1,2,…}}
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

1. Interpret S,A,B as states tracking the number of a symbols modulo 3: a advances S→A→B→S, while b leaves the state unchanged. Terminating production S→b ends with residue 0, and B→a also ends with residue 0.

2. Consequently every generated word has #a divisible by 3. Conversely any nonempty word with that property can be scanned along these transitions; if its last symbol is b it terminates via S→b, and if its last symbol is a it terminates via B→a.

3. Thus L={w in {a,b}^+ : #a(w)≡0 mod3}, option C in the stated positive-word universe.

4. Teaching check: There is no ε production, so the empty word is excluded despite having zero a symbols. The problem explicitly uses {a,b}^+, which resolves that apparent exception. Each a advances one of three residue states while any b preserves it.

Original paper, page 12

2 marks · MCQ
Report issue

Decidability of an enumeration-order language

Decidability & Computability

Question 89, GATE 2004: L1 is recursively enumerable over Σ. Algorithm A enumerates its words as w1,w2,w3,… . Let #∉Σ and L2={wi#wj:wi,wj∈L1 and i<j}. Consider S1: if L1 is recursive then L2 is recursive; S2: if L2 is recursive then L1 is recursive. Which is true? The reproduction does not state whether enumeration can repeat words; keep that distinction explicit.
Options:
(A) Both S1 and S2
(B) S1, but S2 need not be true
(C) S2, but S1 need not be true
(D) Neither need be true
Tap to enlarge
Your answer
Answer & solution

Answer: None (no official key was published)

1. Under repetition-free enumeration, both S1 and S2 hold (A). For S1, first decide membership of both components in recursive L1; if either is absent reject, otherwise run A until both appear and compare their unique indices.

2. For S2, if L1 is empty it is recursive. Otherwise fix its first enumerated word w1.

3. Decide whether x is in L1 by accepting x=w1 and otherwise asking the L2 decider whether w1#x belongs. Every other word appears later, so this is correct.

4. The S2 argument also survives repetitions. However, if arbitrary repetitions are permitted, S1 can fail: let recursive L1 consist of all distinct tags ae and be.

5. Enumerate each be before its ae, and repeat be after ae exactly if machine e halts, using dovetailing. Then ae#be belongs to L2 exactly for halting machines, making L2 nonrecursive despite recursive L1.

6. Thus with repetitions allowed only S2 is necessarily true (C). No unconditional option is assigned without fixing the enumeration convention.

7. Teaching check: The relation depends on enumeration positions, not a lexicographic order on words. If words repeat, one pair may have witnesses in both directions. That is why a proof using unique indices needs an explicit repetition-free convention instead of being applied automatically.

Original paper, page 12

1 mark · MCQ
Not in GATE 2027 syllabusReport issue

Two directions of an NP-completeness proof

Complexity & Reductions

Question 12, GATE 2003: Ram gives a polynomial-time reduction from 3-SAT to decision problem Π. Shyam gives a polynomial-time reduction from Π to 3-SAT. What follows? A. Π is NP-hard but not NP-complete; B. Π is in NP but not NP-complete; C. Π is NP-complete; D. Π is neither NP-hard nor in NP.
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

1. Reduction direction matters: 3-SAT≤pΠ means a solver for Π could solve an NP-complete problem, proving hardness. For membership, compute the other reduction and use a satisfying assignment to the resulting 3-CNF as a polynomial certificate. Combining membership and hardness is precisely NP-completeness.

2. The reduction 3-SAT≤pΠ proves Π is NP-hard. The reduction Π≤p 3-SAT supplies a polynomial verifier/NP algorithm because 3-SAT is in NP, so Π is in NP. Together these establish NP-completeness, C, for the standard decision-problem reductions.

Original paper, page 2

1 mark · MCQ
Report issue

Unknown proposition defining a simple language

Decidability & Computability

Question 13, GATE 2003: Define L={0,1}* if P=NP, and L=∅ otherwise. Which statement is true? A. L is recursive; B. L is recursively enumerable but not recursive; C. L is not recursively enumerable; D. Its recursiveness can be known only after resolving P=NP.
Question 13, GATE 2003: Define L={0,1}* if P=NP, and L=∅ otherwise. Which statement is true? A. L is recursive; B. L is recursively enumerable but not recursive; C. L is not recursively enumerable; D. Its recursiveness can be known only after resolving P=NP.
Tap to enlarge
Your answer
Answer & solution

Answer: A (no official key was published)

1. Reason by cases without trying to resolve the open problem. If P=NP, an always-accept machine decides L. Otherwise an always-reject machine decides L. Each possible language has a halting decider, so the uncertainty about which case holds is not noncomputability of L.

2. Regardless of the truth of P=NP, L is either all binary strings or the empty language. Both are regular and recursive, so L is recursive, A. Establishing that some decider exists does not require knowing which of these two particular deciders describes L.

Original paper, page 2

1 mark · MCQ
Report issue

Equivalent binary regular expressions

Regular Expressions & Languages

Question 14, GATE 2003: Which regular expression denotes the same language as 0*(10*)*? Here + means union. A. (1*0)*1*; B. 0+(0+10)*; C. (0+1)*10(0+1)*; D. None of these.
Tap to enlarge
Your answer
Answer & solution

Answer: A (no official key was published)

1. For instance, 0010010 splits as 00·100·10 under the given expression. In A it splits into zero-terminated blocks with a final run of ones. B cannot produce the single string 1, and C requires a substring 10 and thus misses ε,0,1. This distinguishes the alternatives without merely appealing to a pattern resemblance.

2. Every binary string can be divided into an initial zero run followed by successive 1-and-zero-run blocks, so 0*(10*)*=Σ*. Likewise(1*0)*1* parses successive zero-terminated blocks followed by a final one run and also gives Σ*. Thus A. The other listed expressions do not cover exactly all binary strings.

Original paper, page 2

1 mark · MCQ
Report issue

Ordered enumeration and decidability

Decidability & Computability

Question 15, GATE 2003: If a language’s strings can be effectively enumerated in lexicographic (the reproduction says “alphabetic”) order, which conclusion is intended? A. L is necessarily finite; B. L is regular but not necessarily finite; C. L is context-free but not necessarily regular; D. L is recursive but not necessarily context-free. The distinction between dictionary order and the usual effective length-first order must be addressed.
Tap to enlarge
Your answer
Answer & solution

Answer: D under the standard length-lexicographic convention (no official key was published)

1. Separate two issues: whether membership is decidable, and whether the enumerator itself yields a stopping test. In effective length-first order each target has finitely many predecessors; its absence is detected once the enumeration passes it. Alphabetic dictionary order lacks that finite-predecessor property, so the conventional answer needs the stated interpretation rather than an unqualified appeal to sortedness.

2. With an effective shortlex (length-first, then alphabetic) enumeration in increasing order, membership is decided by enumerating until the target appears or an output exceeds it; if the enumerator terminates, absence is also decided. Finite languages are recursive separately. Thus the conventional result is recursive but not necessarily context-free, D; for example{0n 1n 2n} has a computable ordered enumeration. The the paper explicitly says lexicographic/alphabetic, not length-first. Ordinary dictionary order can have infinitely many predecessors, so the surpassing argument needs an additional guarantee: enumeration of 0,00,000,... never surpasses the absent string 1. The conclusion is recorded under the standard effective length-order convention, not justified by that flawed stopping argument for arbitrary dictionary order.

Original paper, page 2

2 marks · MCQ
Report issue

Counting constrained binary strings accepted by a DFA

Finite Automata

Question 50, GATE 2003: A DFA over {0,1} has states q0 (start), q1, q2 and q3 (the only accepting state). Transitions: q0 on 1→q0 and 0→q1; q1 on 1→q0 and 0→q2; q2 on 0→q2 and 1→q3; q3 on either symbol→q3. Let S contain seven-bit strings whose first, fourth and last bits are 1. How many strings of S are accepted?
A. 1  B. 5  C. 7  D. 8
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

1. Reaching q2 requires two consecutive zeros; after reaching q2 a later 1 enters the absorbing accepting state q3.
2. Strings of S have form 1xy1zw1, leaving four free bits and 16 total strings. Adjacent zeros can occur only as xy=00 or zw=00, because fixed 1s separate the blocks.
3. Fixing xy=00 leaves four choices for zw; fixing zw=00 leaves four choices for xy. The string 1001001 is counted twice. Inclusion–exclusion yields 4+4−1=7, so C.

Solution: The DFA accepts precisely strings that contain two consecutive zeros followed later by a one. With positions 1,4,7 fixed to one, a qualifying pair of zeros must occupy positions 2–3 or 5–6, and the following fixed one guarantees acceptance. Of the 16 assignments to the four free bits, four have the first zero pair, four have the second, and one has both. Inclusion–exclusion gives 4+4−1=7 accepted strings, option C.

Original paper, page 7

2 marks · MCQ
Report issue

Deterministic recognition of balanced brackets

Context-Free Grammars & Languages

Question 51, GATE 2003: Let G=({S},{a,b},R,S), where R is S→aSb | SS | ε. Which statement is true?
A. G is not ambiguous.
B. There exist x,y in L(G) with xy not in L(G).
C. A deterministic pushdown automaton accepts L(G).
D. A deterministic finite-state automaton accepts L(G).
Question 51, GATE 2003: Let G=({S},{a,b},R,S), where R is S→aSb | SS | ε. Which statement is true?
A. G is not ambiguous.
B. There exist x,y in L(G) with xy not in L(G).
C. A deterministic pushdown automaton accepts L(G).
D. A deterministic finite-state automaton accepts L(G).
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

1. Interpret a as an opening bracket and b as a closing bracket. aSb encloses a balanced string, SS concatenates two balanced strings, and ε is balanced. Conversely, split any nonempty balanced string at its first matching close to obtain these productions.
2. A deterministic stack machine pushes on a, pops on b, rejects a pop from an empty stack, and accepts exactly with empty stack at end. This establishes C.
3. A is false: ε has both the direct S→ε tree and S→SS→εε. B is false because S→SS supplies closure under concatenation. D is false because intersecting with regular a*b* leaves the nonregular language {an bn:n≥0}.

Solution: The grammar generates balanced strings with a as opening bracket and b as closing bracket, including concatenations and the empty word. A deterministic pushdown automaton pushes on a, pops on b, rejects an unmatched b, and accepts at the end exactly when its stack is empty. Thus C is true. The grammar itself is ambiguous, for example ε can be produced directly or through S→SS with two empty children. Its language is closed under concatenation by S→SS and is not regular, since intersection with a*b* gives {aⁿbⁿ:n≥0}.

Original paper, page 7

2 marks · MCQ
Report issue

Decidability under a polynomial-time language isomorphism

Decidability & Computability

Question 52, GATE 2003: L1 and L2 are languages over Σ. A bijection f:Σ*→Σ* and its inverse are polynomial-time computable, and for every x, x∈L1 iff f(x)∈L2. Which cannot hold?
A. L1∈P and L2 is finite
B. L1∈NP and L2∈P
C. L1 is undecidable and L2 is decidable
D. L1 is recursively enumerable and L2 is recursive
Source caveat: GateForum drops the stars in the displayed domain/codomain; the GFG string-domain version is used here.
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

1. Suppose L2 has a decider D2. An algorithm for L1 computes f(x), which always terminates, then returns D2(f(x)). The membership equivalence makes this algorithm correct and terminating.
2. Thus decidability of L2 forces decidability of L1, contradicting C. In fact the inverse supplies the converse reduction too.
3. The other combinations are not contradictions. Take f to be identity and L1=L2=∅: the language is finite, in P and NP, recursive and recursively enumerable. This single example witnesses the possibility of A, B and D.

Solution: If L₂ is decidable, compute f(x) and run its decider; the membership equivalence decides L₁. Hence an undecidable L₁ and decidable L₂ cannot coexist, option C. The other alternatives are possible by choosing finite or otherwise polynomial-time decidable languages: P is contained in NP, and recursively enumerable does not mean nonrecursive.

Original paper, page 7

2 marks · MCQ
Report issue

Nonhalting behavior of a two-state Turing machine

Turing Machines

Question 53, GATE 2003: A single-tape Turing machine has states q0 (start), q1, tape symbols {0,1,B}, and input alphabet {0,1}; B is blank. A transition (q,s,D) means write s, move D, enter q. The table is:
q0 on 0: (q1,1,R); on 1: (q1,1,R); on B: Halt.
q1 on 0: (q1,1,R); on 1: (q0,1,L); on B: (q0,B,L).
Which is true?
A. M does not halt on any string in (0+1)+.
B. M does not halt on any string in (00+1)*.
C. M halts on all strings ending in 0.
D. M halts on all strings ending in 1.
Here + between symbols is union and superscript + means one or more repetitions.
Tap to enlarge
Your answer
Answer & solution

Answer: A (no official key was published)

1. Empty input starts with a blank under q0 and halts immediately. Since ε belongs to (00+1)*, B cannot be true.
2. On any nonempty input q0 writes a 1 and moves right into q1. q1 passes over zeros, replacing each with 1, until reaching either a preexisting 1 or the right-hand blank.
3. At this boundary q1 moves left to q0. That left cell is now 1, so q0 moves right into q1 without changing it. q1 sees the same boundary symbol and moves left again. These two configurations repeat forever.
4. This applies to every nonempty binary input, regardless of its final symbol. Hence A, not C or D.

Solution: On a nonempty input, q₀ writes 1 in the first cell and moves right in q₁. State q₁ changes any subsequent zeros to ones and moves right until it sees a 1 or the first blank. At either such boundary it moves left into q₀. The cell to its left is now 1, so q₀ moves right again to the boundary in q₁, producing a two-configuration loop. Thus every nonempty binary input diverges, option A. Empty input halts immediately, so option B, whose starred language includes ε, is false.

Original paper, page 7

2 marks · MCQ
Report issue

Tagged halting and nonhalting languages

Decidability & Computability

Question 54, GATE 2003: Define L0={⟨M,w,0⟩: M halts on w} and L1={⟨M,w,1⟩: M does not halt on w}, where M is a Turing-machine encoding, w a string and the last component a bit. Let L=L0∪L1. Which is true?
A. L is recursively enumerable but its complement is not.
B. Its complement is recursively enumerable but L is not.
C. Both L and its complement are recursive.
D. Neither L nor its complement is recursively enumerable.
Question 54, GATE 2003: Define L0={⟨M,w,0⟩: M halts on w} and L1={⟨M,w,1⟩: M does not halt on w}, where M is a Turing-machine encoding, w a string and the last component a bit. Let L=L0∪L1. Which is true?
A. L is recursively enumerable but its complement is not.
B. Its complement is recursively enumerable but L is not.
C. Both L and its complement are recursive.
D. Neither L nor its complement is recursively enumerable.
Tap to enlarge
Your answer
Answer & solution

Answer: D (no official key was published)

1. The halting language H is recognizable, but its complement is not recognizable: recognizers for both would yield a decider by dovetailing them.
2. Map each halting-instance pair (M,w) to ⟨M,w,1⟩. It belongs to L exactly when M does not halt. Therefore a recognizer for L would recognize the complement of H, impossible.
3. Map the same pair to ⟨M,w,0⟩. It belongs to the complement of L exactly when M does not halt. A recognizer for that complement would give the same contradiction.
4. Neither tagged language is recognizable, so D. The different tags are essential; halting and nonhalting cases are not simply being unioned without a tag.

Solution: Let H be the halting language. If L were recursively enumerable, mapping (M,w) to ⟨M,w,1⟩ would make the complement of H recursively enumerable, a contradiction. If the complement of L were recursively enumerable, mapping (M,w) to ⟨M,w,0⟩ would again recognize the complement of H. Therefore neither L nor its complement is recursively enumerable, option D. The tag prevents the union from simply being the universal set.

Original paper, page 7

2 marks · MCQ
Report issue

Flipping final states in an NFA

Finite Automata

Question 55, GATE 2003: An NFA M over {0,1} has states p (start), q and r (only final). Transitions are p→q on 0 or 1; q→p on 0; q→q on 0 or 1; p→r on 1; q→r on 0; r→q on 0. There are no other transitions. Let L=L(M). M1 is obtained by making r nonfinal and p,q final, and L1=L(M1). Which statement is true?
A. L1={0,1}*−L
B. L1={0,1}*
C. L1⊆L
D. L1=L
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

1. Since p is final in M1, ε is accepted.
2. For any nonempty word, choose p→q on its first symbol. Then choose the 0/1 loop at q for every remaining symbol. This accepting run exists for every word.
3. Therefore L1 is the universal binary language, B. In particular ε∈L1 but ε∉L, ruling out C and D. Since 1∈L as well as L1, they are not complements, ruling out A. NFA acceptance is existential over runs, which is why simply flipping finals fails as a complement construction.

Solution: After the flip, the initial left state and the upper-right state are accepting. The empty string is accepted at the initial state. For every nonempty binary string, choose the transition from the initial state to the upper-right state on its first symbol and then use that state’s 0/1 loop for the suffix. Therefore the new language is all of {0,1}*, option B. Flipping final states complements a complete DFA, not a general NFA.

Original paper, page 8

1 mark · MCQ
Report issue

Pushdown automaton with bounded stack

Pushdown Automata

Question 1.7, GATE 2002: A pushdown automaton is restricted to at most 10 stack items. Which class best describes the language it accepts?
(A) Context-free; (B) Regular; (C) Deterministic context-free; (D) Recursive.
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

Step 1: Turn stack contents into finite control.

Step 2: If the stack alphabet has s symbols, at most 1+s+…+s10 stack words are possible. With q control states, at most q(1+s+…+s10) combined configurations are needed, apart from fixed acceptance bookkeeping. Every push/pop transition can be represented between these finite states, so an unbounded-memory PDA advantage is absent.

Conclusion: A fixed finite stack alphabet and maximum stack height 10 allow only finitely many stack strings. Pairing each with the finite control state yields a finite automaton, including epsilon transitions if needed. Hence the language is regular, B; the larger language classes listed are less precise.

Original paper, page 1

2 marks · MCQ
Report issue

Automaton for lengths divisible by three

Finite Automata

Question 2.13, GATE 2002: How many states does the smallest finite automaton need to accept all strings whose lengths are divisible by 3?
(A) 2; (B) 3; (C) 4; (D) 5.
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

Step 1: Explain both construction and minimality.

Step 2: Label states 0,1,2 and send each state to its successor modulo 3 for every input symbol. Start and accept at 0. To distinguish residues r≠s, append a word of length(3−r) mod3: the state r accepts afterward and s does not. Thus no two residue states can be merged in a deterministic automaton.

Conclusion: Use three states for the input length modulo 3, advance the residue on every symbol, and accept residue 0. The three residues are distinguishable: append a length that brings one chosen residue to 0; it does not bring a different residue to 0. Thus a minimal DFA has 3 states, B, over a nonempty alphabet.

Original paper, page 5

2 marks · MCQ
Report issue

Complement closure and overlapping answer choices

Closure Properties & Language Hierarchy

Question 2.14, GATE 2002: Which statement is true?
(A) The complement of a recursive language is recursive.
(B) The complement of a recursively enumerable language is recursively enumerable.
(C) The complement of a recursive language is either recursive or recursively enumerable.
(D) The complement of a context-free language is context-free.
Tap to enlarge
Your answer
Answer & solution

Answer: A; C is also true with inclusive or (no official key was published)

Step 1: Separate mathematical closure from multiple-choice wording.

Step 2: A recursive decider halts on every input; reversing its output gives another total decider. A recognizer for an arbitrary RE language need not halt on nonmembers, so merely reversing its states is not a complement recognizer. Option C nevertheless remains true as a weak inclusive disjunction because its first alternative already holds; it is not made false simply by being less informative than A.

Conclusion: A decider always halts, so swapping its accept and reject answers decides the complement. Thus A is true. Recursive languages are also recursively enumerable, making C’s printed claim that the complement is either recursive or recursively enumerable true as an inclusive disjunction as well. If C intends recursive or merely-RE-but-not-recursive, its imprecise wording is hiding that distinction. General RE languages are not closed under complement (otherwise dovetailing both recognizers decides every RE language), and CFLs are not closed under complement. A is the strongest precise statement, but the literal single-choice options overlap.

Original paper, page 5

2 marks · MCQ
Report issue

Context dependence in C programs

Other / Mixed Topics

Question 2.18, GATE 2002: Classify the C programming language.
(A) Context-free; (B) Context-sensitive; (C) Regular; (D) Fully parsable only by a Turing machine.
Tap to enlarge
Your answer
Answer & solution

Answer: B under the usual syntax-plus-static-constraints interpretation (no official key was published)

Step 1: Distinguish parsing from all static validity checks.

Step 2: A phrase-structure grammar can describe expression and statement shapes while a symbol table checks whether identifier uses agree with their declarations. The latter checks depend on context not captured by merely recognizing those shapes. The answer’s scope is this conventional language-classification question, not a claim that a context-free parser alone proves a C program fully valid or that it decides termination.

Conclusion: C includes context-dependent restrictions such as consistent declarations and uses of identifiers, beyond a context-free phrase-structure grammar. The usual classification including such static checks is context-sensitive, B. A compiler may still use a context-free parser supplemented by symbol-table analysis; this does not make all well-formed C programs a context-free syntax-only language. Runtime behavior and whether a program halts are separate from this classification.

Original paper, page 5

Descriptive
Report issue

Reduction machine: simulate a fixed computation

Decidability & Computability

Question 14(a), GATE 2002: Prove undecidable the language of machines M that halt and output 1 on every input, by reducing the known halting problem {⟨M′,x⟩:M′ halts on x}. Construct M from M′,x. Original14(a): On input w, describe the first main step M performs.
Question 14(a), GATE 2002: Prove undecidable the language of machines M that halt and output 1 on every input, by reducing the known halting problem {⟨M′,x⟩:M′ halts on x}. Construct M from M′,x. Original14(a): On input w, describe the first main step M performs.
Tap to enlarge
Answer & solution

Answer: Ignore input w and simulate M′ on the hard-coded input x. (no official key was published)

Given a halting-problem instance ⟨M′,x⟩, effectively construct a machine M with M′ and x embedded in its finite description. On arbitrary input w, ignore w and simulate M′ on x. If that computation never halts, this simulation never proceeds to the next step. The construction itself does not need to decide whether M′ halts.

Original paper, page 8

Descriptive
Report issue

Reduction machine: output after the simulation halts

Decidability & Computability

Question 14(b), GATE 2002: Prove undecidable the language of machines M that halt and output 1 on every input, by reducing the known halting problem {⟨M′,x⟩:M′ halts on x}. Construct M from M′,x. Original14(b): Describe its second step, depending on the first step’s outcome.
Question 14(b), GATE 2002: Prove undecidable the language of machines M that halt and output 1 on every input, by reducing the known halting problem {⟨M′,x⟩:M′ halts on x}. Construct M from M′,x. Original14(b): Describe its second step, depending on the first step’s outcome.
Tap to enlarge
Answer & solution

Answer: If the simulation halts, output 1 and halt; otherwise continue simulating forever. (no official key was published)

After the simulation of M′ on x terminates, discard its result, output 1, and halt. The branch is triggered by any halting outcome of M′, not only acceptance or output 1. If M′ fails to halt, M never reaches this branch on any input w.

Original paper, page 8

Descriptive
Report issue

Correctness of the all-input halting reduction

Decidability & Computability

Question 14(c), GATE 2002: Prove undecidable the language of machines M that halt and output 1 on every input, by reducing the known halting problem {⟨M′,x⟩:M′ halts on x}. Construct M from M′,x. Original14(c): State the key equivalence relating M on arbitrary w to M′ on x.
Question 14(c), GATE 2002: Prove undecidable the language of machines M that halt and output 1 on every input, by reducing the known halting problem {⟨M′,x⟩:M′ halts on x}. Construct M from M′,x. Original14(c): State the key equivalence relating M on arbitrary w to M′ on x.
Tap to enlarge
Answer & solution

Answer: M′ halts on x iff M halts and outputs 1 on every input. (no official key was published)

If M′ halts on x, its simulation finishes regardless of the ignored input w, and M then halts with output 1 for every w. If M′ does not halt on x, M loops on every w, so its description is not in the target language. Thus ⟨M′,x⟩ belongs to HALT iff the computably constructed ⟨M⟩ belongs to {⟨N⟩: N halts and outputs 1 on every input}. A decider for the target language would decide HALT by constructing M and invoking that decider, which is impossible. Hence the target language is undecidable.

Original paper, page 8

Descriptive
Report issue

Four-state NFA for strings ending in abb

Finite Automata

Question 21(a), GATE 2002: Original21(a): Construct a four-state NFA for the language (a|b)*abb over {a,b}. Specify initial/final states and every transition.
Question 21(a), GATE 2002: Original21(a): Construct a four-state NFA for the language (a|b)*abb over {a,b}. Specify initial/final states and every transition.
Tap to enlarge
Answer & solution

Answer: Start q0, accept q3: δ(q0,a)={q0,q1}, δ(q0,b)={q0}, δ(q1,b)={q2}, δ(q2,b)={q3}; all other transitions empty. (no official key was published)

Over alphabet {a,b}, use states q0,q1,q2,q3, with q0 initial and q3 the sole accepting state. q0 has loops on a and b and an additional a-transition to q1; q1 has a b-transition to q2; q2 has a b-transition to q3; q3 has no outgoing transitions. In notation:
q0 --a--> q1 --b--> q2 --b--> q3 (accept), with a,b self-loops at q0.
The loop consumes an arbitrary prefix from (a|b)*, and a nondeterministic branch chooses the a beginning the final abb. Acceptance requires the whole input to end at q3, so the last three letters must be abb. Conversely every string ending in abb has such an accepting path. No epsilon transitions or extra states are needed.

Original paper, page 10

Descriptive
Report issue

Four-state DFA for strings ending in abb

Finite Automata

Question 21(b), GATE 2002: Original21(b): Construct a four-state DFA for the same language (a|b)*abb; specify all transitions and accepting state.
Question 21(b), GATE 2002: Original21(b): Construct a four-state DFA for the same language (a|b)*abb; specify all transitions and accepting state.
Tap to enlarge
Answer & solution

Answer: Start q0, accept q3. On (a,b): q0→(q1,q0); q1→(q1,q2); q2→(q1,q3); q3→(q1,q0). (no official key was published)

Step through it (2 parts)

Use state qj to record the length j of the longest suffix of the input seen so far that is also a prefix of abb. The four represented suffixes are empty, a, ab, abb. Start at q0 and accept only q3. The transition table is:
State | a | b
q0 | q1 | q0
q1 | q1 | q2
q2 | q1 | q3
q3 | q1 | q0
For example, reading a after ab or abb leaves suffix a, while reading b after abb leaves no nonempty suffix that begins abb. This invariant proves that q3 is reached at end exactly for strings ending in abb. All transitions are defined and exactly four states are used.

Original paper, page 10

1 mark · MCQ
Report issue

Regularity of two unary-block languages

Regular Expressions & Languages

Question 1.4, GATE 2001: Assess regularity of L1={0^(2n):n≥1} and L2={0^m1^n0^(m+n):m,n≥1}. Choices A/B/C/D assert only L1, only L2, both, or neither is regular.
Tap to enlarge
Your answer
Answer & solution

Answer: A (no official key was published)

Step 1: S1 contains positive even-length strings of zeros, described by regular expression 00(00)*, so it is regular.

Step 2: Suppose S2 were regular with pumping length p. Choose 0p1p02p. Any pumping segment in the first p symbols consists of k≥1 initial zeros. Pumping it out changes the first zero-block length to p−k while leaving the final zero block length 2p. That final block no longer equals the sum(p−k)+p. This contradicts the pumping lemma.

Therefore S2 is not regular and only S1 is correct, A.

Original paper, page 1

1 mark · MCQ
Report issue

Closure properties of context-free languages

Closure Properties & Language Hierarchy

Question 1.5, GATE 2001: Which statement about context-free languages is true: every CFL has a deterministic PDA; CFLs are closed under union; CFLs are closed under intersection; or CFLs are closed under complement?
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

Step 1: Given grammars with disjoint renamed nonterminals and start symbols S1,S2, introduce a fresh start S→S1|S2. This grammar generates their union, proving B.

Step 2: The CFLs {an bn cm} and {am bn cn} have intersection{an bn cn}, which is not context-free. Thus C is false. If CFLs were closed under complement, their union closure and De Morgan would imply intersection closure, so D also fails.

Finally deterministic PDA languages form a strict subclass of CFLs; an arbitrary CFL need not have a deterministic PDA. Hence A is false.

Original paper, page 1

1 mark · MCQ
Report issue

Worst-case NFA to DFA state blowup

Finite Automata

Question 1.6, GATE 2001: For an N-state NFA, determine the maximum possible size of an equivalent minimized DFA. Listed expressions are N², 2^N, 2N, and N!. The reproduced wording uses “maximum … at least”; distinguish worst-case size from the size for every individual NFA.
Tap to enlarge
Your answer
Answer & solution

Answer: B for the tight worst-case bound (no official key was published)

Step 1: Subset construction represents a DFA state by a subset of the N NFA states. There are at most 2N such subsets, and minimization cannot increase that number.

Step 2: This bound can be attained when the alphabet is unrestricted. Start at q0, make q0 accepting, and include symbols that map q0 to each chosen subset S. Include test symbols bi that map only qi to q0 and all other states to the empty set. Every subset is reachable, and bi distinguishes two subsets that differ in whether they contain qi. Thus all 2N subsets are inequivalent.

Conclusion: The maximum over N-state NFAs is 2N, B. This is not a claim that every particular NFA requires 2N states. The source phrase “maximum … at least” is imprecise; the tight worst-case reading is used.

Original paper, page 1

2 marks · MCQ
Report issue

DFA tracking two independent modular counts

Finite Automata

Question 2.5, GATE 2001: Find the minimum DFA size over {a,b} accepting exactly strings whose a-count is divisible by 6 and b-count by 8. Options: 8,14,15,48.
Question 2.5, GATE 2001: Find the minimum DFA size over {a,b} accepting exactly strings whose a-count is divisible by 6 and b-count by 8. Options: 8,14,15,48.
Tap to enlarge
Your answer
Answer & solution

Answer: D (no official key was published)

Step 1: Store a pair(i,j), where i is the number of a symbols modulo 6 and j the number of b symbols modulo 8. Reading a increments only i; reading b increments only j. Accept(0,0). This constructs 6·8=48 states.

Step 2: Every pair is reached by ai bj. For two distinct pairs, append a number of a and b symbols that brings the first pair to(0,0). The second pair retains a nonzero difference in at least one residue and rejects. Thus all pairs are distinguishable.

The construction is minimal, giving 48, D, not the sum 6+8.

Original paper, page 4

2 marks · MCQ
Report issue

Regularity of copying, reversal and unary lengths

Regular Expressions & Languages

Question 2.6, GATE 2001: Which languages are regular? L1={ww:w∈{a,b}*}; L2={ww^R:w∈{a,b}*}; L3={0^(2i)}; L4={0^(i²)}, interpreting valid nonnegative lengths. Choices: L1/L2; L2/L3/L4; L3/L4; only L3.
Tap to enlarge
Your answer
Answer & solution

Answer: D (no official key was published)

Step 1: L3 contains even-length unary strings, recognized by a two-state parity machine. Interpreting only nonnegative string lengths, negative integer parameters do not add new words.

Step 2: L1={ww} is nonregular: prefixes an b are pairwise distinguishable, since suffix an b makes a square with that prefix but not with am b for m≠n. L2={wwR} is nonregular: prefixes an b are distinguished by suffix b an; the resulting word am bb an is an even palindrome exactly when m=n.

Step 3: L4 has square unary lengths. For pumping length p, pump a nonempty segment of length k≤p in 0p². Pumping once more gives length p²+k strictly between consecutive squares p² and(p+1)², contradiction.

Therefore only L3 is regular, D.

Original paper, page 4

2 marks · MCQ
Report issue

Whether a computation visits a designated state

Decidability & Computability

Question 2.7, GATE 2001: Given a Turing machine M, input w, and state q, ask whether M’s computation on w ever visits q. Is this decidable, undecidable but partially decidable, not even partially decidable, or not a decision problem?
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

Step 1: Simulate M on w and accept as soon as q is visited. Every yes instance is eventually accepted; a no instance may run forever. This proves partial decidability.

Step 2: Reduce the halting problem: construct a simulator that enters a fresh designated state q exactly when the simulated machine halts. A decider for state visitation would decide halting, impossible.

Hence X is undecidable but partially decidable, B. It is a decision problem because the required answer is yes/no, regardless of whether an algorithm always produces that answer.

Original paper, page 4

Descriptive
Report issue

DFA detecting substring baab

Finite Automata

Question 5(a), GATE 2001: Alphabet {a,b}; accept precisely strings containing baab as a contiguous substring.

Task: Construct a DFA for this language.
Question 5(a), GATE 2001: Alphabet {a,b}; accept precisely strings containing baab as a contiguous substring.

Task: Construct a DFA for this language.
Tap to enlarge
Shared context

Alphabet {a,b}; accept precisely strings containing baab as a contiguous substring.

Answer & solution

Answer: Start q0; accepting q4. Transitions on (a,b): q0→(q0,q1), q1→(q2,q1), q2→(q3,q1), q3→(q0,q4), q4→(q4,q4). (no official key was published)

Step through it (2 parts)

1. Use states to remember the longest suffix of the input read so far that is also a prefix of baab: q0 remembers ε, q1 remembers b, q2 remembers ba, and q3 remembers baa. q4 means the complete substring has already occurred.

2. From q0, a contributes no matching prefix and b starts one: δ(q0,a)=q0, δ(q0,b)=q1. From q1, a extends b to ba, while another b starts a fresh b: δ(q1,a)=q2, δ(q1,b)=q1.

3. From q2, a extends ba to baa; b leaves the suffix b. Thus δ(q2,a)=q3, δ(q2,b)=q1. From q3, b completes baab and a destroys every nonempty matching suffix: δ(q3,b)=q4, δ(q3,a)=q0.

4. Both transitions from q4 loop to q4, since later symbols cannot remove an occurrence already seen. Set start q0 and accepting set {q4}. The trace baab is q0→q1→q2→q3→q4; baa alone ends in nonaccepting q3.

Original paper, page 7

Descriptive
Report issue

DFA for odd counts of both letters

Finite Automata

Question 5(b), GATE 2001: Alphabet {a,b}; accept strings with an odd number of a symbols and an odd number of b symbols.

Task: Construct a DFA for this language.
Question 5(b), GATE 2001: Alphabet {a,b}; accept strings with an odd number of a symbols and an odd number of b symbols.

Task: Construct a DFA for this language.
Tap to enlarge
Shared context

Alphabet {a,b}; accept strings with an odd number of a symbols and an odd number of b symbols.

Answer & solution

Answer: Four parity states EE, OE, EO, OO; start EE, sole accepting OO. a toggles first component, b toggles second. (no official key was published)

Step through it (2 parts)

1. Only the two parities matter, so use states (parity of a count, parity of b count). The empty string has counts zero and zero, making EE the start state.

2. Reading a increments only the a count and toggles its parity. Reading b toggles only the b parity. Complete transition table on (a,b): EE→(OE,EO); OE→(EE,OO); EO→(OO,EE); OO→(EO,OE).

3. Mark only OO accepting. By induction on the processed prefix, the stored pair equals its two actual count parities: the base is EE and every transition applies the correct single parity toggle.

4. Therefore a string is accepted exactly when both counts are odd. For instance ab ends in OO, whereas aab ends in EO and is rejected.

Original paper, page 7

Descriptive
Report issue

Deterministic PDA for aⁿcb²ⁿ

Pushdown Automata

Question 6, GATE 2001: L={aⁿcb²ⁿ | n≥1}, alphabet {a,b,c}; specify accepting state.

Task: Construct a deterministic PDA and specify its accepting state.
Tap to enlarge
Shared context

L={aⁿcb²ⁿ | n≥1}, alphabet {a,b,c}; specify accepting state.

Answer & solution

Answer: Push two X markers per a, consume one per b after c, accept only on exhaustion of markers and input. (no official key was published)

1. Use stack alphabet {Z,X} with bottom marker Z, and states q0 (start), qA (a phase), qB (b phase), qF (sole accepting state). Stack top is written at the left. A transition (q,s,T)→(p,γ) consumes s and replaces top T by γ.

2. Define δ(q0,a,Z)=(qA,XXZ); δ(qA,a,X)=(qA,XXX); δ(qA,c,X)=(qB,X); δ(qB,b,X)=(qB,ε); δ(qB,ε,Z)=(qF,Z). All unspecified transitions reject. Accept by final state only after all input is consumed.

3. The first a is required to leave q0, enforcing n≥1. Each subsequent a replaces one X with three, a net push of two; after n a symbols there are exactly 2n markers. The unique c switches irreversibly to qB.

4. Each b pops one X. Exactly 2n b symbols expose Z, allowing the ε-move to qF. Too few leave the PDA nonaccepting; extra input cannot be consumed from qF. Wrong symbol order has no transition.

5. Determinism holds because qB has a b transition only with top X and an ε-transition only with top Z; no fixed state/top pair offers both an ε-transition and an input transition.

Original paper, page 7

Descriptive
Report issue

Undecidability of nonhalting

Decidability & Computability

Question 7(a), GATE 2001: X asks whether a Turing machine M loops forever on input w. The halting problem H is assumed undecidable but partially decidable.

Task: Prove that X is undecidable.
Question 7(a), GATE 2001: X asks whether a Turing machine M loops forever on input w. The halting problem H is assumed undecidable but partially decidable.

Task: Prove that X is undecidable.
Question 7(a), GATE 2001: X asks whether a Turing machine M loops forever on input w. The halting problem H is assumed undecidable but partially decidable.

Task: Prove that X is undecidable.
Tap to enlarge
Shared context

X asks whether a Turing machine M loops forever on input w. The halting problem H is assumed undecidable but partially decidable.

Answer & solution

Answer: X is undecidable. (no official key was published)

1. For a fixed valid encoding ⟨M,w⟩, exactly one possibility holds: M halts on w, or it runs forever. Thus X is the complement of H on valid encodings.

2. Assume a decider D for X exists. A decider always terminates and correctly answers both yes and no instances.

3. Construct a halting decider by running D on ⟨M,w⟩ and reversing its answer. If D says loops forever, answer does not halt; if D says does not loop forever, answer halts.

4. This new algorithm terminates on every input because D does, contradicting the assumed undecidability of H. Therefore no such D exists. Mere simulation does not refute this result: observing a halt is possible, but waiting forever is not a terminating negative test.

Original paper, page 7

Descriptive
Report issue

Nonrecognizability of nonhalting

Decidability & Computability

Question 7(b), GATE 2001: X asks whether a Turing machine M loops forever on input w. The halting problem H is assumed undecidable but partially decidable.

Task: Prove that X is not even partially decidable.
Question 7(b), GATE 2001: X asks whether a Turing machine M loops forever on input w. The halting problem H is assumed undecidable but partially decidable.

Task: Prove that X is not even partially decidable.
Question 7(b), GATE 2001: X asks whether a Turing machine M loops forever on input w. The halting problem H is assumed undecidable but partially decidable.

Task: Prove that X is not even partially decidable.
Tap to enlarge
Shared context

X asks whether a Turing machine M loops forever on input w. The halting problem H is assumed undecidable but partially decidable.

Answer & solution

Answer: X is not partially decidable (not recursively enumerable). (no official key was published)

1. Partial decidability means a recognizer must halt and accept every yes instance, but may run forever on no instances. Let R_H be the given recognizer for halting, and suppose a recognizer R_X for nonhalting also exists.

2. On the same encoding ⟨M,w⟩, dovetail the two recognizers: execute one step of R_H, then one step of R_X, repeatedly. Do not run either one to completion before starting the other.

3. If R_H accepts, answer halts; if R_X accepts, answer does not halt. Since H and X partition valid machine-input pairs, precisely the appropriate recognizer is guaranteed eventually to accept.

4. The combined computation therefore always terminates with a correct answer, deciding H. This contradicts undecidability. Hence X is not even partially decidable, although its complement H is.

Original paper, page 7

1 mark · MCQ
Report issue

Equivalent starred regular expressions

Regular Expressions & Languages

Question 1.4, GATE 2000: Let S=(a+b*)* and T=(a+b)* over {a,b}. Are S and T in a proper-subset relation, equal, or disjoint?
Question 1.4, GATE 2000: Let S=(a+b*)* and T=(a+b)* over {a,b}. Are S and T in a proper-subset relation, equal, or disjoint?
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

Step 1: Every block allowed inside S is either a or a finite run of b symbols. Concatenating such blocks can produce every word over {a,b}, since individual a and b symbols are both available.

Step 2: No other symbol can appear, so S⊆{a,b}*. The expression T also generates exactly {a,b}*, including ε.

Hence S=T, option C. The inner star on b does not restrict the outer star’s ability to concatenate individual symbols.

Original paper, page 1

1 mark · MCQ
Report issue

Language generated by symmetric zero insertion

Context-Free Grammars & Languages

Question 1.5, GATE 2000: For grammar S→0S0|00, decide whether L is 0+, regular but not 0+, context-free but not regular, or not context-free.
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

Step 1: The base production yields two zeros. Each use of 0S0 adds exactly two more, so every generated word has positive even length. Conversely, applying the recursive rule k times generates 02k+2.

Step 2: Therefore L={02m:m≥1}=00(00)*, a regular language. It excludes the one-symbol string 0, which belongs to 0+.

Thus B. A recursive-looking grammar does not imply a nonregular language.

Original paper, page 1

2 marks · MCQ
Report issue

What a two-state unary DFA need not imply

Finite Automata

Question 2.8, GATE 2000: A unary regular language has a minimal two-state automaton. Must it be the odd-length language,the even-length language,a*,or one of the two parity languages?
Tap to enlarge
Your answer
Answer & solution

Answer: No listed conclusion follows without an additional restriction (no official key was published)

Step 1: Consider L=a+, the nonempty unary strings. A minimal complete DFA has a nonaccepting start state that transitions on a to an accepting state with an a self-loop. The two states are distinguishable by ε.

Step 2: This L contains both odd and positive even lengths but excludes ε, so it is neither parity language nor a*. It satisfies the two-state premise and refutes all four mandatory claims.

If the two reachable states were additionally required to form a cycle, exactly one would accept in a minimal two-state DFA, yielding parity and option D. The source does not state that restriction. Strong connectivity cannot be assumed from minimality.

Original paper, page 4

2 marks · MCQ
Report issue

Decidability of finite-state membership and CFG infiniteness

Decidability & Computability

Question 2.9, GATE 2000: Decide whether P1,finite-state-machine acceptance of a given string,and P2,infiniteness of a CFG language,are decidable. Options: both,neither,only P1,only P2.
Tap to enlarge
Your answer
Answer & solution

Answer: A (no official key was published)

Step 1: For P1, simulate the finite automaton on the finite input, tracking a set of states if it is nondeterministic, then inspect acceptance. This always terminates.

Step 2: For P2, convert the productive nonempty-word portion of the grammar to Chomsky normal form with m variables. Any parse tree without a repeated variable along a root-to-leaf path has bounded height and hence bounded word length. A sufficiently long word forces a repeat and pumping to infinitely many lengths.

One can effectively test whether the CFG generates a word exceeding that finite bound by intersection with the regular language of longer words and then CFG emptiness. Hence infiniteness is decidable too, giving A.

Original paper, page 4

Descriptive
Report issue

Minimal automaton for alternating bits

Finite Automata

Question 7(a), GATE 2000: Alphabet {0,1}; accept exactly the strings containing neither 00 nor 11 as a substring.

Task: Construct a minimal finite-state machine.
Question 7(a), GATE 2000: Alphabet {0,1}; accept exactly the strings containing neither 00 nor 11 as a substring.

Task: Construct a minimal finite-state machine.
Tap to enlarge
Shared context

Alphabet {0,1}; accept exactly the strings containing neither 00 nor 11 as a substring.

Answer & solution

Answer: Complete minimal DFA has four states: start, last-0, last-1, dead. (no official key was published)

1. Use states s (no symbol yet), z (valid prefix ending 0), o (valid prefix ending 1), and d (a forbidden equal adjacent pair has occurred). Start at s; accepting states are s,z,o, so ε is accepted.

2. Complete transition table, entries in input order 0,1: s→(z,o); z→(d,o); o→(z,d); d→(d,d). This is also a complete text specification of the requested machine.

3. Induction on the processed prefix proves the state invariant. Alternating bits move between z and o; a repeated bit enters d permanently. Thus precisely the required language is recognized.

4. All four states are reachable using ε,0,1,00. Dead d is distinguished from every accepting state by suffix ε. States s and z are distinguished by suffix 0, s and o by suffix 1, and z and o by suffix 0. Therefore no pair can merge and four states are minimal for a complete DFA. A partial drawing may omit the explicit dead state, but that is not a three-state complete DFA.

Original paper, page 7

Descriptive
Report issue

Exponents generated by a recursive grammar

Context-Free Grammars & Languages

Question 7(b), GATE 2000: Grammar S→aSAb | ε and A→bA | ε, with start S, generates strings aⁱbʲ, i,j≥0.

Task: Determine the exact condition on i,j.
Question 7(b), GATE 2000: Grammar S→aSAb | ε and A→bA | ε, with start S, generates strings aⁱbʲ, i,j≥0.

Task: Determine the exact condition on i,j.
Tap to enlarge
Shared context

Grammar S→aSAb | ε and A→bA | ε, with start S, generates strings aⁱbʲ, i,j≥0.

Answer & solution

Answer: (i,j)=(0,0), or i≥1 and j≥i. (no official key was published)

1. Every application of S→aSAb adds one a at the front and one mandatory b at the end, with an A that can generate any additional number of b symbols.

2. After i recursive applications and S→ε, the form is aⁱ(Ab)ⁱ. Thus j=i+k₁+⋯+kᵢ for arbitrary nonnegative integers k₁,…,kᵢ.

3. If i≥1, this gives j≥i. Every such j is attainable by assigning j−i extra b symbols to one A and zero to all the others.

4. If i=0, S goes directly to ε and there are no A symbols, so j must also be zero. The looser answer j≥i incorrectly includes nonempty strings consisting only of b.

Original paper, page 7

Descriptive
Report issue

Completing a reverse-matching PDA

Pushdown Automata

Question 8(a), GATE 2000: Two states q₀ (initial) and q₁. Existing edges: q₀→q₀ labeled 1,s/1s; q₀→q₁ labeled 2,s/s; q₁→q₁ labeled 1,1s/s. A label d,u/v consumes d and replaces entire stack u by v; s denotes the arbitrary remainder, top at left. Target L={x2xᴿ:x∈{0,1}*}.

Task: Add two appropriately labeled edges to accept L by empty stack.
Question 8(a), GATE 2000: Two states q₀ (initial) and q₁. Existing edges: q₀→q₀ labeled 1,s/1s; q₀→q₁ labeled 2,s/s; q₁→q₁ labeled 1,1s/s. A label d,u/v consumes d and replaces entire stack u by v; s denotes the arbitrary remainder, top at left. Target L={x2xᴿ:x∈{0,1}*}.

Task: Add two appropriately labeled edges to accept L by empty stack.
Question 8(a), GATE 2000: Two states q₀ (initial) and q₁. Existing edges: q₀→q₀ labeled 1,s/1s; q₀→q₁ labeled 2,s/s; q₁→q₁ labeled 1,1s/s. A label d,u/v consumes d and replaces entire stack u by v; s denotes the arbitrary remainder, top at left. Target L={x2xᴿ:x∈{0,1}*}.

Task: Add two appropriately labeled edges to accept L by empty stack.
Tap to enlarge
Shared context

Two states q₀ (initial) and q₁. Existing edges: q₀→q₀ labeled 1,s/1s; q₀→q₁ labeled 2,s/s; q₁→q₁ labeled 1,1s/s. A label d,u/v consumes d and replaces entire stack u by v; s denotes the arbitrary remainder, top at left. Target L={x2xᴿ:x∈{0,1}*}.

Answer & solution

Answer: Add q₀→q₀: 0,s/0s and q₁→q₁: 0,0s/s. Exact formal acceptance requires the caveat below. (no official key was published)

1. The missing push edge is a q₀ self-loop labeled 0,s/0s. The missing matching-pop edge is a q₁ self-loop labeled 0,0s/s. Together with the existing 1 loops these handle both symbols.

2. Before the delimiter, q₀ pushes every input symbol. The sole 2 edge enters q₁ without changing the stack. After it, each input bit must match the top bit and pops it; mismatches have no move.

3. For x=01, the successive configurations are (q₀,01210,ε)→(q₀,1210,0)→(q₀,210,10)→(q₁,10,10)→(q₁,0,0)→(q₁,ε,ε). Thus the intended accepting condition is exhausted input, empty stack, and completed delimiter transition into q₁.

4. Formal defect: under ordinary acceptance by empty stack in ANY state, an initially empty stack accepts ε immediately, although ε∉L. The two requested edges cannot undo this existing accepting run. An initial bottom marker does not alone solve it: none of the displayed or added transitions removes that marker.

5. To formalize the intended construction, require q₁ together with empty stack at input end; alternatively start with bottom marker Z and additionally permit q₁→q₁ labeled ε,Z/ε. The latter is a third added edge and therefore exceeds the literal two-edge request. We report the intended pair without claiming it repairs the original formal specification.

Original paper, page 7

Descriptive
Report issue

Three-state PDA for bounded ratios

Pushdown Automata

Question 8(b), GATE 2000: Target L={0ⁿ1ᵐ:n≤m≤2n}, with n,m nonnegative. Use labels d,u/v to consume d and replace entire stack u by v; stack top is at left.

Task: Describe a nondeterministic three-state PDA accepting by empty stack.
Question 8(b), GATE 2000: Target L={0ⁿ1ᵐ:n≤m≤2n}, with n,m nonnegative. Use labels d,u/v to consume d and replace entire stack u by v; stack top is at left.

Task: Describe a nondeterministic three-state PDA accepting by empty stack.
Question 8(b), GATE 2000: Target L={0ⁿ1ᵐ:n≤m≤2n}, with n,m nonnegative. Use labels d,u/v to consume d and replace entire stack u by v; stack top is at left.

Task: Describe a nondeterministic three-state PDA accepting by empty stack.
Tap to enlarge
Shared context

Target L={0ⁿ1ᵐ:n≤m≤2n}, with n,m nonnegative. Use labels d,u/v to consume d and replace entire stack u by v; stack top is at left.

Answer & solution

Answer: Push one X per 0; nondeterministically consume either one or two 1s per X using three states. (no official key was published)

1. Use states p (initial zero-reading phase), q (one-reading phase), r (one more 1 required for the current X). Start with empty stack. Edges: p→p: 0,s/Xs; p→q: ε,s/s; q→q: 1,Xs/s; q→r: 1,Xs/Xs; r→q: 1,Xs/s. There are no other edges. Accept only when all input is consumed and the stack is empty, in any state.

2. The zero phase pushes n copies of X. After the ε transition to q, no transition reads a zero, so every accepted word has form 0ⁿ1ᵐ.

3. For each X, q may consume one 1 and pop immediately, or consume one 1 without popping, enter r, and require a second 1 to pop and return to q. State r cannot have an empty stack because its entry edge requires and retains an X.

4. If k of the n markers use the two-symbol option, total ones are m=n+k with 0≤k≤n. Conversely any m in [n,2n] is realized by selecting k=m−n markers for that option.

5. The empty word is correctly accepted for n=m=0. A nonempty all-zero word leaves markers, a leading 1 has no applicable pop, and extra 1s cannot be read after the last marker disappears. This verifies the boundary cases without a bottom-marker convention.

Original paper, page 7

1 mark · MCQ
Report issue

DFA for a fixed binary length

Finite Automata

Question 1.4, GATE 1999: For the regular expression consisting of n concatenated factors (0+1), find the minimum finite-automaton states; choice C is n+2 and B is n+1.
Tap to enlarge
Your answer
Answer & solution

Answer: C for a complete DFA (no official key was published)

The language contains exactly the binary strings of length n. Use states 0 through n to record how many symbols have been read and a dead state for lengths above n. State n alone accepts; both symbols advance the count, and the dead state loops. This constructs n+2 states. For i<j≤n, a suffix of length n−j accepts from j but not i, so all progress states are distinguishable. The dead state is distinguishable from each by an appropriate accepting suffix. A partial automaton or NFA could omit that state and use n+1, giving B. The source says finite automaton without explicitly saying complete deterministic; C uses that conventional interpretation, rather than a universal minimum across all automaton models.

Original paper, page 1

1 mark · MCQ
Report issue

Context-free closure properties

Closure Properties & Language Hierarchy

Question 1.5, GATE 1999: Which pair of operations preserves context-free languages: intersection/complement, union/Kleene star, or the other listed pairs?
Question 1.5, GATE 1999: Which pair of operations preserves context-free languages: intersection/complement, union/Kleene star, or the other listed pairs?
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

For union, introduce a fresh start symbol with alternatives leading to the two original start symbols. For Kleene star, introduce S→S_old S|ε, producing any finite concatenation of words from the original language. Thus union and star preserve context-freeness. Intersection does not: {ai bi cj} intersected with {ai bj cj} gives {an bn cn}. Closure under complement together with union would imply intersection closure by De Morgan, so complement closure also fails. Hence B.

Original paper, page 1

1 mark · MCQ
Report issue

Two PDA acceptance conventions

Pushdown Automata

Question 1.6, GATE 1999: Compare languages accepted by final state and by empty stack: equal classes, one proper inclusion, or incomparable?
Tap to enlarge
Your answer
Answer & solution

Answer: A for nondeterministic PDAs (no official key was published)

An empty-stack PDA can be turned into a final-state PDA by adding a protected bottom marker and moving to an accepting state when the original stack empties. Conversely, a final-state PDA can nondeterministically enter a stack-draining phase after reaching an accepting state; acceptance still requires consuming the whole input. These constructions preserve the recognized language and show equal classes, A. The statement is for unrestricted nondeterministic PDAs. Deterministic acceptance conventions have additional restrictions and cannot be substituted without qualification.

Original paper, page 1

2 marks · MSQ
Report issue

False context-free closure claims

Closure Properties & Language Hierarchy

Question 2.4, GATE 1999: L1 is context-free and L2 regular. Which claims are false in general: A L1−L2 is not context-free; B L1∩L2 is context-free; C complement L1 is context-free; D complement L2 is regular?
Tap to enlarge
Select all that apply
Answer & solution

Answer: A,C (no official key was published)

Regular languages are closed under complement, and intersecting a CFL with a regular language preserves context-freeness using a PDA–DFA product. Thus L1−L2=L1∩complement(L2) is context-free, so A is false; B and D are true. CFLs are not closed under complement: otherwise their union closure plus De Morgan would imply intersection closure, contradicted by the standard an bn cn construction. Hence C is also false as a universal assertion. Some particular L1 do have context-free complements, so the conclusion is about closure, not every instance.

Original paper, page 3

2 marks · MSQ
Report issue

Restricting a language to terminating programs

Decidability & Computability

Question 2.5, GATE 1999: Which constructs should be excluded to make the language’s halting function programmable: choices include arbitrary goto(v),recursive calls(vii),and repeat loops(viii), together in B? Remaining constructs are assignment,bounded for,if,forward goto,and nonrecursive calls.
Question 2.5, GATE 1999: Which constructs should be excluded to make the language’s halting function programmable: choices include arbitrary goto(v),recursive calls(vii),and repeat loops(viii), together in B? Remaining constructs are assignment,bounded for,if,forward goto,and nonrecursive calls.
Tap to enlarge
Select all that apply
Answer & solution

Answer: B under the bounded-loop model (no official key was published)

Exclude arbitrary backward jumps, unrestricted recursion and unbounded repeat loops. The remaining for loops have fixed finite bounds whose control variable cannot be changed in the body; forward jumps cannot create cycles; and a finite acyclic nonrecursive call structure terminates. Structural induction on these constructs therefore proves every valid program halts. Its halting predicate is simply the constant true function, expressible in the language. This establishes the intended sufficient restriction B. The argument assumes finite evaluated bounds and ordinary bounded-for semantics, not changing loop limits or hidden nonterminating primitives.

Original paper, page 3

2 marks · Descriptive
Report issue

Regular union does not determine a summand

Closure Properties & Language Hierarchy

Question 6(a), GATE 1999: Given that language A is regular and A∪B is regular, must B be regular? Justify.
Question 6(a), GATE 1999: Given that language A is regular and A∪B is regular, must B be regular? Justify.
Tap to enlarge
Shared context

Given that language A is regular and A∪B is regular, must B be regular? Justify.

Answer & solution

Answer: No: take A={0,1}* and B={0ⁿ1ⁿ:n≥0}. (no official key was published)

Let the alphabet be {0,1}. Choose A={0,1}*, a regular language, and B={0ⁿ1ⁿ:n≥0}, which is not regular. Because B⊆A, the union A∪B equals A and is regular.

For completeness, B is nonregular by the pumping lemma: for pumping length p, any allowed pumped substring in 0ᵖ1ᵖ lies among the initial p zeros, and pumping it down changes the number of zeros without changing the p ones. The resulting word is not in B.

Closure under difference only proves (A∪B)\A=B\A is regular. It gives no control over the possibly nonregular part B∩A. This is precisely why reversing union closure fails.

Original paper, page 6

3 marks · Descriptive
Report issue

Decide strict inclusion of automaton languages

Finite Automata

Question 6(b), GATE 1999: Given finite automata M₁ and M₂, outline an algorithm to decide L(M₁)⊊L(M₂). The prose explicitly says strict subset even though a reproduced symbol permits equality.
Question 6(b), GATE 1999: Given finite automata M₁ and M₂, outline an algorithm to decide L(M₁)⊊L(M₂). The prose explicitly says strict subset even though a reproduced symbol permits equality.
Tap to enlarge
Shared context

Given finite automata M₁ and M₂, outline an algorithm to decide L(M₁)⊊L(M₂). The prose explicitly says strict subset even though a printed symbol permits equality.

Answer & solution

Answer: Require L(M₁)\L(M₂)=∅ and L(M₂)\L(M₁)≠∅. (no official key was published)

1. Put the automata over the same alphabet Σ, taking the union of their alphabets if needed. Determinize any NFAs and complete both resulting DFAs with sink states for missing transitions. This makes complementing acceptance correct.

2. Explore the product states (q₁,q₂) from the initial pair, with δ((q₁,q₂),a)=(δ₁(q₁,a),δ₂(q₂,a)). A reachable pair with q₁ accepting and q₂ rejecting witnesses a word in L(M₁)\L(M₂). If such a pair exists, answer NO.

3. Also look for a reachable pair with q₂ accepting and q₁ rejecting. If none exists, the languages are equal, so strict inclusion is false. If one exists while the first kind does not, answer YES.

4. Breadth-first or depth-first search suffices because a finite automaton language is nonempty exactly when an accepting state is reachable. On complete DFAs the search takes O(|Σ||Q₁||Q₂|) time; determinization can add exponential cost for NFA input. Both tests are necessary: ordinary inclusion alone incorrectly accepts equal languages.

Original paper, page 6

5 marks · Descriptive
Report issue

The marked copy language is not context-free

Context-Free Grammars & Languages

Question 7, GATE 1999: Prove L={xcx:x∈{0,1}*} is not context-free, where c is a terminal different from 0 and 1.
Tap to enlarge
Shared context

Prove L={xcx:x∈{0,1}*} is not context-free, where c is a terminal different from 0 and 1.

Answer & solution

Answer: A context-free pumping-lemma argument on 0ᵖ1ᵖc0ᵖ1ᵖ yields a contradiction. (no official key was published)

Suppose L were context-free and let p be its pumping length. Choose w=0ᵖ1ᵖc0ᵖ1ᵖ∈L. For any pumping decomposition w=uvxyz, the lemma requires |vxy|≤p, |vy|>0, and uvⁱxyⁱz∈L for every i≥0. We show pumping down (i=0) always fails.

If v or y contains c, removing v and y removes the unique separator. The result cannot be in L.

Otherwise c is not pumped. If vxy lies entirely on one side of c, pumping down shortens only that copy. The two sides have unequal lengths, so cannot be equal.

The remaining case is that vxy spans c, with c inside the unpumped substring x. Because |vxy|≤p, everything it can reach to the left of c is in the first block of ones, and everything to the right is in the second block of zeros: it cannot reach the first zeros or the final ones, each separated by a whole length-p block. Thus v=1ᵃ and y=0ᵇ, allowing a or b to be zero, but a+b>0. Pumping down leaves 0ᵖ1p−ac0p−b1ᵖ. Equality of the two copies would force both a=0 (compare ones) and b=0 (compare zeros), contrary to |vy|>0.

Every allowable decomposition fails the lemma, so L is not context-free. The argument relies on a genuine copy xc x, not the context-free reversed-copy language xc xᴿ.

Original paper, page 7

2 marks · Descriptive
Report issue

Termination of the diagonal function

Decidability & Computability

Question 10(a), GATE 1999: Assume a total, correct procedure HALTS(f,x) reports whether f(x) terminates. Define FUNNY(f)=IF HALTS(f,f) THEN NOT(f(f)) ELSE TRUE. Show FUNNY terminates for every f.
Question 10(a), GATE 1999: Assume a total, correct procedure HALTS(f,x) reports whether f(x) terminates. Define FUNNY(f)=IF HALTS(f,f) THEN NOT(f(f)) ELSE TRUE. Show FUNNY terminates for every f.
Tap to enlarge
Shared context

Assume a total, correct procedure HALTS(f,x) reports whether f(x) terminates. Define FUNNY(f)=IF HALTS(f,f) THEN NOT(f(f)) ELSE TRUE. Show FUNNY terminates for every f.

Answer & solution

Answer: Under the hypothetical HALTS assumption, both selected branches terminate. (no official key was published)

Interpret f as a program that can be supplied its own description as input; for the NOT expression restrict attention to programs returning Boolean values when they halt. This restricted class already suffices for the impossibility proof.

HALTS(f,f) terminates by the assumed totality of the decision procedure. If it returns FALSE, FUNNY immediately returns TRUE without running the nonterminating f(f). If it returns TRUE, its correctness guarantees that f(f) terminates. Evaluating that result and applying Boolean NOT therefore also terminates.

Thus for every such input program f, FUNNY(f) terminates and returns a Boolean. This is a conclusion conditional on the assumed existence of HALTS, not an independently implementable algorithm. Short-circuit branch selection is essential: the unselected branch must not evaluate f(f).

Original paper, page 7

3 marks · Descriptive
Report issue

Diagonal contradiction for a halting decider

Decidability & Computability

Question 10(b), GATE 1999: Assume a total, correct procedure HALTS(f,x) reports whether f(x) terminates. Define FUNNY(f)=IF HALTS(f,f) THEN NOT(f(f)) ELSE TRUE. Use termination of FUNNY to prove by contradiction that no such total correct HALTS exists.
Question 10(b), GATE 1999: Assume a total, correct procedure HALTS(f,x) reports whether f(x) terminates. Define FUNNY(f)=IF HALTS(f,f) THEN NOT(f(f)) ELSE TRUE. Use termination of FUNNY to prove by contradiction that no such total correct HALTS exists.
Question 10(b), GATE 1999: Assume a total, correct procedure HALTS(f,x) reports whether f(x) terminates. Define FUNNY(f)=IF HALTS(f,f) THEN NOT(f(f)) ELSE TRUE. Use termination of FUNNY to prove by contradiction that no such total correct HALTS exists.
Tap to enlarge
Shared context

Assume a total, correct procedure HALTS(f,x) reports whether f(x) terminates. Define FUNNY(f)=IF HALTS(f,f) THEN NOT(f(f)) ELSE TRUE. Use termination of FUNNY to prove by contradiction that no such total correct HALTS exists.

Answer & solution

Answer: FUNNY(FUNNY) would return the negation of its own Boolean result. (no official key was published)

Assume HALTS exists as a computable, always-terminating correct decision procedure. Then the definition constructs a computable FUNNY, and part (a) shows that FUNNY terminates on every program description, including its own. Consequently HALTS(FUNNY,FUNNY) must return TRUE.

Let b be the Boolean returned by FUNNY(FUNNY). Following its definition and the TRUE answer, the same call must return NOT(FUNNY(FUNNY)), namely NOT b. This implies b=NOT b. Neither Boolean value satisfies this equation: TRUE would have to be FALSE and FALSE would have to be TRUE.

There is also an operational view: the TRUE branch invokes the identical FUNNY(FUNNY) call again before it can negate the result, producing unending recursion, contradicting the termination guaranteed by part (a). Either explanation refutes the initial assumption. Therefore no algorithm decides halting for arbitrary programs and inputs. Assuming a function can accept its own encoded description is standard for general-purpose programs; restricting output to Booleans does not avoid the contradiction.

Original paper, page 7

1 mark · MCQ
Report issue

Equivalent regular-expression groupings

Regular Expressions & Languages

Question 1.9, GATE 1998: Compare A=(01+1)* and B=((01)*1*)*: proper inclusion, equality, or incomparable?
Tap to enlarge
Your answer
Answer & solution

Answer: D: equality (no official key was published)

Every block in B is a sequence of 01 blocks followed by a sequence of 1 symbols, all of which are permitted individual blocks of A. Thus B⊆A. Conversely B can produce an individual 01 by selecting one occurrence in (01)* and none in 1*, and can produce an individual 1 by the reverse choice. Its outer star concatenates any sequence of these, so A⊆B. Both include the empty string. Therefore A=B, D.

Original paper, page 1

1 mark · MCQ
Report issue

Recognizable numerical languages

Regular Expressions & Languages

Question 1.10, GATE 1998: Which is regular: powers of two written in binary, powers of two in unary, equal numbers of zeros and ones, or{1, 101, 11011, 1110111, …}?
Tap to enlarge
Your answer
Answer & solution

Answer: A (no official key was published)

Binary powers of two are exactly 10*, a regular expression, so a DFA recognizes A. Unary powers of two have gaps that keep increasing and are not ultimately periodic, as every unary regular language must be. Equal zero/one counts would yield nonregular 0n1n after intersection with 0*1*. The displayed final pattern requires matching runs of ones on either side of a zero and is likewise nonregular by pumping or distinguishable prefixes. Hence A under the evident continuation of that example list; an ellipsis itself is not a formal language definition.

Original paper, page 1

1 mark · MCQ
Report issue

Limits of nondeterminism

Other / Mixed Topics

Question 1.11, GATE 1998: Which GFG claim is false: NFA=DFA, NPDA=DPDA, NTM=DTM, multitape TM=single-tape TM in recognized languages?
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

Subset construction converts NFAs to DFAs. Turing-machine computation branches can be dovetailed, and tapes can be encoded on one tape, preserving recognized languages though not necessarily runtime. But deterministic PDAs recognize a proper subclass of CFLs: nondeterminism genuinely adds recognition power there. Thus the the paper false statement is B. That source error is disclosed rather than using its letters interchangeably.

Original paper, page 2

1 mark · MCQ
Report issue

Testing a word against four regexes

Regular Expressions & Languages

Question 1.12, GATE 1998: Which does not contain 1101: A 110*(0+1), B1(0+1)*101, C(10)*(01)*(00+11)*, D(00+(11)*0)*?
Tap to enlarge
Your answer
Answer & solution

Answer: C, D (no official key was published)

A accepts 1101 using one zero in 0* and final 1. B accepts it with an empty middle star:1·101. For C, the initial 10 block cannot be used because the word starts 11; neither can the next 01 block. The remaining (00+11)* cannot partition 1101 into equal-symbol pairs because its last pair is 01. Thus C rejects. Every nonempty block of D ends in 0, so every nonempty word of D ends in 0;1101 ends in 1 and is rejected too. The paper shows these expressions. A single-answer instruction therefore conflicts with the two rejecting choices.

Original paper, page 2

2 marks · MCQ
Report issue

Minimum DFA remembering equal final bits

Finite Automata

Question 2.5, GATE 1998: Over{0, 1}, accept exactly words whose last two symbols are equal. Find minimum states among 2, 5, 8, 3.
Tap to enlarge
Your answer
Answer & solution

Answer: B: 5 (no official key was published)

Step through it (2 parts)

Use five states: start S; nonaccepting q0 for a last 0 without an equal final pair; nonaccepting q1 analogously; accepting a 0 for suffix 00; accepting a 1 for suffix 11. On0, S→q0, q0/a 0→a 0, q1/a 1→q0. On1 use the symmetric transitions. To prove minimality, accepting versus nonaccepting states differ on ε. a 0 and a 1 differ on suffix 0; q0 and q1 differ on 0; S differs from q0 on 0 and from q1 on 1. All five are reachable, so no merging is possible. Therefore B.

Original paper, page 4

2 marks · MCQ
Report issue

False regular-language subset claim

Regular Expressions & Languages

Question 2.6, GATE 1998: Which is false: finite subsets of nonregular languages are regular; every subset of a regular language is regular; finite subsets of regular languages are regular; intersection preserves regularity?
Question 2.6, GATE 1998: Which is false: finite subsets of nonregular languages are regular; every subset of a regular language is regular; finite subsets of regular languages are regular; intersection preserves regularity?
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

Every finite language is regular: form a finite union of its individual words. Thus A and C hold regardless of the larger language. Regular languages are closed under intersection using a product DFA, so D holds. But the regular language{0, 1}* contains the nonregular subset{0n1n:n≥0}. Hence arbitrary subsets need not be regular, disproving B. Finite-subset closure must not be extrapolated to unrestricted infinite subsets.

Original paper, page 4

Descriptive
Report issue

Regular expression for constrained zeros

Regular Expressions & Languages

Question 3(b), GATE 1998: Give a regular expression for binary strings in which every 0 is immediately followed by exactly k consecutive 1s and preceded by at least k consecutive 1s, for fixed nonnegative integer k.
Question 3(b), GATE 1998: Give a regular expression for binary strings in which every 0 is immediately followed by exactly k consecutive 1s and preceded by at least k consecutive 1s, for fixed nonnegative integer k.
Tap to enlarge
Answer & solution

Answer: 1* ∪ 1^k 1* 0 1^k (0 1^k)*. (no official key was published)

Interpret “exactly k” as the length of the entire run of consecutive 1s immediately after a 0. Write 1k for k copies of the symbol 1, not a variable exponent inside the regex. One expression is

1* ∪ 1k 1* 0 1k (0 1k)*.

The first branch handles strings with no zeros, including ε. Their condition is vacuously true; they must not be discarded merely because they contain fewer than k ones. In the second branch, the initial run 1k1* has at least k ones, so the first zero has the required predecessor run. Every zero then contributes the block 01k. Repeating that block gives exactly k ones between consecutive zeros, simultaneously satisfying the preceding and following requirements. The last zero is also followed by exactly k ones, with no extra trailing ones.

Conversely, any valid string containing a zero has an initial run of at least k ones. After its first zero, each run of ones has length exactly k, until the string ends or the next zero begins. It therefore has the displayed form. For k=2, 11011 and 111011011 are accepted, whereas 1011 lacks enough leading ones and 110111 has too many final ones. For k=0 the formula reduces to 1*0*: no one may occur after the first zero. If “followed by k ones” meant at least k rather than exactly k, a different language would result.

Original paper, page 5

Descriptive
Report issue

Minimal DFA for multiples of five

Finite Automata

Question 4, GATE 1998: Design a minimum-state DFA for binary strings whose numeric value, ignoring leading zeros, is divisible by five.
Tap to enlarge
Answer & solution

Answer: Five remainder states if ε represents 0; six if an empty representation is excluded. (no official key was published)

Maintain the remainder r of the binary prefix modulo 5. Appending bit b changes a value v into 2v+b, so the transition is δ(qr,b)=q_((2r+b) mod 5). The start and sole accepting state is q0, using the conventional value 0 for ε.

State     input 0   input 1
q0        q0        q1
q1        q2        q3
q2        q4        q0
q3        q1        q2
q4        q3        q4

This transition table fully specifies the DFA. Leading zeros loop at q0, and zero is divisible by five. Induction on prefix length proves the invariant that state qr means the prefix value is congruent to r. Consequently the final state is accepting exactly for multiples of five.

For minimality, all five states are reachable: ε, 1, 10, 11 and 100 reach q0 through q4. Given distinct remainders r and s, choose v in {0,1,2,3,4} with 8r+v≡0 mod 5 and append its three-bit binary representation, including leading zeros. From qr the result is accepting. From qs its remainder differs by 8(s−r), which is nonzero modulo 5 because 8 is invertible modulo 5. Thus every pair is distinguishable, establishing a five-state lower bound.

The source says strings in {0,1}* but does not define the value of ε. If a binary numeral must contain at least one symbol, add a new nonaccepting start state s with 0→q0 and 1→q1. It is distinct from q0 by ε and from every other remainder state by the suffix argument, so this alternative language needs six states. The five-state answer uses the explicitly stated conventional interpretation.

Original paper, page 6

Descriptive
Report issue

Language of a PDA

Pushdown Automata

Question 13(a), GATE 1998: For the displayed PDA on states q0,q1, alphabet {0,1}, stack {Z0,X}, start (q0,Z0), and empty-store acceptance, determine its language. Common transitions: (q0,1,Z0)→(q0,XZ0), (q0,ε,Z0)→(q0,ε), (q0,1,X)→(q0,XX), (q1,1,X)→(q1,ε). GFG has (q0,0,Z0)→(q1,X) and (q1,0,Z0)→(q0,Z0); GateForum instead has (q0,0,X)→(q1,X) and (q0,0,Z0)→(q0,Z0).
Question 13(a), GATE 1998: For the displayed PDA on states q0,q1, alphabet {0,1}, stack {Z0,X}, start (q0,Z0), and empty-store acceptance, determine its language. Common transitions: (q0,1,Z0)→(q0,XZ0), (q0,ε,Z0)→(q0,ε), (q0,1,X)→(q0,XX), (q1,1,X)→(q1,ε). GFG has (q0,0,Z0)→(q1,X) and (q1,0,Z0)→(q0,Z0); GateForum instead has (q0,0,X)→(q1,X) and (q0,0,Z0)→(q0,Z0).
Tap to enlarge
Answer & solution

Answer: As printed: {ε, 01}. A plausible repaired PDA accepts (⋃_(n≥1)1^n01^n0)*. (no official key was published)

Empty-store acceptance requires both the entire input to be consumed and the stack to be empty. Merely reaching Z0, or emptying the stack while unread input remains, is not sufficient. The two printed transition sets differ materially, so there is no source-independent single language.

The paper literal version: at (q0,Z0), ε can pop Z0 and accept ε. Reading 0 uses its printed transition (q0,0,Z0)→(q1,X), replacing Z0 rather than preserving it. One subsequent 1 pops X and accepts 01 with an empty stack. No further input can then be consumed. Reading any 1 first puts X above Z0 in q0; that state can only push more X on further 1s, because the paper's zero transition tests Z0, not X. It can never enter its popping phase from such a stack. Thus L={ε,01}. The printed q1,0,Z0 return transition is unreachable from the start in this literal machine.

It cannot empty Z0. Hence no string containing a 1 is accepted and L_GF=0*.

It pushes n≥1 Xs on 1s, reads 0 to switch phase, pops n Xs on 1s, then reads another 0 to return to q0. It can repeat such blocks and finally pop Z0 by ε. Conditional on exactly those repairs, the language is (⋃_(n≥1){1^n01^n0})*. The choice n≥1 is necessary because no q0,0,Z0 transition remains in this repair. This reconstructed answer is useful but not verified as the original question; silently substituting it would conceal different literal answers.

Original paper, page 7

Descriptive
Report issue

Explain the PDA stack behavior

Pushdown Automata

Question 13(b), GATE 1998: For the displayed PDA on states q0,q1, alphabet {0,1}, stack {Z0,X}, start (q0,Z0), and empty-store acceptance, describe its operation informally. Common transitions: (q0,1,Z0)→(q0,XZ0), (q0,ε,Z0)→(q0,ε), (q0,1,X)→(q0,XX), (q1,1,X)→(q1,ε). GFG has (q0,0,Z0)→(q1,X) and (q1,0,Z0)→(q0,Z0); GateForum instead has (q0,0,X)→(q1,X) and (q0,0,Z0)→(q0,Z0).
Question 13(b), GATE 1998: For the displayed PDA on states q0,q1, alphabet {0,1}, stack {Z0,X}, start (q0,Z0), and empty-store acceptance, describe its operation informally. Common transitions: (q0,1,Z0)→(q0,XZ0), (q0,ε,Z0)→(q0,ε), (q0,1,X)→(q0,XX), (q1,1,X)→(q1,ε). GFG has (q0,0,Z0)→(q1,X) and (q1,0,Z0)→(q0,Z0); GateForum instead has (q0,0,X)→(q1,X) and (q0,0,Z0)→(q0,Z0).
Tap to enlarge
Answer & solution

Answer: See the solution below (no official key was published)

A transition (q,a,T)→(p,γ) consumes a when a≠ε, changes state to p, and replaces the top stack symbol T by γ. Take the leftmost stack symbol as the top. Thus replacing X by XX pushes one extra counter symbol, while replacing X by ε pops one.

In the plausible reconstruction specified in part (a), q0 is a counting-up phase and q1 a counting-down phase. Start with Z0. Each leading 1 pushes one X. A 0 with X on top switches q0→q1 without changing the stack. Each following 1 in q1 pops one X. Once only Z0 remains, another 0 returns to q0 without removing Z0. The machine may process another block in the same way. Only at q0 with top Z0 may ε remove the bottom marker, accepting if input is exhausted.

For reconstructed input 110110, the configurations (state, unread input, stack) are
(q0,110110,Z0)
→(q0,10110,XZ0)
→(q0,0110,XXZ0)
→(q1,110,XXZ0)
→(q1,10,XZ0)
→(q1,0,Z0)
→(q0,ε,Z0)
→(q0,ε,ε).

An extra 1 in the popping phase has no transition once Z0 is reached; too few 1s leave X on top when the closing 0 is encountered, also blocking the run. These restrictions enforce equal positive counts within every block. The four-phase explanation applies only to the explicitly repaired transition set, not literally to both printed versions.

Literal machine the special input 01 instead replaces Z0 by X on its first step, then pops X, so that machine accepts only ε and 01. These observations explain why the attractive counting-machine interpretation cannot be presented without disclosing the source repairs. All unspecified transitions are treated as absent, not guessed.

Original paper, page 7

Descriptive
Report issue

Language of an unequal-count grammar

Context-Free Grammars & Languages

Question 14(a), GATE 1998: Find L(G1) for S1→aS1b|aAb|aBb, A→aA|a, B→Bb|b.
Question 14(a), GATE 1998: Find L(G1) for S1→aS1b|aAb|aBb, A→aA|a, B→Bb|b.
Tap to enlarge
Answer & solution

Answer: {a^i b^j : i,j≥1 and i≠j}. (no official key was published)

A generates exactly ar with r≥1: each recursive step adds one a and the final A→a supplies the last. Similarly B generates exactly bs with s≥1. The left recursion in B changes derivation direction, not its generated language or uniqueness for a fixed length.

After t≥0 uses of S1→aS1b, choosing S1→aAb and A⇒ar produces at+r+1bt+1. Both exponents are positive and the number of a's exceeds the number of b's by r≥1. Choosing S1→aBb instead gives at+1bt+s+1, whose b-count exceeds its a-count by s≥1. These are the only terminating choices, so equality of the counts is impossible.

Conversely, for any i>j≥1, choose t=j−1 and r=i−j, yielding ai bj through the A branch. For j>i≥1, choose t=i−1 and s=j−i through the B branch. Therefore every positive unequal pair occurs, proving L(G1)={ai bj:i,j≥1,i≠j}.

This grammar is also unambiguous. The comparison between i and j forces the A or B branch; the smaller exponent forces t; the difference forces r or s. The unary A or B derivation of that length is unique. This fact will be useful when answering the inherent-ambiguity question, but does not need to be assumed to establish the language.

Original paper, page 7

Descriptive
Report issue

Extend the grammar in four rules

Context-Free Grammars & Languages

Question 14(b), GATE 1998: Using G1 from part (a), construct a CFG for L2={a^i b^j a^k b^l : i,j,k,l≥1 and (i=j or k=l)} by adding no more than five productions.
Question 14(b), GATE 1998: Using G1 from part (a), construct a CFG for L2={a^i b^j a^k b^l : i,j,k,l≥1 and (i=j or k=l)} by adding no more than five productions.
Question 14(b), GATE 1998: Using G1 from part (a), construct a CFG for L2={a^i b^j a^k b^l : i,j,k,l≥1 and (i=j or k=l)} by adding no more than five productions.
Tap to enlarge
Answer & solution

Answer: Add S2→TAB|S1T and T→aTb|ab, taking S2 as the new start symbol: four added alternatives. (no official key was published)

Keep every production of G1. Introduce new nonterminals S2 and T, take S2 as the new start symbol, and add exactly four individual productions:

S2 → TAB
S2 → S1T
T → aTb
T → ab

T generates precisely {an bn:n≥1}. Existing A and B generate a+ and b+, so AB generates all ak bl with k,l≥1. Consequently the first new start production TAB generates exactly the words with i=j and arbitrary positive k,l. The second production S1T generates exactly those with i≠j and k=l, because part (a) established the unequal-count language of S1.

These two cases together are equivalent to i=j or k=l. If the first equality holds, the first branch handles the word whether or not the second equality also holds. If the first equality fails, the language condition forces k=l, so the second branch handles it. Conversely every generated word satisfies one of those required equalities. Positive lengths of all four runs are guaranteed by T,A,B and S1.

The extension uses four alternatives, within the stated limit of five, even when each bar-separated alternative is counted separately. Reusing the unequal-count grammar is deliberate: the simpler-looking union “balanced first or balanced second” would have overlapping branches when both pairs are balanced. Here the two branches are disjoint, which also supplies a clean unambiguity proof for part (c).

Original paper, page 7

Descriptive
Report issue

Is the four-run language inherently ambiguous?

Context-Free Grammars & Languages

Question 14(c), GATE 1998: For L2={a^i b^j a^k b^l : i,j,k,l≥1 and (i=j or k=l)}, decide whether it is inherently ambiguous. Use the grammar extension from part (b) if helpful.
Question 14(c), GATE 1998: For L2={a^i b^j a^k b^l : i,j,k,l≥1 and (i=j or k=l)}, decide whether it is inherently ambiguous. Use the grammar extension from part (b) if helpful.
Question 14(c), GATE 1998: For L2={a^i b^j a^k b^l : i,j,k,l≥1 and (i=j or k=l)}, decide whether it is inherently ambiguous. Use the grammar extension from part (b) if helpful.
Question 14(c), GATE 1998: For L2={a^i b^j a^k b^l : i,j,k,l≥1 and (i=j or k=l)}, decide whether it is inherently ambiguous. Use the grammar extension from part (b) if helpful.
Tap to enlarge
Answer & solution

Answer: No. The four-rule extension gives an unambiguous CFG. (no official key was published)

A context-free language is inherently ambiguous only if every CFG generating it is ambiguous. It is therefore enough to exhibit and prove one unambiguous grammar. Use the extension from part (b): S2→TAB|S1T, T→aTb|ab, retaining the unambiguous unequal-count grammar G1.

Every word of L2 has four nonempty runs ai,bj,ak,bl. The boundaries between the runs are determined by changes of symbol, particularly the middle b-to-a change, so a derivation cannot shift the split between its two a*b* components.

If i=j, only S2→TAB can apply, since S1 generates unequal first counts. The exponent i fixes the unique derivation in T. The remaining exponents k and l fix the unique unary derivations in A and B. If i≠j, only S2→S1T can apply. Then membership requires k=l. Part (a)'s proof gives a unique derivation of ai bj in S1, and the common value k=l gives a unique derivation in T. Hence each word has exactly one parse tree.

Words satisfying both equalities still use only the first branch, so they do not create an intersection ambiguity. A different grammar with productions for “first pair equal” and “second pair equal” may generate those words twice, but ambiguity of one grammar does not establish inherent ambiguity of its language. This four-run language also should not be confused with classical three-run examples whose equality conditions share the middle count. The explicit disjoint grammar here proves that L2 is not inherently ambiguous.

Original paper, page 7

Descriptive
Report issue

Bounded identifier regex

Regular Expressions & Languages

Question 22(a), GATE 1998: An identifier has one through six letters/digits, with a letter first. Give a regular expression.
Question 22(a), GATE 1998: An identifier has one through six letters/digits, with a letter first. Give a regular expression.
Tap to enlarge
Answer & solution

Answer: L(ε|A|A²|A³|A⁴|A⁵), A=L∪D. (no official key was published)

Let L denote the finite union of permitted letters and D the union of decimal digits. Let A=L|D. The first character must be from L. It can be followed by zero through five alphanumeric characters, giving

L(ε | A | AA | AAA | AAAA | AAAAA).

With repetition shorthand this is L A{0,5}. The expanded expression above uses only ordinary regular-expression union, concatenation and ε; braces are not essential notation.

A one-letter identifier follows the ε branch; a six-character one follows AAAAA. No branch accepts an empty identifier or a first digit, and none permits a seventh character. Conversely any permitted identifier can be decomposed into its initial letter and its remaining zero to five alphanumeric symbols, so it is accepted. The actual letter alphabet, such as upper/lowercase distinctions, is a language-design input; underscores are not included because the question permits only letters and digits.

Original paper, page 8

1 mark · MCQ
Report issue

An uncountable collection of languages

Turing Machines

Question 3.4, GATE 1997: Over{a, b}, which is uncountable: all finite strings, all languages, regular languages, or Turing-recognizable languages?
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

Finite strings can be enumerated by length and lexicographic order, so Σ* is countably infinite. All languages form its power set P(Σ*), which is uncountable by Cantor’s theorem. In contrast, finite automata and Turing machines each have finite descriptions over a finite alphabet, so there are only countably many of either and hence only countably many languages they describe. Thus B. The distinction is between elements that are strings and arbitrary sets of those strings.

Original paper, page 3

2 marks · MCQ
Report issue

Regex avoiding100

Regular Expressions & Languages

Question 6.4, GATE 1997: Which regex describes binary strings with no substring 100? Choice D is 0*(10+1)*.
Tap to enlarge
Your answer
Answer & solution

Answer: D (no official key was published)

Any leading run of zeros is harmless and is covered by 0*. After the first 1, there cannot be two consecutive zeros, or the preceding 1 followed by those zeros would form 100. Thus the remaining word can be partitioned into blocks 1 and 10, covered by (1+10)*. Conversely, a word built this way has no pair of zeros after a 1, so it cannot contain 100. Hence 0*(10+1)* is exactly the desired language, D. It includes ε and all-zero strings, which also avoid the forbidden substring.

Original paper, page 5

2 marks · MCQ
Report issue

An undecidable machine problem

Decidability & Computability

Question 6.5, GATE 1997: Choose the undecidable task: bounded-step TM acceptance, TM language equivalence, DFA nonemptiness, CFG nonemptiness.
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

Given a step bound k, simulate the TM for at most k steps and answer, so A is decidable. DFA nonemptiness is reachability of an accepting state. CFG nonemptiness is found by marking variables that derive terminal strings until a fixed point. TM language equivalence is undecidable: if decidable, it could compare any TM with one recognizing the empty language and thereby decide TM language emptiness, an undecidable semantic property. Thus B. Bounded simulation differs crucially from unbounded acceptance.

Original paper, page 5

2 marks · MCQ
Report issue

Deterministic recognition with a middle marker

Pushdown Automata

Question 6.6, GATE 1997: Which language is deterministic context-free: {wcwR:w∈{a, b}*}, unmarked even palindromes over{a, b, c}, {a^n b^n c^n}, or all palindromes over{a, b, c}?
Question 6.6, GATE 1997: Which language is deterministic context-free: {wcwR:w∈{a, b}*}, unmarked even palindromes over{a, b, c}, {a^n b^n c^n}, or all palindromes over{a, b, c}?
Tap to enlarge
Your answer
Answer & solution

Answer: A (no official key was published)

For A, the symbol c uniquely marks the midpoint because w uses only a, b. A DPDA pushes symbols before c, then deterministically switches to popping and comparing symbols after c, accepting when they match exactly and input ends. Unmarked palindrome languages require finding an unspecified midpoint and are not deterministic context-free over a multi-symbol alphabet. The equal-three-block language is not even context-free. Hence A. The delimiter’s exclusion from w is essential; without it, the same deterministic switch is unavailable.

Original paper, page 5

3 marks · Descriptive
Report issue

Characterize a block grammar

Context-Free Grammars & Languages

Question 11(a), GATE 1997: Use the GFG grammar with start symbol S:
S → bSe | PQR
P → bPc | ε
Q → cQd | ε
R → dRe | ε.
Terminals are b,c,d,e. Generated words are b^i c^j d^k e^m with nonnegative integer exponents. GateForum instead prints S→bSc and mistakenly gives nonpositive exponents; those literal variants must be distinguished.
What condition on i,j,k,m characterizes the generated language?
Question 11(a), GATE 1997: Use the GFG grammar with start symbol S:
S → bSe | PQR
P → bPc | ε
Q → cQd | ε
R → dRe | ε.
Terminals are b,c,d,e. Generated words are b^i c^j d^k e^m with nonnegative integer exponents. GateForum instead prints S→bSc and mistakenly gives nonpositive exponents; those literal variants must be distinguished.
What condition on i,j,k,m characterizes the generated language?
Question 11(a), GATE 1997: Use the GFG grammar with start symbol S:
S → bSe | PQR
P → bPc | ε
Q → cQd | ε
R → dRe | ε.
Terminals are b,c,d,e. Generated words are b^i c^j d^k e^m with nonnegative integer exponents. GateForum instead prints S→bSc and mistakenly gives nonpositive exponents; those literal variants must be distinguished.
What condition on i,j,k,m characterizes the generated language?
Tap to enlarge
Answer & solution

Answer: i, j, k, m≥0 and i+k=j+m (no official key was published)

Let t be the number of uses of S→bSe before S→PQR. Let p,q,r be the numbers of recursive productions used by P,Q,R. Their contributions are P⇒bp cp, Q⇒cq dq and R⇒dr er. Combining them with the outer b/e pairs gives

i=t+p, j=p+q, k=q+r, m=r+t,
where t,p,q,r are nonnegative integers. Adding opposite equations yields the necessary relation i+k=j+m.

To prove sufficiency, assume all four exponents are nonnegative and i+k=j+m. Choose any integer t satisfying max(0,i−j)≤t≤min(i,m), and put p=i−t, q=j−i+t, r=m−t. These parameters are nonnegative and reproduce every exponent, including k=j−i+m. Such a t always exists: i−j≤m follows from k≥0, while i−j≤i follows from j≥0. Thus the equality, together with nonnegativity, is also sufficient.

Its full generated form is bt+pcp+qdq+rer ct, with a trailing block of c symbols after the d/e blocks. For example S⇒bSc⇒bPQRc⇒bcdc is possible, contradicting that the paper's claim that every generated word is in b*c*d*e*. Restricting to words of the claimed block form forces either t=0, or q=r=0 so no d/e lies before the final c. The t=0 case gives i=p,j=p+q,k=q+r,m=r, hence i+k=j+m and j≥i. The other case gives only bi ci, already included in that subset.

Taken literally as string exponents, only zero exponents are meaningful, leaving ε; the language intended by the grammar is not that singleton. This solution uses nonnegative counts, as explicitly printed, and discloses both source differences.

Original paper, page 7

2 marks · Descriptive
Report issue

Find the shortest ambiguous word

Context-Free Grammars & Languages

Question 11(b), GATE 1997: Use the GFG grammar with start symbol S:
S → bSe | PQR
P → bPc | ε
Q → cQd | ε
R → dRe | ε.
Terminals are b,c,d,e. Generated words are b^i c^j d^k e^m with nonnegative integer exponents. GateForum instead prints S→bSc and mistakenly gives nonpositive exponents; those literal variants must be distinguished.
Find a shortest word having two distinct parse trees.
Question 11(b), GATE 1997: Use the GFG grammar with start symbol S:
S → bSe | PQR
P → bPc | ε
Q → cQd | ε
R → dRe | ε.
Terminals are b,c,d,e. Generated words are b^i c^j d^k e^m with nonnegative integer exponents. GateForum instead prints S→bSc and mistakenly gives nonpositive exponents; those literal variants must be distinguished.
Find a shortest word having two distinct parse trees.
Question 11(b), GATE 1997: Use the GFG grammar with start symbol S:
S → bSe | PQR
P → bPc | ε
Q → cQd | ε
R → dRe | ε.
Terminals are b,c,d,e. Generated words are b^i c^j d^k e^m with nonnegative integer exponents. GateForum instead prints S→bSc and mistakenly gives nonpositive exponents; those literal variants must be distinguished.
Find a shortest word having two distinct parse trees.
Tap to enlarge
Answer & solution

Answer: bcde (length 4) (no official key was published)

Bcde has two different parses. The difference is whether the initial b and final e are supplied by the outer S rule or by P and R:

Parse 1: S⇒PQR, with P⇒bPc⇒bc, Q⇒ε, R⇒dRe⇒de. Concatenation gives bcde.
Parse 2: S⇒bSe⇒bPQRe, with P⇒ε, Q⇒cQd⇒cd, R⇒ε. This also gives bcde.

These are distinct parse trees because the first root uses S→PQR and the second root uses S→bSe. Merely changing the order of independent rewrites would not demonstrate ambiguity; here the production at the root really differs.

To prove shortestness, fix a word's exponents. Every parse is uniquely determined by t, the number of outer S→bSe applications, since p=i−t, q=j−i+t and r=m−t determine the unique chains in P,Q,R. Two parses require two possible t values. If consecutive valid choices are t and t+1, the lower choice has p≥1 and r≥1. Those two recursive chains alone contribute at least two b/c symbols and two d/e symbols, so the total length is at least four. The displayed word attains that bound.

Original paper, page 7

5 marks · Descriptive
Report issue

Minimum DFA for two divisibility conditions

Finite Automata

Question 20, GATE 1997: Construct a finite-state machine with the minimum number of states accepting exactly the strings over {a,b} whose number of a symbols is divisible by 2 and number of b symbols is divisible by 3.
Tap to enlarge
Answer & solution

Answer: Six-state DFA tracking (#a mod 2, #b mod 3); start and only accepting state q00. (no official key was published)

Step through it (2 parts)

The future acceptance of a prefix depends on two remainders, not on the order of its symbols. Let qij mean that the prefix contains i a's modulo 2 and j b's modulo 3. Use Q={q00,q01,q02,q10,q11,q12}; start at q00 and make only q00 accepting. An a toggles i, while a b advances j modulo 3.

State    on a    on b    Accepting?
q00      q10     q01     yes
q01      q11     q02     no
q02      q12     q00     no
q10      q00     q11     no
q11      q01     q12     no
q12      q02     q10     no

This table completely specifies the machine and can be drawn as two three-state b-cycles with paired a-transitions between them. By induction on input length, its state is always the pair of remainders claimed above. Therefore it accepts exactly the required strings, including the empty string because zero is divisible by both divisors.

To prove minimum size, first note that every qij is reachable by ai bj. Next take any distinct qij and qkl. Append the suffix a^((-i) mod 2)b^((-j) mod 3). From qij this reaches q00 and accepts. From qkl it reaches the nonzero remainder pair ((k−i) mod 2,(l−j) mod 3), so it rejects. Every pair of states is thus distinguishable by a common suffix. The six distinct residual languages require at least six DFA states; our six-state construction meets this lower bound. Merely multiplying 2 by 3 would suggest the answer but would not, without distinguishability, prove minimality.

Original paper, page 9

5 marks · Descriptive
Report issue

Closure under prefixes and reversal

Closure Properties & Language Hierarchy

Question 21, GATE 1997: A language L is accepted by a finite-state machine. Prove that finite-state machines also accept L′={s: ss′∈L for some string s′} and Lᴿ={s: s is the reversal of some string in L}.
Tap to enlarge
Answer & solution

Answer: For prefixes, accept all states that can reach an old final state. For reversal, reverse edges and exchange starts/finals using an ε-NFA. (no official key was published)

Begin with a DFA M=(Q,Σ,δ,q0,F) for L. This loses no generality because any finite-state recognizer can be determinized. The two constructions solve different problems: L′ consists of prefixes that can still be completed to an accepted word; Lᴿ reverses complete accepted words.

Prefix construction: compute C={q∈Q: δ*(q,t)∈F for some t∈Σ*}. These are exactly the states from which some accepting state is reachable, found by a reverse graph search starting at F. Keep Q,Σ,δ,q0 unchanged and replace the accepting set F by C. The new machine accepts s precisely when δ*(q0,s) belongs to C, which is equivalent to the existence of t with δ*(q0,st)∈F. That is exactly s∈L′. No new states are needed. If L is nonempty, q0∈C and ε is a prefix; if L is empty, C is empty and no word is accepted.

Reversal construction: retain all old states and reverse every labeled transition. For each δ(p,a)=q, add an a-transition q→p. Introduce a fresh start state r with ε-transitions to every f∈F, and make q0 the sole final state. The result is generally nondeterministic because reversing edges can create several transitions with the same label. A path q0 --a1...an--> f in the old machine becomes f --an...a1--> q0 in the new one, and the converse follows by reversing the path again. Thus exactly the reversed words are accepted. If a DFA is required, apply ε-closure and subset construction. Simply exchanging start/final states without reversing edges, or reversing edges while insisting on a single old final as start, would not establish closure for arbitrary L.

Original paper, page 9

1 mark · MCQ
Report issue

Equivalent unary regular expressions

Regular Expressions & Languages

Question 1.8, GATE 1996: Compare (i)(00)*(ε+0), (ii)(00)*, (iii)0*, and (iv)0(00)*. Which expressions are equivalent?
Tap to enlarge
Your answer
Answer & solution

Answer: C: (i) and (iii) (no official key was published)

Expression (00)* produces every even number of zeros, including zero. Appending either ε or one zero therefore produces every nonnegative length, exactly 0*. Expression (ii) alone excludes odd lengths; expression (iv) produces only odd lengths and excludes ε. Thus only (i) and (iii) describe the same language. Checking both ε and a one-symbol word already distinguishes the parity-restricted alternatives from the full unary language.

Original paper, page 2

1 mark · MCQ
Report issue

Decidable equivalence for regular grammars

Decidability & Computability

Question 1.9, GATE 1996: Select the false undecidability claim among TM halting, CFG ambiguity, CFG equivalence and regular-grammar equivalence.
Tap to enlarge
Your answer
Answer & solution

Answer: D (no official key was published)

Regular grammars can be converted to finite automata. Determinize and complete the automata, form their product accepting the symmetric difference, and test whether any accepting product state is reachable. No reachable accepting state means the languages are equal. This is a terminating decision procedure, so saying regular-grammar equivalence is undecidable is false. TM halting, general CFG ambiguity and general CFG equivalence are undecidable problems. The finite-state restriction is what makes the fourth case different.

Original paper, page 2

1 mark · MCQ
Report issue

A regular two-block language

Regular Expressions & Languages

Question 1.10, GATE 1996: Which language over {a,b} is regular: (A) all words with equally many a and b symbols; (B) {a^n b^n:n≥1}; (C) all words with more a symbols than b symbols; (D) {a^m b^n:m≥1,n≥1}?
Tap to enlarge
Your answer
Answer & solution

Answer: D (no official key was published)

The displayed language has no equality or inequality coupling the two block lengths. It is described by the regular expression aa*bb*: read at least one a, then at least one b. A finite automaton only needs to remember which block it is reading and reject a later a. In contrast, requiring equal block lengths or comparing their unbounded counts generally needs more than finite memory. Thus the unrestricted positive two-block choice D is regular; the independent quantifiers m,n are crucial.

Original paper, page 2

2 marks · MCQ
Report issue

Closure properties of context-free languages

Closure Properties & Language Hierarchy

Question 2.8, GATE 1996: For CFLs L1,L2 and regular R, which need not be context-free: concatenation, L1∩L2, L1∩R, or union?
Tap to enlarge
Your answer
Answer & solution

Answer: B, C (no official key was published)

Context-free languages are closed under union and concatenation by introducing an appropriate new grammar start rule. They are also closed under intersection with a regular language, using a product of a PDA and a finite automaton. But take L1={an bn cm} and L2={am bn cn}, with nonnegative exponents. Each is context-free, while their intersection is {an bn cn}, which is not. Hence intersection of two arbitrary CFLs is the exceptional operation. The paper instead repeats L1∩L2 in choice C, making both B and C valid answers to its literal options; this source discrepancy is retained.

Original paper, page 4

2 marks · MCQ
Report issue

Prefixes of equal-count binary strings

Other / Mixed Topics

Question 2.9, GATE 1996: Let init(L)={u:uv∈L for some v}. If L is the set of nonempty binary words with equally many 0s and 1s, determine init(L).
Question 2.9, GATE 1996: Let init(L)={u:uv∈L for some v}. If L is the set of nonempty binary words with equally many 0s and 1s, determine init(L).
Tap to enlarge
Your answer
Answer & solution

Answer: B: {0,1}* (no official key was published)

Take any binary word u. If it has more zeros than ones, append exactly enough ones to balance the counts; if it has more ones, append zeros instead. If its counts are already equal and u is nonempty, append ε; if u=ε, append 01 so the resulting balanced word is nonempty. In every case there exists a suffix v with uv∈L, so every binary word is in init(L). Conversely, every prefix of a binary word is binary. The two inclusions prove init(L)={0,1}*, without requiring the prefix itself to have balanced counts.

Original paper, page 4

5 marks · Descriptive
Report issue

Eliminate nullable and unit rules

Context-Free Grammars & Languages

Question 11, GATE 1996: Transform S→ABAC, A→aA|ε, B→bB|ε, C→d into an equivalent CFG with no ε-productions and no unit productions.
Tap to enlarge
Answer & solution

Answer: S→ABAC|BAC|AAC|ABC|AC|BC|d; A→aA|a; B→bB|b; C→d. (no official key was published)

The nullable nonterminals are A and B. C is not nullable because it must produce d; S is consequently not nullable. In S→ABAC, independently retain or omit each of the two occurrences of A and the one occurrence of B. The distinct right sides are ABAC, BAC, AAC, ABC, AC, BC and C. The side AC arises twice because either A can be the sole retained A, but duplicate productions need only be written once.

Removing A→ε and B→ε requires adding the terminating alternatives A→a and B→b: their old recursive rules could previously terminate by using the nullable final nonterminal. Keep A→aA|a and B→bB|b, so these variables now generate positive rather than arbitrary nonnegative repetitions. Keep C→d.

The only unit production introduced is S→C. Substitute C's nonunit right side to obtain S→d, then delete S→C. The resulting grammar is S→ABAC|BAC|AAC|ABC|AC|BC|d, A→aA|a, B→bB|b, C→d.

Every rule now has a nonempty right side; none has a sole nonterminal. The original language is {ai bj ak d:i,j,k≥0}. The seven start alternatives cover exactly which of the three repetition blocks are empty, with the all-empty case producing d. Thus the transformation preserves the language, including the shortest word d.

Original paper, page 8

Descriptive
Report issue

Concatenate two finite automata

Finite Automata

Question 12(a), GATE 1996: M1 has states A(start,final),B(nonfinal), with A→B and B→A on either 0 or 1. M2 has C(start,final),D(final),E(nonfinal): C loops on a, C→D on b, D loops on b, D→E on a, and E loops on a,b. Construct an ε-NFA recognizing L1L2 using no new states and only added ε-transitions.
Question 12(a), GATE 1996: M1 has states A(start,final),B(nonfinal), with A→B and B→A on either 0 or 1. M2 has C(start,final),D(final),E(nonfinal): C loops on a, C→D on b, D loops on b, D→E on a, and E loops on a,b. Construct an ε-NFA recognizing L1L2 using no new states and only added ε-transitions.
Question 12(a), GATE 1996: M1 has states A(start,final),B(nonfinal), with A→B and B→A on either 0 or 1. M2 has C(start,final),D(final),E(nonfinal): C loops on a, C→D on b, D loops on b, D→E on a, and E loops on a,b. Construct an ε-NFA recognizing L1L2 using no new states and only added ε-transitions.
Question 12(a), GATE 1996: M1 has states A(start,final),B(nonfinal), with A→B and B→A on either 0 or 1. M2 has C(start,final),D(final),E(nonfinal): C loops on a, C→D on b, D loops on b, D→E on a, and E loops on a,b. Construct an ε-NFA recognizing L1L2 using no new states and only added ε-transitions.
Tap to enlarge
Answer & solution

Answer: Use start A, final states C,D; add A→C on ε, retaining every original transition. (no official key was published)

M1 accepts binary strings of even length: each 0 or 1 toggles A and B, and A is accepting. M2 accepts a*b*: it stays at C through a's, moves to D at the first b, and a later a leads to rejecting sink E. Both languages contain ε.

For concatenation, retain all original symbol-labelled edges and add A→C on ε, because A is the only accepting state of M1 and C is the initial state of M2. The combined machine has just one initial state, A. Its accepting states are C and D, the former accepting states of M2. A is no longer designated accepting, although ε is still accepted via the new ε-edge to C. B and E remain nonaccepting.

Any accepting run first follows a run of M1 ending at A, then uses the ε-edge and follows an accepting run in M2. The consumed string therefore factors as uv with u∈L1 and v∈L2. Conversely every such factorization gives an accepting run. This proves equivalence rather than just providing a diagram recipe.

Text diagram addition: A --ε--> C. Initial/final annotations must be updated as stated; “only add ε-transitions” refers to edges and state count, not to keeping two independent initial-state markings. No new states or symbol transitions are required.

Original paper, page 8

Descriptive
Report issue

Iterate a concatenated language

Closure Properties & Language Hierarchy

Question 12(b), GATE 1996: M1 has states A(start,final),B(nonfinal), with A→B and B→A on either 0 or 1. M2 has C(start,final),D(final),E(nonfinal): C loops on a, C→D on b, D loops on b, D→E on a, and E loops on a,b. Starting with the concatenation machine (start A, finals C,D, added ε-edge A→C), recognize (L1L2)* without new states.
Question 12(b), GATE 1996: M1 has states A(start,final),B(nonfinal), with A→B and B→A on either 0 or 1. M2 has C(start,final),D(final),E(nonfinal): C loops on a, C→D on b, D loops on b, D→E on a, and E loops on a,b. Starting with the concatenation machine (start A, finals C,D, added ε-edge A→C), recognize (L1L2)* without new states.
Question 12(b), GATE 1996: M1 has states A(start,final),B(nonfinal), with A→B and B→A on either 0 or 1. M2 has C(start,final),D(final),E(nonfinal): C loops on a, C→D on b, D loops on b, D→E on a, and E loops on a,b. Starting with the concatenation machine (start A, finals C,D, added ε-edge A→C), recognize (L1L2)* without new states.
Question 12(b), GATE 1996: M1 has states A(start,final),B(nonfinal), with A→B and B→A on either 0 or 1. M2 has C(start,final),D(final),E(nonfinal): C loops on a, C→D on b, D loops on b, D→E on a, and E loops on a,b. Starting with the concatenation machine (start A, finals C,D, added ε-edge A→C), recognize (L1L2)* without new states.
Tap to enlarge
Answer & solution

Answer: Add C→A and D→A on ε; keep start A and final states C,D. (no official key was published)

In the concatenation machine, reaching either C or D after consuming input means one complete L1L2 factor has been recognized. To permit another factor, add ε-edges from both accepting states back to the start A. Retain A→C and all original symbol edges. The complete added-edge set relative to the original two diagrams is A→C, C→A and D→A, all labelled ε.

An accepting run can now consist of any finite number of concatenation runs separated by the new return edges. Each segment consumes a word of L1L2; conversely a concatenation of such words is realized by joining their accepting runs through these ε-edges. Since L1 and L2 already contain ε, the start A can reach accepting C without consuming input, so the zero-factor case is accepted without adding a new accepting start state.

Keep C,D as final states. Making A final as well would also be harmless here because A already has an ε-path to a final state, but it is unnecessary. Adding only D→A would be insufficient as a general concatenation construction because C is also a valid final state, for example after a factor ending with only a's. ε-cycles cause no language-theoretic problem; an implementation computes finite ε-closures rather than following such cycles forever.

Original paper, page 8

5 marks · Descriptive
Report issue

Complete a palindrome PDA carefully

Pushdown Automata

Question 13, GATE 1996: A PDA with states q1,q2, alphabet {a,b}, stack alphabet {a,b,Z}, initial state q1 and stack Z accepts nonempty even palindromes by empty stack. Stack top is at the right. Given δ(q1,a,Z)={(q1,Za)}, δ(q1,b,Z)={(q1,Zb)}, δ(q2,a,a)={(q2,ε)}, δ(q2,b,b)={(q2,ε)}, δ(q2,ε,Z)={(q2,ε)}, fill the two alternatives in each of δ(q1,a,a) and δ(q1,b,b). Discuss whether the displayed list is sufficient.
Tap to enlarge
Answer & solution

Answer: δ(q1,a,a)={(q1,aa),(q2,ε)}; δ(q1,b,b)={(q1,bb),(q2,ε)}. Also require δ(q1,a,b)={(q1,ba)} and δ(q1,b,a)={(q1,ab)}. (no official key was published)

In state q1, the machine is guessing and storing the first half. On a matching input/top pair, it has two nondeterministic choices: push that input as another first-half symbol, or treat it as the first symbol of the reversed second half and pop the matching top while entering q2. Thus the displayed blanks are (q1,aa) and (q2,ε) for input a/top a, and (q1,bb) and (q2,ε) for input b/top b.

Those fillings alone do not recognize all even palindromes. The paper omits the mixed push transitions δ(q1,a,b)={(q1,ba)} and δ(q1,b,a)={(q1,ab)}. With rightmost stack top, ba means retain b and push a. For example abba requires pushing b over a; it is rejected if the missing transitions are absent. This is a defect in the printed specification, not an additional blank that can be silently filled.

With these two additional rules, q1 pushes an arbitrary nonempty first half. It switches to q2 only while reading and popping a matching character, then q2 can only pop further matching characters. Finally it removes Z by ε. Acceptance requires both empty stack and exhausted input. The first symbol must be pushed, so the empty word cannot be accepted; each push corresponds to exactly one later matched input, enforcing even length. The accepted strings are exactly wwR with nonempty w. No literal filling of just the four displayed blanks repairs the missing mixed cases.

Original paper, page 8

1 mark · MCQ
Report issue

Regular expression for identifiers

Regular Expressions & Languages

Question 1.9, GATE 1995: An identifier is one letter followed by zero or more letters or digits. With letter set L and digit set D, choose its expression.
Tap to enlarge
Your answer
Answer & solution

Answer: B: L(L∪D)* (no official key was published)

The initial L enforces exactly one initial letter. Every subsequent character may independently be a letter or digit, represented by L∪D, and the star allows zero or more such characters. Thus a one-letter identifier is allowed, but an empty identifier or one beginning with a digit is not. Expressions that star an alternating letter-digit pair impose an unjustified pattern, while starring or plussing L∪D alone permits a digit first. The concatenation L(L∪D)* captures precisely the requirement.

Original paper, page 1

1 mark · MCQ
Report issue

A damaged grammar classification

Context-Free Grammars & Languages

Question 1.10, GATE 1995: Classify the reproduced grammar as context-free, regular, context-sensitive or LR(k). Its final GFG line reads bα→bdb|b; other nonterminal labels and the alternate differ.
Question 1.10, GATE 1995: Classify the reproduced grammar as context-free, regular, context-sensitive or LR(k). Its final GFG line reads bα→bdb|b; other nonterminal labels and the alternate differ.
Tap to enlarge
Your answer
Answer & solution

Answer: No listed classification can be justified: the printed grammar has a contracting rule (no official key was published)

A context-free production must have one nonterminal on its left side; the visible bα left side has multiple symbols. A context-sensitive grammar in the usual noncontracting form cannot contain bα→b, which shortens a nonempty string. Regular and LR(k) grammars are context-free and therefore fail the same left-side condition. Moreover, the reproductions disagree on labels and contain undeclared-looking symbols, so even a valid unrestricted grammar cannot be reconstructed confidently. If the contraction or labels are typographic errors, classification might change. No option is asserted without a trustworthy correction of the source.

Original paper, page 1

2 marks · MCQ
Report issue

A grammar versus regular expressions for equal counts

Regular Expressions & Languages

Question 2.20, GATE 1995: For L={x^n y^n:n≥1}, compare I E→xEy|xy; II xy | x⁺xyy⁺; III x⁺y⁺. Which define L?
Tap to enlarge
Your answer
Answer & solution

Answer: A: I only (no official key was published)

Grammar I starts with xy and each recursive wrapping adds one x to the front and one y to the end. It therefore generates exactly equal positive block counts. Expression III permits unequal counts, for example xyy. Expression II permits independently sized positive runs before its extra x and after its first y; for example xxyyy is accepted but has unequal counts. Hence neither regular expression enforces equality. Only I defines L, in agreement with the fact that the equal-count language is not regular.

Original paper, page 5

2 marks · MCQ
Report issue

Union with the universal binary language

Regular Expressions & Languages

Question 2.24, GATE 1995: Let Σ={0,1}, L=Σ*, R={0^n1^n:n>0}. Classify L∪R and R as regular or nonregular.
Tap to enlarge
Your answer
Answer & solution

Answer: C: regular,nonregular (no official key was published)

Every member of R is a binary word, so R⊆Σ*=L. Hence L∪R=L, which is regular. R itself is nonregular: if its pumping length were p, the word 0p1p would have a pumpable nonempty segment entirely among its first p zeros. Pumping that segment changes the number of zeros but not ones, leaving R and contradicting the lemma. Thus adjoining R to a universal regular language does not make the union nonregular.

Original paper, page 5

Descriptive
Report issue

Explain cycles and LL(1) parsing

Context-Free Grammars & Languages

Question 9(b), GATE 1995: A grammar has a cycle if A⇒⁺A for some nonterminal A. Show that a grammar with cycles cannot be LL(1), stating any necessary qualification.
Tap to enlarge
Answer & solution

Answer: A useful/productive cycle is incompatible with LL(1); the unrestricted claim needs a reduced-grammar assumption. (no official key was published)

Assume the cyclic nonterminal A is reachable in a successful derivation and can derive a terminal string w (possibly ε). Starting at A, one may derive w directly, or first traverse the nonempty cycle A⇒⁺A and then derive the same w. Inserting the cycle into a successful start-symbol derivation gives two distinct parse trees for the same terminal string. Every LL(1) grammar is unambiguous, so this useful cyclic grammar cannot be LL(1).

Operationally, a predictive parser cannot decide from the same next input symbol whether to begin another traversal of a nullable cycle or leave it to produce the terminal string. The proof concerns a cycle deriving A itself, not ordinary right recursion such as A→aA, which consumes input and can be LL(1).

The statement as printed omits the usual reduced-grammar qualification. As a literal counterexample, S→a with an unreachable rule A→A generates only a and has a conflict-free predictive table for all successful parses from S; the unreachable cycle contributes no competing table entry. A nonproductive cycle likewise cannot be inserted in a successful parse. Thus the intended theorem is valid for reduced grammars, or for cycles on useful nonterminals, rather than arbitrary added useless rules.

Original paper, page 6

5 marks · Descriptive
Not in GATE 2027 syllabusReport issue

Certify the complement of a thin NP language

Complexity & Reductions

Question 11, GATE 1995: L⊆Σ* is in NP and contains exactly one string of each length n. Prove its complement is in NP.
Tap to enlarge
Answer & solution

Answer: For x, certify a different same-length y∈L using its NP witness. (no official key was published)

Since L is in NP, there is a polynomial-time verifier V(y,c) and a polynomial bound on certificates c such that y∈L exactly when some c makes V accept. To verify that x is in the complement, guess a pair (y,c), require |y|=|x| and y≠x, and run V(y,c). Accept precisely when all checks pass.

Completeness: if x∉L, the hypothesis guarantees a string y∈L of length |x|. It cannot equal x, and it has an accepting NP certificate, so the new verifier has an accepting guess. Soundness: if x∈L, uniqueness says no different same-length y lies in L. Therefore no proposed pair can pass all checks.

The guessed y has length n, its certificate has polynomial length in n, and both comparison and verification take polynomial time. This proves the complement is in NP without assuming NP=coNP. Both parts of “exactly one” matter: existence supplies a witness on complement instances, while uniqueness prevents false acceptance on member instances. At length zero the only word is ε, which is in L, and no different same-length word exists, so rejection is correct.

Original paper, page 7

Report issue

Counting substring occurrences

Other / Mixed Topics

Question 1.15, GATE 1994: For a character string of length n, how many nonempty contiguous substrings are there when counted by position?
Tap to enlarge
Your answer
Answer & solution

Answer: D: n(n+1)/2 (no official key was published)

A substring of length k can start in n−k+1 positions. Summing for k=1 through n gives n+(n−1)+…+1=n(n+1)/2. Equivalently choose its two boundaries among n+1 boundary positions. This counts occurrences, not necessarily distinct string values: repeated characters can make different positions yield the same word. It also excludes ε. If “substrings of all lengths” includes the empty word or means distinct values, the answer needs that additional convention.

Original paper, page 2

Report issue

A conversion impossible in general

Pushdown Automata

Question 1.16, GATE 1994: Which equivalent-machine conversion is impossible in general: regular grammar→CFG, NFA→DFA, NPDA→DPDA, or nondeterministic TM→deterministic TM?
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

Every regular grammar is already a restricted CFG, and the subset construction converts NFAs to equivalent DFAs. A deterministic TM can simulate all branches of a nondeterministic TM by dovetailing, preserving recognition power. But deterministic context-free languages are strictly fewer than context-free languages. For example unmarked palindromes over a two-letter alphabet are context-free but not deterministic context-free. Hence some NPDAs have no equivalent DPDA at all, so a general conversion cannot exist.

Original paper, page 2

Report issue

Regex from an automaton with a trap

Regular Expressions & Languages

Question 2.10, GATE 1994: Start/accept state A loops on 0 and goes to accept B on 1. B loops on 1 and goes to nonaccepting trap C on 0; C loops on both. Give a regex.
Tap to enlarge
Answer & solution

Answer: 0*1* (no official key was published)

While in A the machine reads any number of zeros, possibly none. The first one moves it to B, where further ones are allowed. A zero after that moves to the trap and cannot be recovered. Thus accepted words are exactly a block of zeros followed by a block of ones, with either block allowed empty: 0*1*. The empty word is accepted because the start state A is accepting. The accepting mark on B permits words ending after one or more ones.

Original paper, page 4

Report issue

Enumerating maximal runs in pi

Decidability & Computability

Question 19(a), GATE 1994: Let S be the set of positive integers x for which the decimal expansion of π contains a maximal consecutive run of exactly x digits equal to 5. Which classification is warranted: (i) regular, (ii) recursively enumerable, (iii) not recursively enumerable, (iv) recursive?
Tap to enlarge
Your answer
Answer & solution

Answer: The justified choice is (ii): recursively enumerable. No claim of nonrecursiveness follows. (no official key was published)

π is a computable real, and any finite initial segment of its decimal digits can be calculated effectively. Scan these digits from left to right, keeping the length of the current run of 5s. When a non-5 follows a nonempty run, output its length and reset the counter. Because a completed run has a non-5 immediately on each side (or begins at the start of the fractional digit stream), it is maximal rather than merely a substring of a longer run. Repeated lengths may be printed repeatedly; enumeration does not require uniqueness.

Equivalently, on input x, keep scanning until a completed run of length exactly x appears, then accept. Every positive instance eventually has a finite witness and is accepted. For an absent length the scan may never halt. This establishes recursive enumerability, the warranted answer (ii).

It does not establish that S is nonrecursive. In particular, a hypothetical proof that all finite digit blocks occur in π would make S all positive integers, which is recursive (and regular under customary encodings). Normality of π is not a given and must not be assumed. Nor does failure of this particular search to halt on negative instances prove that no different decision procedure exists. Options (i) and (iv) therefore cannot be inferred merely from the stated computability facts; describing (ii) as the only possible mathematical property would overstate the argument. A regular-language claim additionally needs an encoding of integers.

Original paper, page 6

Descriptive
Report issue

A regular union does not determine its operand

Regular Expressions & Languages

Question 19(b), GATE 1994: If L1 and L1∪L2 are regular, must L2 be regular? Prove the answer.
Tap to enlarge
Answer & solution

Answer: No. Take L1={a,b}* and L2={a^n b^n:n≥0}. (no official key was published)

Choose the common alphabet Σ={a,b}, let L1=Σ*, and let L2={an bn:n≥0}. L1 is recognized by a single accepting state with a loop on each alphabet symbol. Since L2⊆L1, their union is Σ*, also regular. Nevertheless L2 is not regular.

To verify the last assertion, suppose a pumping length p exists. The word ap bp must have a decomposition xyz with |xy|≤p and |y|>0. Consequently y consists of k≥1 copies of a. Pumping y zero times gives ap−kbp, which is not in L2 because the numbers of a and b differ. This contradicts the pumping lemma.

The tempting subtraction argument is invalid: (L1∪L2) minus L1 equals L2 minus L1, not necessarily L2. Regularity of the union controls the portion of L2 outside L1, but places no constraint on its arbitrary portion inside L1. Our counterexample puts all of L2 inside L1, making that gap explicit.

Original paper, page 6

5 marks · Descriptive
Report issue

Length of a strict CNF derivation

Context-Free Grammars & Languages

Question 20, GATE 1994: A CFG has only productions A→BC and A→a. For a generated terminal word of length ℓ, how many production applications occur in its derivation? GateForum omits the symbol after “length”; GFG supplies ℓ.
Tap to enlarge
Answer & solution

Answer: 2ℓ−1 production applications for ℓ≥1. (no official key was published)

Each terminal of the final word is introduced by exactly one A→a production: no other production introduces terminals, and no production subsequently removes them. Hence there are exactly ℓ terminal-producing steps. Start with one nonterminal. Each A→BC application increases the number of nonterminals by one, whereas each A→a decreases it by one. If b is the number of binary applications, the final nonterminal count is 1+b−ℓ=0, so b=ℓ−1. The total number of applications is b+ℓ=2ℓ−1.

The same result follows by viewing the nonterminal portion of the parse tree as a full binary tree: ℓ terminal-producing leaves require ℓ−1 binary internal nodes. The count is independent of which nonterminal is expanded first, of leftmost versus rightmost derivation, and of ambiguity of the grammar. For ℓ=1 there is just the single terminal production, agreeing with the formula.

This is a count of steps, not a count of sentential forms: including both the initial symbol and final word gives 2ℓ sentential forms. Under the strict production forms stated here ε cannot be generated. If a different CNF convention permits S→ε, its ε derivation is a separate one-step exception, not an application of the formula at ℓ=0.

Original paper, page 6

5 marks · Descriptive
Report issue

DFA excluding three consecutive b characters

Finite Automata

Question 27, GATE 1993: Draw a DFA over {a,b} accepting exactly strings with no substring bbb.
Tap to enlarge
Answer & solution

Answer: States q0,q1,q2 accepting, qD rejecting; start q0; a resets q0 before death; b advances q0→q1→q2→qD; qD loops. (no official key was published)

Step through it (2 parts)

While no forbidden substring has appeared, only the length of the trailing run of b characters matters. State q0 means zero trailing b's, q1 one, and q2 two. A third consecutive b makes the input permanently unacceptable, represented by rejecting sink qD.

Transition diagram as a complete edge list:
q0 --a--> q0; q0 --b--> q1
q1 --a--> q0; q1 --b--> q2
q2 --a--> q0; q2 --b--> qD
qD --a,b--> qD.
Start at q0; accepting states are q0,q1,q2. In particular epsilon is accepted, and bb is accepted but bbb is not.

Induct on the processed prefix: before a forbidden block occurs, the named state records its trailing b count; an a resets that count and a b increments it. Upon reaching three, qD is entered and can never be escaped, so later a's cannot erase an earlier violation. This invariant proves both acceptance of every valid string and rejection of every invalid one. Four states are also minimal: qD differs from all accepting states on epsilon, and q0,q1,q2 can be distinguished by appending b or bb as appropriate.

Original paper, page 15

Report issue

Malformed regular-expression identities

Regular Expressions & Languages

Question 2(xvii), GATE 1992: The copies print A r(*)=r* and B (r*s*)=(r+s)*, plus C (r+s)*=r*+s* and D r*s*=r*+s*. Which identities are justified?
Question 2(xvii), GATE 1992: The copies print A r(*)=r* and B (r*s*)=(r+s)*, plus C (r+s)*=r*+s* and D r*s*=r*+s*. Which identities are justified?
Tap to enlarge
Select all that apply
Answer & solution

Answer: Literal A malformed, B/C/D false; intended A/B would need missing outer stars (no official key was published)

A standard true identity is (r*)*=r*, but the source’s r(*) is not that well-formed expression. Another true identity is (r*s*)*=(r+s)*, which requires an outer star absent from printed B. For literal B, take r=a, s=b: ba belongs to (a+b)* but not a*b*. For C, ab belongs to the left but neither a* nor b*. For D, ab belongs to a*b* but not a*+b*. Thus the often-intended answers A, B are conditional repairs, not identities established by the literal printed notation. The missing-star issue is retained as a source discrepancy.

Original paper, page 4

Report issue

Length of a CNF derivation

Context-Free Grammars & Languages

Question 2(xviii), GATE 1992: For a nonempty word w of length ℓ in a Chomsky-normal-form grammar, how many production applications derive it?
Question 2(xviii), GATE 1992: For a nonempty word w of length ℓ in a Chomsky-normal-form grammar, how many production applications derive it?
Tap to enlarge
Select all that apply
Answer & solution

Answer: C: 2ℓ−1 (no official key was published)

A CNF parse tree uses binary nonterminal productions A→BC and terminal productions A→a. There are ℓ terminal-producing leaves. A full binary tree with ℓ leaves has ℓ−1 binary internal nodes, so the total applications are ℓ+(ℓ−1)=2ℓ−1. The order of expanding variables does not change that count. The special ε-production sometimes allowed for the start symbol is outside this nonempty-word case; substituting ℓ=0 into the formula would not count its derivation correctly.

Original paper, page 4

Report issue

Closure of context-free languages

Closure Properties & Language Hierarchy

Question 2(xix), GATE 1992: Which closures hold for CFLs: union, complement, intersection, Kleene star?
Question 2(xix), GATE 1992: Which closures hold for CFLs: union, complement, intersection, Kleene star?
Tap to enlarge
Select all that apply
Answer & solution

Answer: A, D (no official key was published)

For union, introduce a new start symbol choosing either original grammar. For star, use a new start that produces ε or concatenates one original-language word with another repetition. Hence both operations preserve context-freeness. Intersection does not: {an bn cm} intersected with {am bn cn} gives the non-CFL equal-three-block language. If CFLs were also closed under complement, De Morgan together with union closure would imply intersection closure, contradicting that example. Thus complement and arbitrary intersection fail.

Original paper, page 4

Report issue

When nondeterminism adds recognition power

Other / Mixed Topics

Question 2(xx), GATE 1992: For which machine models does every nondeterministic machine have an equivalent deterministic machine: finite automata, PDAs, TMs, or none?
Question 2(xx), GATE 1992: For which machine models does every nondeterministic machine have an equivalent deterministic machine: finite automata, PDAs, TMs, or none?
Tap to enlarge
Select all that apply
Answer & solution

Answer: A, C (no official key was published)

The subset construction converts an NFA to a DFA recognizing the same language. A deterministic TM can explore the finitely branching computation tree breadth-first or by dovetailing, accepting whenever some nondeterministic branch accepts. Thus nondeterministic TMs recognize no additional languages, though complexity can change. NPDAs recognize all CFLs, while DPDAs recognize only deterministic CFLs, a strict subclass. Consequently the universal equivalence holds for finite automata and Turing machines, but not pushdown automata.

Original paper, page 4

Descriptive
Report issue

Union of two recursive languages

Closure Properties & Language Hierarchy

Question 16(i), GATE 1992: True or false? The union of two recursive languages is recursive. Prove your answer.
Question 16(i), GATE 1992: True or false? The union of two recursive languages is recursive. Prove your answer.
Tap to enlarge
Answer & solution

Answer: True; run the two total deciders and accept iff either accepts. (no official key was published)

True. A recursive language has a decider: a machine that halts on every input and answers membership correctly. Let M1 decide L1 and M2 decide L2, taking a common ambient alphabet (the union of their alphabets if necessary). A machine for L1∪L2 operates as follows:

On input w:
  run M1(w) to completion;
  if M1 accepts, accept;
  run M2(w) to completion;
  if M2 accepts, accept;
  otherwise reject.

If w belongs to the union, at least one decider accepts. Acceptance by M1 immediately suffices; otherwise M2 accepts. If w is outside the union, both deciders reject, and the constructed machine rejects. It always halts because M1 always halts and, when run, M2 always halts. Correctness together with total termination proves recursiveness.

Sequential simulation is adequate here. For merely recursively enumerable languages the first recognizer might loop forever on a nonmember, so a union recognizer generally needs dovetailing instead. The stronger halting promise for recursive languages is the precise reason the simpler proof works. This establishes closure under finite union by induction; it does not establish closure under arbitrary infinite union.

Original paper, page 9

Descriptive
Report issue

Unary prime-length language is not regular

Regular Expressions & Languages

Question 16(ii), GATE 1992: True or false? L={0ⁿ : n is prime} is not regular. Prove your answer.
Question 16(ii), GATE 1992: True or false? L={0ⁿ : n is prime} is not regular. Prove your answer.
Tap to enlarge
Answer & solution

Answer: True. Pump a prime-length q word with i=q+1 to obtain composite length q(1+|y|). (no official key was published)

True. Suppose for contradiction that L is regular, and let p≥1 be its pumping length. There is a prime q≥p, because primes are unbounded. Choose w=0q∈L. For any pumping-lemma decomposition w=xyz with |xy|≤p and |y|≥1, let d=|y|, so 1≤d≤p.

The pumping lemma requires xyi z∈L for every integer i≥0. Choose i=q+1. This word has length
|xz|+(q+1)|y| = (q−d)+(q+1)d = q+qd = q(1+d).
Both factors exceed one: q is prime and therefore q≥2, while d≥1 gives 1+d≥2. The length is composite. Consequently xyq+1z∉L, contradicting the pumping lemma.

The contradiction holds for every valid decomposition, because the same choice i=q+1 works for every positive d. We therefore refute the existence of a pumping length, and L is nonregular. Choosing an arbitrary fixed pump such as i=2 would not suffice: q+d might itself be prime for some decompositions. The deliberately selected exponent makes the resulting length a multiple of q larger than q.

Original paper, page 9

Report issue

Failure of closure under infinite union

Closure Properties & Language Hierarchy

Question 16(iii), GATE 1992: True or false? Regular languages are closed under infinite union. Prove your answer.
Question 16(iii), GATE 1992: True or false? Regular languages are closed under infinite union. Prove your answer.
Tap to enlarge
Answer & solution

Answer: False; ⋃_{n≥0}{0ⁿ1ⁿ} is nonregular although each singleton is regular. (no official key was published)

False. For every n≥0 define Ln={0n1n}. Each Ln contains one fixed finite word and is regular: a finite chain of states accepts exactly that word, or the word itself is a regular expression. However, the infinite union ⋃_{n≥0}Ln={0n1n:n≥0} is not regular.

For completeness, suppose this union has pumping length p. The word w=0p1p belongs to it. Every legal decomposition w=xyz with |xy|≤p and |y|≥1 puts y entirely in the first block of zeros, say y=0d with d≥1. Pump down to i=0. The resulting xz=0p−d1p has unequal numbers of zeros and ones and is not in the union, contradicting the pumping lemma.

This is a countably infinite family of regular languages with a nonregular union, enough to disprove arbitrary infinite-union closure. Closure under two-way union, and hence any finite union, is not in conflict: the usual product/NFA constructions use finitely many component automata, whereas this family requires unboundedly many distinct word lengths. Some infinite unions do happen to be regular, for example ⋃_{n≥0}{0n}=0*. The statement fails because not every infinite union is regular.

Original paper, page 9

2 marks · MSQ
Report issue

Regular-expression inclusions

Regular Expressions & Languages

Question 3(xiii), GATE 1991: Let r=1(1+0)*, s=11*0, t=1*0. Choose A L(s)⊆L(r) and L(s)⊆L(t); B reverse first inclusion; C L(s)=L(t); D L(t)⊆L(s); E none.
Question 3(xiii), GATE 1991: Let r=1(1+0)*, s=11*0, t=1*0. Choose A L(s)⊆L(r) and L(s)⊆L(t); B reverse first inclusion; C L(s)=L(t); D L(t)⊆L(s); E none.
Tap to enlarge
Select all that apply
Answer & solution

Answer: A (no official key was published)

Every s-word is one or more 1s followed by a single 0. It starts with 1 and has an arbitrary binary suffix, so it belongs to r. It also consists of zero or more 1s followed by 0, so it belongs to t. The inclusions are strict: 1 belongs to r but not s, and 0 belongs to t but not s. These witnesses refute the reverse inclusion and equality choices. Kleene star in 11*0 applies only to the second 1; the mandatory initial 1 is what excludes 0 from s.

Original paper, page 4

2 marks · MSQ
Report issue

Strongest classification of a finite language

Regular Expressions & Languages

Question 3(xiv), GATE 1991: For a finite language over a finite alphabet, choose strongest claim: possibly undecidable, TM-recognizable, context-sensitive, regular, none.
Question 3(xiv), GATE 1991: For a finite language over a finite alphabet, choose strongest claim: possibly undecidable, TM-recognizable, context-sensitive, regular, none.
Tap to enlarge
Select all that apply
Answer & solution

Answer: D: regular (no official key was published)

Write the finite language as{w1, …, wk}. Each fixed word has a regular expression obtained by concatenating its symbols, and their finite union is a regular expression for the whole language. The empty language and words containing ε also fit the regular class. Hence it is regular, which already implies decidability and TM recognizability. Those weaker true classifications are not the strongest requested answer. The proof is existential: it does not claim that an arbitrary description of an unknown finite language makes its entire list immediately computable.

Original paper, page 4

5 marks · Descriptive
Report issue

Constant-workspace machines recognize regular languages

Turing Machines

Question 17(a), GATE 1991: Prove that Turing machines with a read-only input tape and constant-size work tape recognize exactly the regular languages. Use the standard single input-head model with endmarkers.
Tap to enlarge
Answer & solution

Answer: Exactly the regular languages: finite workspace folds into finite control, giving a two-way finite automaton, and two-way finite automata recognize regular languages. (no official key was published)

For the easy direction, let L be regular and choose a DFA for L. A Turing machine stores the DFA state in its finite control, scans the read-only input from left to right, and accepts exactly when the simulated DFA ends in an accepting state. It needs no growing work tape, hence satisfies the constant-space requirement.

For the other direction, let the machine use at most c work cells, where c is independent of input length. If the work alphabet is Γ and the finite control has q states, the work contents and work-head location together have at most |Γ|^c·O(c) possibilities. Fold these possibilities into the control state. This gives a finite-state device whose only unbounded feature is the position of its single head on the read-only input. It is a two-way finite automaton, not immediately an ordinary one-way DFA: treating input-head position as a fixed finite state would be an error.

Here is why two-way motion does not add language power. For any finite input block, summarize its behavior by a finite relation recording which control state and side can enter the block and which control state and side can next exit it, together with whether acceptance can be reached before exit. There are finitely many such boundary-state combinations, so only finitely many possible block summaries, regardless of block length. Infinite internal loops yield no exit or acceptance in the summary.

The summary of a concatenation uv is determined solely by the summaries of u and v: connect their touching boundaries and compute reachability through the finite interface graph, allowing repeated crossings. Each symbol has its own summary. A one-way DFA can therefore read symbols from left to right, retaining the accumulated block summary as its state and updating it by this finite composition. With the endmarkers included, its accepting states are exactly the summaries allowing the original initial state to reach acceptance. This constructs a finite recognizer for the same language. For nondeterministic machines use existential reachability in the same summaries; a finite relation still suffices.

Thus the constant-workspace machine cannot recognize any nonregular language, and both containments establish equality. The standard assumptions exclude multiple independent input heads or writable unbounded input cells, which would invalidate this reduction.

Original paper, page 8

5 marks · Descriptive
Report issue

Third-from-last bit: NFA and minimum DFA

Finite Automata

Question 17(b), GATE 1991: Let L be the set of binary strings whose third symbol from the right is 1. Construct an NFA for L and justify the number of states in its minimized equivalent DFA.
Tap to enlarge
Answer & solution

Answer: A four-state NFA suffices; the minimum DFA has exactly 8 states. (no official key was published)

The language is {0,1}*1{0,1}{0,1}. An NFA can guess which 1 will be third from last, then require exactly two more symbols before acceptance. Use states q0,q1,q2,q3; q0 is initial and q3 is the only accepting state. Missing transitions go to the empty set.

Transition table

State | on 0 | on 1
q0    | {q0} | {q0,q1}
q1    | {q2} | {q2}
q2    | {q3} | {q3}
q3    | {}   | {}

Equivalently, q0 has a loop labeled 0,1 and an additional edge labeled 1 to q1; q1→q2 and q2→q3 are labeled 0,1. A successful path stays at q0 through an arbitrary prefix, takes the guessing edge on a 1, and reads exactly two additional symbols. It ends in q3 precisely for the required strings.

For a DFA upper bound, store the most recent three bits, padding on the left with zeros before three bits have arrived. Use the eight states abc∈{0,1}^3, initial state 000, transition δ(abc,d)=bcd, and accepting states 100,101,110,111. After at least three inputs the first stored bit is exactly third from last; shorter strings remain nonaccepting because their padded first bit is zero. Every state is reachable by reading its three-bit label.

For minimality, take two different length-three strings x and y, differing at position r counted from the left, with 1≤r≤3. Append 0r−1 to both. In each resulting string, the third symbol from the right is precisely the old position r, so exactly one extension is accepted. Thus all eight three-bit strings have pairwise distinct right languages. By Myhill–Nerode, every DFA needs at least eight states. The construction meets this bound, proving that its minimized size is exactly 8.

Original paper, page 8