![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
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
Generate a CNF for a given context free grammar
Problem
Generate a Chomsky normal form (CNF) for the following context free grammar (CFG).
S->aAa|bBb|e
A->C|a
B->C|b
C->CDE|e
D->A|B|ab
Solution
Follow the steps mentioned below to generate a CNF for the given CFG
Step 1 − Eliminate ∧ -productions
We can delete, erase or ∧ -productions double time repeated.
S --> aAa | bBb | ∧
A --> a | ∧
B --> b | ∧
D --> A | B | ab
Step 2 − Eliminate unit productions in above grammar
Eliminate R.H.S one symbol productions
S --> aDa | bDb
D --> a | b | ab
Step 3 − Eliminate useless symbols
E is a useless symbol from given grammar since it is not derivative in RHS.
S --> aDa | bDb
D --> a | b | ab
Step 4 − Chomsky normal form (CNF)
Get productions whose bodies are mixes of terminals and variables, or consists of more than one terminal
Break up productions in short form as shown below
S --> XYX | ZYZ
S --> XP | ZQ
P --> YX
Q --> YZ
X --> a
Y --> a | b | ab
Z --> b