# Union and Intersection of Regular languages with CFL

**Prerequisite –** Chomsky Hierarchy, Regular Languages

As we all are aware that languages accepted by **finite automata** are called **regular** languages and those which are accepted by **push down automata** are called **context free** languages But, when it comes to the union or intersection of these two languages some people find it difficult to analyse whether the intersection results in a regular or a context-free language.

The first thing to observe is **every** regular language is actually context-free,the reason is quite simple. One way to call a language regular is by designing its equivalent finite automata or in other words if we can design a finite automata for a particular language then only we can call that language – regular and same exists for context free languages, if it is possible to design a push down automata for a particular language then only it is called context free.

Now a push down automata in simple words is actually a finite automata with a **memory** provided to it as **infinite stack**. What you need to observe that is possible to design a finite automata for a particular language then it is also possible to design its equivalent push down automata what we have to do is just **not to use** the infinite stack available in it. Its that simple. Observe this and finally what will you get is that for every regular language it is possible to design finite automata and thus push down automata. This is the reason why every regular language can also be called context-free or in other words regular languages are subset of context-free languages.

**Union of Regular language with context free language –**

As all regular languages are context-free the union of both results in a context-free language. But it is always good to understand with the help of an example.

Let’s take a language L1 = {0*1*} (regular) and L2 = {0^n1^n |n>=0} (context-free)

And let L=L1 U L2 which will result in union of both these languages and that will be :

L = {0*1*} which is regular language but since every regular language is context-free. So, we can say the union of two always results in context-free language.

**Intersection of Regular language with context-free language –**

Because now we know that all regular languages are subset of context-free there is no problem in understanding the union of two but when we talk about intersection again the answer is context-free language. Yes, the intersection of a regular and a context-free language always result in a context-free language.

Let’s again take the above example in which L1 and L2 are same but now let

L= L1 ∩ L2 which will easily result in

L={0^n1^n | n>=0} which is context-free .

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.

Read Next article – Closure Properties of Context Free Languages

This article is contributed by **Dimpy Varshni**. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

## Please

Loginto comment...