Question

Let L1,L2L_1, L_2 be any two context-free languages and RR be any regular language. Then which of the following is/are CORRECT?

I. L1∪L2L_1 \cup L_2 is context-free.
II. L1‾\overline{L_1} is context-free.
III. L1−RL_1 - R is context-free.
IV. L1∩L2L_1 \cap L_2 is context-free.

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

Solution

Apply known closure properties of Context-Free Languages (CFLs) under set operations.

Evaluate each statement:

  • Statement I (L1∪L2L_1 \cup L_2 is context-free): Context-free languages are closed under union. If S1,S2S_1, S_2 are start symbols of grammars for L1,L2L_1, L_2, we can introduce S→S1∣S2S \to S_1 \mid S_2. Thus, Statement I is CORRECT.
  • Statement II (L1‾\overline{L_1} is context-free): CFLs are not closed under complementation. For example, L={anbncn∣n≥1}L = \{a^n b^n c^n \mid n \ge 1\} is not context-free, but its complement L‾\overline{L} is context-free. Thus, the complement of a CFL is not necessarily context-free. Statement II is INCORRECT.
  • Statement III (L1−RL_1 - R is context-free): Note that L1−R=L1∩R‾L_1 - R = L_1 \cap \overline{R}. Since RR is regular, its complement R‾\overline{R} is also regular. The intersection of a context-free language with a regular language is always context-free. Thus, Statement III is CORRECT.
  • Statement IV (L1∩L2L_1 \cap L_2 is context-free): CFLs are not closed under intersection. For instance, L1={anbncm}L_1 = \{a^n b^n c^m\} and L2={ambncn}L_2 = \{a^m b^n c^n\} are both CFLs, but L1∩L2={anbncn}L_1 \cap L_2 = \{a^n b^n c^n\} is not context-free. Statement IV is INCORRECT.

Therefore, statements I and III only are correct, which corresponds to option B.

Final answer

B

Common trap

Assuming CFLs are closed under set difference; they are closed under difference with a regular language, but not under difference with another CFL.

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 2
Question
4 of 65, printed as CS Q.4
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.