Let \(𝐺 = (𝑉,𝑇,𝑆,𝑃)\) be a context-free grammer such that every one of…

2017

LetΒ \(𝐺 = (𝑉,𝑇,𝑆,𝑃)\)Β be a context-free grammer such that every one of its productions is of the formΒ \(𝐴 β†’ 𝑣,\) withΒ \(βˆ£π‘£βˆ£ = 𝐾 > 1\). The derivation tree for anyΒ \(π‘ŠβˆˆπΏ(𝐺)\)Β has a heightΒ \(β„Ž\)Β such thatΒ 

  1. A.

    \(\log_{K} \mid W \mid \leq h\leq \log_{K} \left (\frac{ \mid W \mid-1}{K-1} \right ) \\\)

  2. B.

    \(\log_{K} \mid W \mid \leq h \leq \log_{K} \left ( K \mid W \mid \right) \\\)

  3. C.

    \(\log_{K} \mid W \mid \leq h \leq K \log_{K} \mid W \mid \\\)

  4. D.

    \(\log_{K}|W \mid \leq h \leq \left (\frac{ \mid W \mid – 1}{K-1} \right)\)

Attempted by 11 students.

Show answer & explanation

Correct answer: D

Correct inequality: log_K |W| ≀ h ≀ (|W|-1)/(K-1)

Reason:

  • Let I be the number of internal (variable) nodes in the derivation tree. Each internal node has K children, so the number of leaves (terminals) |W| satisfies |W| = I*(K-1) + 1.

  • Lower bound: For a tree of height h the maximum possible number of leaves is that of a full K-ary tree, namely K^h. Thus |W| ≀ K^h, which implies h β‰₯ log_K |W|.

  • Upper bound: For fixed |W| the height is maximized when the tree is as unbalanced as possible (a chain of internal nodes). In that case each internal node contributes exactly (K-1) leaves, so I = h and |W| = h*(K-1) + 1. Solving gives h = (|W|-1)/(K-1), so h ≀ (|W|-1)/(K-1).

  • Combining these bounds yields the stated inequality: log_K |W| ≀ h ≀ (|W|-1)/(K-1).

Explore the full course: Mppsc Assistant Professor