Consider the grammar. S -> SxSxS | ϵ For a string “xxxxxx”, How many total…

Consider the grammar.
S -> SxSxS | ϵ
For a string “xxxxxx”, How many total number of parse tree/s are possible.

Answer: 12Key insight: each application of the rule S -> S x S x S adds two terminal symbols 'x'. Step 1: Determine how many times the rule must be applied. Let k be…

Attempted by 27 students.

Show answer & explanation

Correct answer: 12

Key insight: each application of the rule S -> S x S x S adds two terminal symbols 'x'.

Step 1: Determine how many times the rule must be applied.

  • Let k be the number of times S -> S x S x S is used. Each use contributes 2 x's, so 2k = 6, giving k = 3.

Step 2: Count the number of distinct parse trees for k = 3.

  • Each internal node of the parse tree has exactly three ordered children (a full ordered ternary tree). The number of such trees with k internal nodes is given by the Fuss–Catalan (generalized Catalan) formula:

  • Number = 1/((3-1)k + 1) * binomial(3k, k) = 1/(2k + 1) * C(3k, k).

  • For k = 3: binomial(9, 3) = 84, and 2k + 1 = 7, so the number = 84 / 7 = 12.

Conclusion: There are 12 distinct parse trees that generate the string "xxxxxx".

Explore the full course: Gate Guidance By Sanchit Sir

Loading lesson…