Skip to content
Official PYQ · 2017

GATE CS 2017 Set 2 Q04 — Regular and Context-free Languages

Explain with AI

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?

  1. L1∪L2L_1 \cup L_2 is context-free
  2. L1‾\overline{L_1} is context-free
  3. L1−RL_1 - R is context-free
  4. L1∩L2L_1 \cap L_2 is context-free
Choose one option
View worked solution

Answer: B

To determine which statements are correct, let us analyze the closure properties of Context-Free Languages (CFLs):

  • Statement I: L1∪L2L_1 \cup L_2 is context-free.
    CORRECT. Context-free languages are closed under union. If S1S_1 and S2S_2 are the start symbols of the grammars generating L1L_1 and L2L_2 respectively, we can define a new start symbol S→S1∣S2S \to S_1 \mid S_2 to generate L1∪L2L_1 \cup L_2.

  • Statement II: L1‾\overline{L_1} is context-free.
    INCORRECT. CFLs are not closed under complementation. For example, the language L={anbncn∣n≥0}L = \{a^n b^n c^n \mid n \ge 0\} is not context-free, but its complement L‾\overline{L} is context-free.

  • Statement III: L1−RL_1 - R is context-free.
    CORRECT. We can rewrite the set difference as: L1−R=L1∩R‾L_1 - R = L_1 \cap \overline{R} Since RR is a regular language, its complement R‾\overline{R} is also regular. CFLs are closed under intersection with regular languages. Since L1L_1 is a CFL and R‾\overline{R} is regular, their intersection L1∩R‾L_1 \cap \overline{R} is guaranteed to be a CFL.

  • Statement IV: L1∩L2L_1 \cap L_2 is context-free.
    INCORRECT. CFLs are not closed under intersection. For example, L1={anbncm∣n,m≥0}L_1 = \{a^n b^n c^m \mid n, m \ge 0\} and L2={ambncn∣n,m≥0}L_2 = \{a^m b^n c^n \mid n, m \ge 0\} are both CFLs, but their intersection: L1∩L2={anbncn∣n≥0}L_1 \cap L_2 = \{a^n b^n c^n \mid n \ge 0\} is a well-known non-CFL.

Thus, only statements I and III are correct.

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

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