IAE Academy

GATE 2024 CS1 Q.59: solution and answer

GATE 2024 · CS1Q.59 · 2 marks · NAT

Let be a context-free grammar in Chomsky Normal Form with and containing 10 variable symbols including the start symbol . The string is derivable from . The number of steps (application of rules) in the derivation is ______.

See the question in the paper

Answer and solution

ANSWER

The derivation takes 179 steps.

Official answer: 179Source: Official answer key, GATE 2024 CS1 (IISc Bengaluru)

  1. In Chomsky Normal Form every production is either (two variables) or (one terminal).

  2. The string has length .

  3. Each rule adds one terminal and no other symbol is ever turned into a terminal. So exactly rules of this kind are used, one for each terminal of .

  4. Each rule replaces one symbol by two, so it raises the length of the sentential form by exactly . Rules leave the length unchanged. We start from the single symbol (length ) and end at length , so exactly rules of the form are used.

  5. Total number of steps .

  6. The count depends only on . The number of variables (10) and the particular derivation do not change it.

KEY IDEA

In a CNF grammar, deriving a string of length always takes exactly rules and rules , so steps in all.

WATCH OUT FOR

Counting only the binary rules, or only the terminal rules. Another slip is trying to use the number of variables (10) or the shape , neither of which affects the count.

From the GATE 2024 CS1 paper. Every question of this paper · Download the full paper · All 9 CFG & PDA questions, with notes

More CFG & PDA questions