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?
- A. 17
- B. 15
- C. 13
- 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
- Which of the following computational models is strictly LESS powerful than a standard single-tape deterministic Turing machine?
- Which of the following problems for a linear bounded automaton (LBA) M and a string w is decidable?
- Let L = { aⁿbⁿ : 0 ≤ n ≤ 3 } over {a, b}. How many Myhill–Nerode equivalence classes does L have (equivalently, how many states does its…
- Which of the following languages is inherently ambiguous?
- Which of the following languages cannot be accepted by any deterministic pushdown automaton?
- Which of the following languages is context-free?