Closure of Context-Free Languages Under Language Difference (L1L2L_1-L_2)

Closure of Context-Free Languages Under Language Difference (L1L2L_1-L_2)

Verified Sources
Sep 12, 2026

Context-Free Languages: Closure Properties (CFL theory)

Let L1L_1 and L2L_2 be Context-Free Languages (CFLs). Consider the set difference L1L2={xxL1 and xL2}.L_1 - L_2 = \{\,x \mid x\in L_1 \text{ and } x\notin L_2\,\}.

The question asks whether L1L2L_1-L_2 must be context-free in general. The key facts are:

  • CFLs are closed under Intersection with a Regular Language and under Union.
  • CFLs are closed under Complement only via special conditions, but not in general.
  • Since difference can be written as L1L2=L1L2,L_1 - L_2 = L_1 \cap \overline{L_2}, whether L1L2L_1-L_2 is context-free hinges on what happens to L2\overline{L_2} for CFLs and how CFLs behave under intersection with it.

In general, context-free languages are not closed under difference. Therefore the correct choice is (iii) never.

This “never” means: there exist CFLs L1,L2L_1,L_2 such that L1L2L_1-L_2 is not a CFL, so the statement “L1L2L_1-L_2 is always context-free” fails.

Closure chain that forces the answer

Define Language difference: L1L2=L1L2.L_1 - L_2 = L_1 \cap \overline{L_2}.

Now use these closure notions:

  • CFL closure under intersection: CFLs are not closed under intersection with arbitrary CFLs.
  • CFL closure under complement: CFLs are not closed under complement in general.

Together, this implies that there is no guarantee that L1L2L_1 \cap \overline{L_2} is a CFL even when both L1L_1 and L2L_2 are CFLs—hence the answer is (iii) never.

How to reason about $L_1-L_2$ from closure properties

  1. 1
    Step 1

    Use L1L2=L1L2L_1-L_2 = L_1\cap \overline{L_2}.

  2. 2
    Step 2

    If L2\overline{L_2} is not guaranteed to be CFL, then the intersection with L1L_1 is also not guaranteed to be CFL.

  3. 3
    Step 3

    Because closure fails in the general case, there must exist CFLs L1,L2L_1,L_2 where L1L2L_1-L_2 is not CFL.

  4. 4
    Step 4

    Therefore the statement is false for all CFL pairs; the correct option is (iii) never.

Pro Tip

When you see L1L2L_1-L_2, immediately rewrite it as L1L2L_1\cap \overline{L_2}. Then check whether CFLs are closed under complement and intersection in the form you need.

Common confusion

CFLs are closed under several operations (e.g., union). But missing closure under complement/intersection is exactly what breaks difference.

Closure-property logic roadmap

Start with difference

1

Consider L1L2L_1-L_2."

Convert to intersection + complement

2

Use L1L2=L1L2L_1-L_2 = L_1 \cap \overline{L_2}."

Check closure assumptions

3

CFLs are not closed under complement (in general)."

Conclude non-closure

4

So L1L2L_1-L_2 is not guaranteed to be CFL → choose (iii) never."

Answer selection

Correct choice for: If L1L_1 and L2L_2 are CFLs, is L1L2L_1-L_2 CFL?

Quick FAQs

CFL difference closure checkpoints

1 / 4
Question · Term

Rewrite $L_1-L_2$ in terms of intersection/complement

Click to reveal
Answer · Definition

L1L2=L1L2L_1-L_2 = L_1 \cap \overline{L_2}

Knowledge Check

Question 1 of 4
Q1Single choice

If L1L_1 and L2L_2 are context-free languages, L1L2L_1-L_2 is: