Question

Consider the following languages over the alphabet Σ={a,b,c}\Sigma = \{a, b, c\}.

Let L1={anbncm∣m,n≥0}L_1 = \{a^n b^n c^m \mid m, n \ge 0\} and L2={ambncn∣m,n≥0}L_2 = \{a^m b^n c^n \mid m, n \ge 0\}.

Which of the following are context-free languages?

I. L1∪L2L_1 \cup L_2
II. L1∩L2L_1 \cap L_2

Choose one option
Official answer and solution
Official answer
A
From
Official GATE 2017 answer key

Solution

Apply context-free language closure properties under union and intersection.

We are given two languages over Σ={a,b,c}\Sigma = \{a, b, c\}:

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

Both L1L_1 and L2L_2 are deterministic context-free languages (DCFLs):

  • For L1L_1, a pushdown automaton pushes aa's, pops on matching bb's, and accepts while reading any number of cc's.
  • For L2L_2, a PDA skips aa's, pushes bb's, and pops on matching cc's.

Statement I: L1∪L2L_1 \cup L_2. Context-free languages are closed under union. If S1S_1 is the start symbol for L1L_1 and S2S_2 for L2L_2, a new start symbol with rule S→S1∣S2S \to S_1 \mid S_2 generates L1∪L2L_1 \cup L_2. Hence, L1∪L2L_1 \cup L_2 is a context-free language.

Statement II: L1∩L2L_1 \cap L_2. The intersection requires both conditions to hold simultaneously:

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

It is a classic result that {anbncn∣n≥0}\{a^n b^n c^n \mid n \ge 0\} is not context-free (provable via the Pumping Lemma for CFLs). Hence, L1∩L2L_1 \cap L_2 is not a context-free language.

Thus, only I is a context-free language.

Final answer

A

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2017 Computer Science and Information Technology (CS) Session 1
Question
38 of 65, printed as CS Q.38
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.