- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Prove that CFL is closed under union and star but not under intersection?

CFL refers to Context Free Language in the theory of computation (TOC). Let us now understand how CFL is closed under Union.

**CFL is closed under UNION**

If L1 and L2 are CFL’s then L1 U L2 is also CFL.

Let L1 and L2 are generated by the Context Free Grammar (CFG).

G1=(V1,T1,P1,S1) and G2=(V2,T2,P2,S2) without loss of generality subscript each non terminal of G1 and a1 and each non terminal of G2 with a2 (so that V1∩V2=φ).

Subsequent steps are used production entirely from G1 or from G2.

Each word generated thus is either a word in L1 or L2.

**Example**

Let L1 be palindrome, defined by:

S->aSa|bSb|a|b|^

Let L2 be {anbn|n>=0} defined by −

S->aSb|^

Then the union language is defined as −

S->S1|S2

S1->aS1a|bS1b|a|b|^

S2->aS2b|^

**CFG are closed under KLEENE star**

Now, let us understand how CFG is closed under a star.

**Proof**

If L1 is a CFL then L1* is a CFL.

Let L1 be generated by CFG G1=(V1,T1,P1,S1) without loss of generality subscript each non-terminal of G1 with a1.

Define the CFG, G generates L1* as −

G=(v1 U {S}, T1, P1 U {S->S1S{^},S}

Each word generated either ^ or the same sequence of words in L1.

Every word in L1* can be generated by G.

**Example**

Let L1 be {anbn|n>=0} defined by S->aSb|^

Then L1* generated as:

S->S1S|^

S1->aS1b|^

**CFGs are not closed under intersection**

Let us now understand how CFG cannot be closed under intersection.

**Proof**

If L1 and L2 are CFL’s then L1∩L2 may not be a CFL.

L1={anbnam|n,m>=0} is generated by the CFG −

S->XA

X->aXb|^

A->Aa|^

L2-{anbmam|n,n>=0} is generated by CFG −

S->AX

X->aXb|^

A->Aa|^

L1∩L2 ={anbnan|n>=0} which is not to be a CFL.

- Related Questions & Answers
- Explain the Closure Under Kleene Star of CFL in TOC?
- Show that the set of recursive languages is closed under reversal?
- Explain Union and Intersection of Regular languages with CFL
- How to show that the regular language is closed under the complementary operation?
- Explain the context free language closure under union operation?
- What is overriding and overloading under polymorphism in java?
- Perform MySQL delete under safe mode?
- What is the performance of ethernet and token ring under light traffic load?
- Different options under SAP HANA System Administration
- Switch ownership option under SAP HANA Perspective
- Find duplicates under given constraints in C++
- Find Union and Intersection of two unsorted arrays in C++
- Activation modes under SAP HANA Modeler Activate option
- Details maintained under Name server in SAP HANA
- Information available under System Monitor in SAP HANA