Union and Intersection of Regular languages with CFL (original) (raw)

Last Updated : 13 Apr, 2026

Context-Free Languages (CFLs) are atopic in automata theory, generated by context-free grammars (CFGs) and recognized by pushdown automata (PDAs). Understanding their closure properties helps determine which operations preserve the context-free nature of a language. While CFLs are closed under some operations, they are not closed under others. Regular languages, in comparison, are simpler and are recognized using finite automata or regular expressions.

Union of Regular language with CFG

If all regular languages are context free then union of both results is also a context-free language.

**Example 1

We know that every regular language is context-free.

So, obviously we can say the union of two always results in context-free language. Because the union of two context-free languages is a context-free language.

Hence proved.

**Example 2

All strings with only a’s:
RL = { a, aa, aaa, ... }

Strings with the same number of a’s and b’s:
CFL = { ab, aabb, ababab, ... }

Union for the above two will be all strings that are either all a’s OR have equal a’s and b’s

Example strings in the result:

So, obviously we can say the union of two always results in context-free language

CFL

RL and CFL

Note: The intersection of a regular and a context-free language always result in a context-free language.

Example 1

The intersection of two languages is as follows −

So, finally it is concluded that the intersection of regular language and context free language generates a context free language.

**Example 2

All strings with only a’s:
RL = { a, aa, aaa, ... }

Strings with the same number of a’s and b’s:
CFL = { ab, aabb, ababab, ... }

Intersection contains strings that start with a AND have equal a’s and b’s

Example strings in the result:

You can take more such examples and verify that the union and intersection of a regular language and a context-free language always results in a context-free language.

Union vs. Intersection

Features **Union ( ∪ ) **Concatenation ( . )
**Meaning Combines strings from either language Joins strings of first language with second
**Form of Result String belongs to L₁ or L₂ String is of form xy, where x ∈ L₁ and y ∈ L₂
**Order Importance No order (choice-based) Order matters (L₁ before L₂)
**Example Structure Either pattern A or pattern B Pattern A followed by pattern B
**Automata View PDA chooses between paths PDA processes in two stages
**Dependency Independent Sequential dependency