Skip to content
Official PYQ · 1992

GATE CS 1992 Q02 — Parsing (LL, LR)

Explain with AI

If GG is a context free grammar and ww is a string of length ll in L(G)L(G), how long is a derivation of ww in GG, if GG is in Chomsky normal form?

Choose one option
View worked solution

Answer: C

A Context-Free Grammar (CFG) in Chomsky Normal Form (CNF) has production rules restricted to the following forms:

  1. A→BCA \rightarrow BC (where BB and CC are non-terminals)
  2. A→aA \rightarrow a (where aa is a terminal)

Let ww be a string of length ll (l≥1l \ge 1) derived from the start symbol SS. We can determine the number of steps in the derivation as follows:

  • Step 1: Generating ll non-terminals
    We start with a single non-terminal (the start symbol SS). Each application of a production rule of the form A→BCA \rightarrow BC replaces one non-terminal with two, thereby increasing the total number of symbols in the sentential form by exactly 11.
    To grow the sentential form from 11 symbol to ll non-terminals, we must apply these rules exactly: Number of branching steps=l−1\text{Number of branching steps} = l - 1
  • Step 2: Converting non-terminals to terminals
    Once we have a sentential form consisting of ll non-terminals, we must replace each non-terminal with a terminal using rules of the form A→aA \rightarrow a. Since there are ll non-terminals, this requires exactly ll steps: Number of terminal substitution steps=l\text{Number of terminal substitution steps} = l

Adding these together, the total length of the derivation is:

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

Example:
For a string of length l=2l = 2 (e.g., abab):

  1. S→ABS \rightarrow AB (1 step)
  2. A→aA \rightarrow a (2 steps)
  3. B→bB \rightarrow b (3 steps)
Here, the derivation length is 33, which matches 2(2)−1=32(2) - 1 = 3.

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

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