Skip to content
Official PYQ · 2021

GATE CS 2021 Set 1 Q1 — Context-free Grammars and Push-down Automata

Explain with AI

Suppose that L1L_1 is a regular language and L2L_2 is a context-free language. Which one of the following languages is NOT\text{NOT} necessarily context-free?

Choose one option
View worked solution

Answer: C

To determine which language is not necessarily context-free, let us analyze the closure properties of Context-Free Languages (CFLs) and Regular languages:

  • Option A (L1∩L2L_1 \cap L_2): The intersection of a regular language and a context-free language is always context-free. This is a standard closure property of CFLs.
  • Option B (L1⋅L2L_1 \cdot L_2): Since every regular language is also a context-free language, and CFLs are closed under concatenation, L1⋅L2L_1 \cdot L_2 is always context-free.
  • Option D (L1∪L2L_1 \cup L_2): Since every regular language is context-free, and CFLs are closed under union, L1∪L2L_1 \cup L_2 is always context-free.
  • Option C (L1−L2L_1 - L_2): This is not necessarily context-free. We can show this using a counterexample:

Counterexample:

Let the alphabet be Σ={a,b,c}\Sigma = \{a, b, c\}.

  • Let L1=a∗b∗c∗L_1 = a^*b^*c^*, which is a regular language.
  • Let L2={aibjck∣i≠j or j≠k}L_2 = \{a^i b^j c^k \mid i \neq j \text{ or } j \neq k\}, which is a context-free language.

Now, let us find L1−L2L_1 - L_2:

L1−L2=a∗b∗c∗−{aibjck∣i≠j or j≠k}={anbncn∣n≥0}L_1 - L_2 = a^*b^*c^* - \{a^i b^j c^k \mid i \neq j \text{ or } j \neq k\} = \{a^n b^n c^n \mid n \ge 0\}

The resulting language {anbncn∣n≥0}\{a^n b^n c^n \mid n \ge 0\} is a well-known non-context-free language. Thus, L1−L2L_1 - L_2 is not necessarily context-free.

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

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