Let \(𝐺=(𝑉,𝑇,𝑆,𝑃)\) be any context-free grammar without any \(πœ†-\)…

2019

LetΒ \(𝐺=(𝑉,𝑇,𝑆,𝑃)\)Β be any context-free grammar without anyΒ \(πœ†-\)Β productions or unit productions. LetΒ \(𝐾\)Β be the maximum number of symbols on the right of any production inΒ \(𝑃\). The maximum number of production rules for any equivalent grammar in Chomsky normal form is given by:

  1. A.

    \((K-1) \mid P \mid + \mid T \mid -1\)

  2. B.

    \((K-1) \mid P \mid + \mid T \mid\)

  3. C.

    \(K \mid P \mid + \mid T \mid -1\)

  4. D.

    \(K \mid P \mid + \mid T \mid\)

Attempted by 8 students.

Show answer & explanation

Correct answer: B

Goal: derive an upper bound on the number of productions in an equivalent Chomsky Normal Form (CNF) grammar for a grammar without Ξ»-productions or unit productions, where K is the maximum length of any right-hand side and |P| is the number of productions.

  • Binarization of long right-hand sides: A production with r symbols on the right-hand side (r β‰₯ 2) can be converted to a chain of binary productions. This replacement yields r-1 productions in the CNF grammar (for example: A β†’ X1 X2 … Xr becomes A β†’ X1 Y1, Y1 β†’ X2 Y2, …, Y_{r-2} β†’ X_{r-1} Xr).

  • Sum over all productions: If the original productions have lengths r1, r2, …, r_|P|, the total number of productions after binarization is βˆ‘(ri βˆ’ 1) = (βˆ‘ri) βˆ’ |P|. Since each ri ≀ K, this is at most (K βˆ’ 1)|P|.

  • Handling terminals inside longer right-hand sides: For any terminal that appears in the middle of a longer right-hand side, introduce a single new nonterminal that produces that terminal. At most |T| such new productions of the form A_t β†’ a are needed (one per terminal).

Conclusion: combining the binarization count and the terminal replacements gives an upper bound of (K βˆ’ 1)|P| + |T| productions in an equivalent CNF grammar.

Note: A β†’ a productions that already have a single terminal on the right-hand side are already in CNF and do not need further modification; the |T| term covers the extra productions introduced for terminals that occur inside longer right-hand sides.

A video solution is available for this question β€” log in and enroll to watch it.

Explore the full course: Mppsc Assistant Professor