The Wayback Machine - https://web.archive.org/web/20240607081829/https://www.geeksforgeeks.org/union-and-intersection-of-regular-languages-with-cfl/
Open In App

Union and Intersection of Regular languages with CFL

Last Updated : 20 Nov, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

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


Previous Article
Next Article

Similar Reads

Regular Expressions, Regular Grammar and Regular Languages
As discussed in Chomsky Hierarchy, Regular Languages are the most restricted types of languages and are accepted by finite automata. Regular Expressions Regular Expressions are used to denote regular languages. An expression is regular if: ? is a regular expression for regular language ?.? is a regular expression for regular language {?}.If a ? ? (
6 min read
Various Properties of context free languages (CFL)
Context-Free Language (CFL) is a language which is generated by a context-free grammar or Type 2 grammar(according to Chomsky classification) and gets accepted by a Pushdown Automata. Some very much important properties of a context-free language is: Regularity- context-free languages are Non-Regular PDA language. Closure properties : The context-f
2 min read
Theory of Computation | Regular languages and finite automata | Question 2
What is the complement of the language accepted by the NFA shown below? (A) A (B) B (C) C (D) D Answer: (B) Explanation: Quiz of this QuestionPlease comment below if you find anything wrong in the above post
1 min read
Closure properties of Regular languages
Closure properties on regular languages are defined as certain operations on regular language that are guaranteed to produce regular language. Closure refers to some operation on a language, resulting in a new language that is of the same "type" as originally operated on i.e., regular. Regular languages are closed under the following operations: Co
4 min read
Star Height of Regular Expression and Regular Language
The star height relates to the field of theoretical of computation (TOC). It is used to indicate the structural complexity of regular expressions and regular languages. Here complexity, relates to the maximum nesting depth of Kleene stars present in a regular expression. It may be noted here that a regular language may be represented by regular exp
6 min read
Regular grammar (Model regular grammars )
Prerequisites: Chomsky hierarchy Type-3 grammar/regular grammar: Regular grammar generates regular language. They have a single non-terminal on the left-hand side and a right-hand side consisting of a single terminal or single terminal followed by a non-terminal. The productions must be in the form: A â‡Ē xB A â‡Ē x A â‡Ē Bx where A, B ∈ Variable(V) and
5 min read
Recursive and Recursive Enumerable Languages in TOC
Recursive Enumerable (RE) or Type -0 Language RE languages or type-0 languages are generated by type-0 grammars. An RE language can be accepted or recognized by Turing machine which means it will enter into final state for the strings of language and may or may not enter into rejecting state for the strings which are not part of the language. It me
5 min read
Ambiguity in Context free Grammar and Context free Languages
Before reading this article, we recommend you to first read about Pushdown Automata and Context Free Languages. Suppose we have a context free grammar G with production rules : S -> aSb | bSa | SS | e Left Most Derivation (LMD) and Derivation Tree : Leftmost derivation of a string from starting symbol S is done by replacing leftmost non-terminal
5 min read
Ambiguity in Context free Grammar and Context free Languages
Prerequisite - Pushdown Automata and Context Free Languages . Suppose we have a context free grammar G with production rules: S->aSb|bSa|SS|? Left most derivation (LMD) and Derivation Tree: Leftmost derivation of a string from starting symbol S is done by replacing leftmost non-terminal symbol by RHS of corresponding production rule. For example
4 min read
Intersection process of two DFAs
Prerequisite - Design a Finite automata Let's understand the intersection of two DFA with an example. Designing a DFA for the set of string over {0, 1} such that it ends with 01 and has even number of 1's. There two desired language will be formed: L1= {01, 001, 101, 0101, 1001, 1101, ....} L2= {11, 011, 101, 110, 0011, 1100, .....}L = L1 and L2 =
2 min read