πŸŽ“ Computer Science & Engineering Portal

Master Engineering Disciplines with Structured Notes

Comprehensive academic lecture notes, exam-oriented unit summaries, laboratory manuals, and previous year question papers designed strictly for university students.

πŸ“‘

University Syllabi

AKTU & AICTE aligned semester guidelines.

πŸ“

Exam Question Papers

Previous 5 years solved university papers.

πŸ’‘

Lab Manuals & Viva

Practical codes with outputs & interview Qs.

Core Subjects & Units Hub

Click on any specific unit to immediately view its lecture notes below

Viewing All Lectures

Chomsky's Normal Form (CNF)

Chomsky's Normal Form (CNF)

CNF stands for Chomsky normal form. A CFG(context free grammar) is in CNF(Chomsky normal form) if all production rules satisfy one of the following conditions:

  • Start symbol generating Ξ΅. For example, A β†’ Ξ΅.
  • A non-terminal generating two non-terminals. For example, S β†’ AB.
  • A non-terminal generating a terminal. For example, S β†’ a.

For example:

G1 = {S β†’ AB, S β†’ c, A β†’ a, B β†’ b}  

G2 = {S β†’ aA, A β†’ a, B β†’ c}  

The production rules of Grammar G1 satisfy the rules specified for CNF, so the grammar G1 is in CNF. However, the production rule of Grammar G2 does not satisfy the rules specified for CNF as S β†’ aZ contains terminal followed by non-terminal. So the grammar G2 is not in CNF.

Steps for converting CFG into CNF

Step 1: Eliminate start symbol from the RHS. If the start symbol T is at the right-hand side of any production, create a new production as:

S1 β†’ S  

Where S1 is the new start symbol.

Step 2: In the grammar, remove the null, unit and useless productions. You can refer to the Simplification of CFG.

Step 3: Eliminate terminals from the RHS of the production if they exist with other non-terminals or terminals. For example, production S β†’ aA can be decomposed as:

S β†’ RA  

R β†’ a  

Step 4: Eliminate RHS with more than two non-terminals. For example, S β†’ ASB can be decomposed as:

S β†’ RS  

R β†’ AS  

Example:

Convert the given CFG to CNF. Consider the given grammar G1:

S β†’ a | aA | B  

A β†’ aBB | Ξ΅  

B β†’ Aa | b  

Solution:

Step 1: We will create a new production S1 β†’ S, as the start symbol S appears on the RHS. The grammar will be:

S1 β†’ S  

S β†’ a | aA | B  

A β†’ aBB | Ξ΅  

B β†’ Aa | b  

Step 2: As grammar G1 contains A β†’ Ξ΅ null production, its removal from the grammar yields:

S1 β†’ S  

S β†’ a | aA | B  

A β†’ aBB  

B β†’ Aa | b | a  

Now, as grammar G1 contains Unit production S β†’ B, its removal yield:

S1 β†’ S  

S β†’ a | aA | Aa | b  

A β†’ aBB  

B β†’ Aa | b | a  

Also remove the unit production S1 β†’ S, its removal from the grammar yields:

S0 β†’ a | aA | Aa | b  

S β†’ a | aA | Aa | b  

A β†’ aBB  

B β†’ Aa | b | a 

Step 3: In the production rule S0 β†’ aA | Aa, S β†’ aA | Aa, A β†’ aBB and B β†’ Aa, terminal a exists on RHS with non-terminals. So we will replace terminal a with X:

S0 β†’ a | XA | AX | b  

S β†’ a | XA | AX | b  

A β†’ XBB  

B β†’ AX | b | a  

X β†’ a  

Step 4: In the production rule A β†’ XBB, RHS has more than two symbols, removing it from grammar yield:

S0 β†’ a | XA | AX | b  

S β†’ a | XA | AX | b  

A β†’ RB  

B β†’ AX | b | a  

X β†’ a  

R β†’ XB  

Hence, for the given grammar, this is the required CNF.

Labels: ,

Discussion & Queries (<$I18NNumComments$>):

<$CommentPager$>
<$I18NAtCommentTimeWithPermalink$>, <$I18NCommentAuthorSaid$>

<$BlogCommentBody$>

<$BlogCommentDeleteIcon$>
<$CommentPager$>