Skip to main content

GATE CSE 2025Theory of Computation › Context-Free Languages & Pushdown AutomataVerified

GATE CSE 2025 PYQ: Consider the following two languages over the alphabet { a , b , c } \{a, b, c\} { a , b , c } , where m m m…

Consider the following two languages over the alphabet {a,b,c}\{a, b, c\}, where mm and nn are natural numbers.

L1={ambmcm+n∣m,n≥1}L2={ambncm+n∣m,n≥1}\begin{aligned} L_{1} & =\left\{a^{m} b^{m} c^{m+n} \mid m, n \geq 1\right\} \\ L_{2} & =\left\{a^{m} b^{n} c^{m+n} \mid m, n \geq 1\right\} \end{aligned}

Which ONE of the following statements is CORRECT?

  1. A
    Both L1L_{1} and L2L_{2} are context-free languages.
  2. B
    L1L_{1} is a context-free language but L2L_{2} is not a context-free language.
  3. C
    L1L_{1} is not a context-free language but L2L_{2} is a context-free language.
    Correct answer
  4. D
    Neither L1L_{1} nor L2L_{2} are context-free languages.

Answer

(C) L 1 L_{1} L 1 ​ is not a context-free language but L 2 L_{2} L 2 ​ is a context-free language.

Approach

Classify $L_1$ and $L_2$ separately. $L_1$ is a standard non-context-free language because it forces three-way agreement $a^m b^m c^m$, with additional trailing $c$'s. $L_2$ is context-free because its condition is only that the number of $c$'s equals the total number of $a$'s and $b$'s, which a pushdown automaton can check by pushing all $a$'s and $b$'s and then popping one symbol per $c$.

The key distinction is that $L_1$ needs $a,b,c$ to agree in the pattern $a^m b^m c^m$ before the extra $c$'s, which no PDA can verify. $L_2$ needs only the total count relation $\#c=\#a+\#b$, which a PDA can verify by pushing all $a$'s and $b$'s and popping on $c$'s. Hence option C.

Reviewed by GateIQ Editorial Team: IIT & IISc Alumni.