Union and Intersection of Regular languages with CFL

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

  • Let’s L1 = {0*1*} is a regular language and L2 = {0m1m | m>=0} be a context free
  • Let L=L1 ∪ L2 be the union of both these languages. In the problem, L = {0*1*} is a regular language.

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:

  • a → in RL
  • aa → in RL
  • ab → in CFL
  • aabb → in CFL
  • abab → in CFL

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

  • L1 = {0*1*} is a regular language and
  • L2 = {0m1m | m>=0} is a CFL

The intersection of two languages is as follows −

  • L= L1 ∩ L2
  • L={ 0m1m | m>=0} which is context-free .

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:

  • ab → starts with a and a = b
  • aabb → starts with a and a = b
  • abab → starts with a and a = b

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

FeaturesUnion ( ∪ )Concatenation ( . )
MeaningCombines strings from either languageJoins strings of first language with second
Form of ResultString belongs to L₁ or L₂String is of form xy, where x ∈ L₁ and y ∈ L₂
Order ImportanceNo order (choice-based)Order matters (L₁ before L₂)
Example StructureEither pattern A or pattern BPattern A followed by pattern B
Automata ViewPDA chooses between pathsPDA processes in two stages
DependencyIndependentSequential dependency
Comment

Explore