GATE / CS ARCHIVE

GATE CSE 1994 / QUESTION 20

Length of a strict CNF derivation

Theory of Computation · Context-Free Grammars & Languages · Full GATE CSE 1994 paper

GATE 1994, Q20 5 marks · Descriptive
Report issue

Context-Free Grammars & Languages

Question 20, GATE 1994: A CFG has only productions A→BC and A→a. For a generated terminal word of length ℓ, how many production applications occur in its derivation? GateForum omits the symbol after “length”; GFG supplies ℓ.
Tap to enlarge
Answer & solution

Answer: 2ℓ−1 production applications for ℓ≥1. (no official key was published)

Each terminal of the final word is introduced by exactly one A→a production: no other production introduces terminals, and no production subsequently removes them. Hence there are exactly ℓ terminal-producing steps. Start with one nonterminal. Each A→BC application increases the number of nonterminals by one, whereas each A→a decreases it by one. If b is the number of binary applications, the final nonterminal count is 1+b−ℓ=0, so b=ℓ−1. The total number of applications is b+ℓ=2ℓ−1.

The same result follows by viewing the nonterminal portion of the parse tree as a full binary tree: ℓ terminal-producing leaves require ℓ−1 binary internal nodes. The count is independent of which nonterminal is expanded first, of leftmost versus rightmost derivation, and of ambiguity of the grammar. For ℓ=1 there is just the single terminal production, agreeing with the formula.

This is a count of steps, not a count of sentential forms: including both the initial symbol and final word gives 2ℓ sentential forms. Under the strict production forms stated here ε cannot be generated. If a different CNF convention permits S→ε, its ε derivation is a separate one-step exception, not an application of the formula at ℓ=0.

Original paper, page 6