GATE Computer ScienceVery hardGATE CS (PYQ pattern)

In the grammar S → AB | aC | b; A → a | aE; B → bB | bD; C → c | cC; D → dD; E → e (start S), how many variables are useless (not appearing in any derivation of a terminal string from S)?

  1. A. 2
  2. B. 3
  3. C. 5
  4. D. 4

Correct answer: D. 4

Non-generating: D (only dD) and hence B (bB, bD). Deleting them removes S → AB, and then A and E are no longer reachable from S. Useless: A, B, D, E = 4. Checking reachability before removing non-generating symbols (A, E still look reachable) gives the trap 2.

More Theory of Computation questions

Exams that ask this topic