Skip to content
Official PYQ · 2017

GATE CS 2017 Set 1 Q38 — Context-free Grammars and Push-down Automata

Explain with AI

Consider the following languages over the alphabet Σ={a,b,c}\Sigma = \left \{ a, b, c \right \}. Let L1={anbncm∣m,n≥0}L_{1} = \left \{ a^{n}b^{n}c^{m}\mid m,n \geq 0 \right \} and L2={ambncn∣m,n≥0}L_{2} = \left \{ a^{m}b^{n}c^{n}\mid m,n \geq 0 \right \}.

Which of the following are context-free languages?

  1. L1∪L2L_{1} \cup L_{2}
  2. L1∩L2L_{1} \cap L_{2}
Choose one option
View worked solution

Answer: A

To determine which of the given languages are context-free, let us analyze L1L_1 and L2L_2 individually:

  • L1={anbncm∣m,n≥0}L_1 = \{a^n b^n c^m \mid m, n \ge 0\} is a Context-Free Language (CFL). A Pushdown Automaton (PDA) can push aa's onto the stack, pop them when reading bb's to ensure their counts match, and then read any number of cc's without modifying the stack.
  • L2={ambncn∣m,n≥0}L_2 = \{a^m b^n c^n \mid m, n \ge 0\} is also a CFL. A PDA can skip the initial aa's, push bb's onto the stack, and pop them when reading cc's to ensure their counts match.

Now, let us evaluate the given statements:

Statement I: L1∪L2L_1 \cup L_2

Context-free languages are closed under union. Since both L1L_1 and L2L_2 are CFLs, their union L1∪L2L_1 \cup L_2 is guaranteed to be a CFL.

Intuition: A non-deterministic PDA can make an initial ϵ\epsilon-transition to either the PDA for L1L_1 or the PDA for L2L_2.

Statement II: L1∩L2L_1 \cap L_2

Let us find the intersection of the two languages:

L1∩L2={anbncm∣m,n≥0}∩{ambncn∣m,n≥0}={anbncn∣n≥0}L_1 \cap L_2 = \{a^n b^n c^m \mid m, n \ge 0\} \cap \{a^m b^n c^n \mid m, n \ge 0\} = \{a^n b^n c^n \mid n \ge 0\}

The language {anbncn∣n≥0}\{a^n b^n c^n \mid n \ge 0\} is a well-known non-context-free language (which can be formally proven using the Pumping Lemma for CFLs). A single stack cannot simultaneously keep track of two independent comparisons (matching aa's with bb's, and then matching bb's with cc's).

Therefore, only I is a context-free language.

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

Published
Report a correction
Keep exploringMore Context-free Grammars and Push-down Automata questions