Skip to content
Official PYQ · 2025

GATE CS 2025 Set 1 Q35 — Regular and Context-free Languages

Explain with AI

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?

Choose one option
View worked solution

Answer: C

To determine if the languages are context-free, we analyze the memory requirements for each language:

Analysis of L1={ambmcm+n∣m,n≥1}L_1 = \{a^m b^m c^{m+n} \mid m, n \geq 1\}:

  • In L1L_1, we must ensure that the number of aa's equals the number of bb's (mm).
  • Additionally, we must compare the count of cc's (m+nm+n) with the count of aa's (or bb's) to ensure there are at least mm occurrences of cc.
  • Since a Pushdown Automaton (PDA) has only one stack, it cannot perform both comparisons (matching aa's with bb's, and then matching the count of aa's with cc's) simultaneously. Thus, L1L_1 is not a context-free language (which can be formally proven using the Pumping Lemma).

Analysis of L2={ambncm+n∣m,n≥1}L_2 = \{a^m b^n c^{m+n} \mid m, n \geq 1\}:

  • In L2L_2, the number of cc's is the sum of the number of aa's and bb's.
  • A PDA can easily recognize this by pushing all aa's and bb's onto the stack, and then popping one symbol for each incoming cc.
  • We can also write a Context-Free Grammar (CFG) for L2L_2: S→aSc∣aAcA→bAc∣bc\begin{aligned} S &\to aSc \mid aAc \\ A &\to bAc \mid bc \end{aligned} Since a CFG exists, L2L_2 is a context-free language.

Therefore, L1L_1 is not a context-free language but L2L_2 is a context-free language.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Regular and Context-free Languages questions