Skip to content
Official PYQ · 2024

GATE CS 2024 Set 1 Q49 — Parsing (LL, LR)

Explain with AI
Let G=(V,Σ,S,P)G=(V, \Sigma, S, P) be a context-free grammar in Chomsky Normal Form with Σ={a,b,c}\Sigma=\{a, b, c\} and VV containing 1010 variable symbols including the start symbol SS. The string w=a30b30c30w=a^{30} b^{30} c^{30} is derivable from SS. The number of steps (application of rules) in the derivation S→∗wS \rightarrow^* w is __________.
View worked solution

Answer: 179

In a Context-Free Grammar (CFG) in Chomsky Normal Form (CNF), all production rules must be of one of the following forms:

  1. A→BCA \rightarrow BC (where B,CB, C are variables)
  2. A→aA \rightarrow a (where aa is a terminal)

To derive a string ww of length nn (n≥1n \ge 1) from the start symbol SS:

  • We start with 11 variable (SS).
  • Each application of a production of the form A→BCA \rightarrow BC increases the number of variables in the sentential form by exactly 11. To reach a sentential form containing nn variables, we need exactly n−1n - 1 steps.
  • Each of these nn variables must then be replaced by a terminal using a production of the form A→aA \rightarrow a. This requires exactly nn steps.

Thus, the total number of steps (rule applications) in the derivation of any string of length nn is:

Total steps=(n−1)+n=2n−1\text{Total steps} = (n - 1) + n = 2n - 1

For the given string w=a30b30c30w = a^{30} b^{30} c^{30}, the length of the string is:

n=∣w∣=30+30+30=90n = |w| = 30 + 30 + 30 = 90

Substituting n=90n = 90 into the formula:

Number of steps=2(90)−1=180−1=179\text{Number of steps} = 2(90) - 1 = 180 - 1 = 179

Note: The number of variable symbols (10) is extra information and does not affect the number of derivation steps.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Parsing (LL, LR) questions