Back to the 2021 paper

Module 2: Context-Free Languages (CFL) and PDA

20212m

If L1L_1 and L2L_2 are CFLs, L1−L2L_1 - L_2 is ____ context-free.

(i) always
(ii) sometimes
(iii) never
(iv) None of the above

Worked SolutionAI Assisted

Answer

Correct Option: (ii) sometimes (i.e., not always — CFLs are not closed under difference)

Explanation

L1−L2=L1∩L2‾L_1 - L_2 = L_1 \cap \overline{L_2}.

  • CFLs are closed under union, concatenation, Kleene star, but NOT under intersection, complement, difference.
  • Since complement of a CFL is not necessarily CFL, difference need not be CFL.

Counterexample:
L1=a∗b∗c∗L_1 = a^*b^*c^* (actually regular, also CFL)
Let L1={anbncm}L_1 = \{a^n b^n c^m\} (CFL) and L2={ambncn}L_2 = \{a^m b^n c^n\} (CFL)
L1∩L2={anbncn}L_1 \cap L_2 = \{a^n b^n c^n\} not CFL.
Then L1−(Σ∗−L2)L_1 - ( \Sigma^* - L_2) style constructions show difference can be non-CFL.

But sometimes it is CFL: e.g., if L2L_2 is regular, then L1−L2=L1∩L2‾L_1 - L_2 = L_1 \cap \overline{L_2} is CFL because CFL ∩ Regular = CFL. So difference is sometimes CFL.

Many textbooks phrase options as:

  • (i) always — false
  • (ii) sometimes / not always closed
  • (iii) never — false (counterexample above shows sometimes)

Hence correct is not necessarily CFL → Option (ii) sometimes (or “not always”). If exam key uses “never”, they mean “not closed”, also acceptable as (iii) in that phrasing — but strictly “sometimes” is precise.

Final Answer

L1−L2L_1 - L_2 is not guaranteed CFL → Not closed → Option (ii) sometimes / not always (exam may list as (iii) never in weaker phrasing).

Similar questions

Budget AppAndroid App

Pocketly on Android

Log daily food, travel, and hostel expenses instantly. Set monthly spending limits and see where your money goes without complex spreadsheets.