- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Construct a pair of languages by using CFG
Problem
Consider the following context-free grammars (CFG) and find the pairs of languages which can be generated by Gl and G2 respectively.
Solution
Consider the following CFG −
G1 : S->aS|B , B->b l bB
G2: S->aA | bB , A->aA| B | ε , B->bB | ε
Now, we can generate the language as follows. First consider G1 as shown below
Consider G1: S->aS|B B->b|bB Using S->B ->b b can be generated Using S->B ->bB ->bb bb can be generated Using S->aS ->aB ->ab ab can be generated Using S->aS ->aB ->abB ->abb abb can be generated
As we can see, the number of a's can be zero or more but the number of b's is always greater than zero.
Therefore, the result will be as follows −
L(G1)= {ambn | m>=0 & n>0 }
Now, consider G2 as shown below −
Consider G2: S->aA|bB A->aA|B| ε B->bB| ε Using S->aA ->a a can be generated Using S->bB ->b b can be generated Using S->aA ->aaA ->aa aa can be generated Using S->bB ->bbB ->bb bb can be generated Using S->aA ->aB ->abB ->abb abb can be generated
As we can see, either a or b must be greater than zero.
Therefore, the result will be as follows −
L(G2)= {aman |m>0 or n>0}
Advertisements