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 RLaa→ in RLab→ in CFLaabb→ in CFLabab→ in CFL
So, obviously we can say the union of two always results in context-free language

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 withaand a = baabb→ starts witha anda = babab→ starts witha anda = 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
| 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 |