GATE / CS ARCHIVE

GATE CSE 2024 SET 1 / QUESTION 59

Count productions in a CNF derivation

Theory of Computation · Context-Free Grammars & Languages · Full GATE CSE 2024 Set 1 paper

GATE 2024 Set 1, Q59 2 marks · NAT
Report issue

Context-Free Grammars & Languages

Question 59, GATE 2024: A context-free grammar in Chomsky Normal Form has terminals {a,b,c} and 10 variables including start symbol S. It derives w=a³⁰b³⁰c³⁰. How many rule applications occur in a derivation S⇒*w?
Tap to enlarge
Answer & solution

Official answer: 179

Approach: In Chomsky Normal Form, a nonempty derivation uses binary-variable rules A→BC and terminal rules A→a. Count each kind using the final word length.
1. The word contains 30+30+30=90 terminal symbols. Each requires exactly one terminal-producing rule application, so there are 90 such applications.
2. Initially there is one variable occurrence. Each binary rule replaces one variable with two and therefore increases the total number of current symbol occurrences by one. Terminal rules replace one symbol with one and do not change that total.
3. To grow from one symbol to a final string of 90 symbols requires exactly 89 binary-rule applications. Equivalently, the variable branching tree is full binary with 90 leaves and 89 internal branching nodes.
4. Total rule applications =90+89=179.
Answer: 179. The ten available variable names can be reused and do not bound the number of variable occurrences. Derivation order does not change these counts; the CNF epsilon exception is irrelevant to this nonempty word.

Original paper, page 34 · Answer key