Explain Union and Intersection of Regular languages with CFL

Data Structure AlgorithmsComputer ScienceComputers

We know that the languages accepted by finite automata (FA) are called regular languages and the languages accepted by push down automata (PDA) are called context free languages (CFG).

Closure of CFLs under Union

CFL is the short form for Context Free Language. Here the CFL is as follows −

G = (V, Σ, R, S) such that L(G) = L(G1) ∪ L(G2)

Thus,

  • V = V1 ∪ V2 ∪ {S} (the three sets are disjoint)

  • Σ = Σ1 ∪ Σ2

  • R = R1 ∪ R2 ∪ {S → S1|S2}

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

Let’s L1 = {0*1*} is a regular language and

        L2 = {0^n1^n |n>=0} be a context free

And let L=L1 ∪ L2 be the union of both these languages. In the problem, it is given 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.

Intersection of Regular language with CFG

We know that all regular languages are subset of CFG .

It is easy to understand the union operation and we also proved that union of regular language with context free language generates a context free language.

Now coming to intersection,

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

Example

L1 = {0*1*} is a regular language and

L2 = {0^n1^n |n>=0} is a CFL

The intersection of two languages is as follows −

L= L1 ∩ L2

It results in the following −

L={0^n1^n | n>=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.

raja
Published on 15-Jun-2021 11:23:53
Advertisements