GATE Computer ScienceHardGATE CS (PYQ pattern)

A grammar has only rules of the forms A → BC, A → BCD (three variables) and A → a. A parse tree of a string of length 9 uses exactly two rules of the form A → BCD. How many internal (variable) nodes does the tree have?

  1. A. 17
  2. B. 15
  3. C. 13
  4. D. 16

Correct answer: B. 15

There are 9 nodes using A → a. Counting variable leaves of the tree above them: starting from 1, each binary rule adds 1 and each ternary rule adds 2, so 1 + b + 2·2 = 9 gives b = 4 binary nodes. Internal nodes = 9 + 4 + 2 = 15 (17 = 2·9 − 1 is the pure CNF answer).

More Theory of Computation questions

Exams that ask this topic