GATE / CS ARCHIVE

GATE CSE 2024 SET 2 / QUESTION 52

Count terminals by production applications

Theory of Computation · Context-Free Grammars & Languages · Full GATE CSE 2024 Set 2 paper

GATE 2024 Set 2, Q52 2 marks · MSQ
Report issue

Context-Free Grammars & Languages

Question 52, GATE 2024: Grammar S→aS | aSbS | c generates w. Let na,nb,nc count the respective terminals in w. Which always hold? A na>nb; B na>nc−2; C nc=nb+1; D nc=2nb.
Tap to enlarge
Select all that apply
Answer & solution

Official answer: B, C

Approach: Count how each production changes both the terminal totals and the outstanding nonterminals.

1. Derivation. Let u count applications of S→aS and v count applications of S→aSbS. Then na=u+v and nb=v. A derivation starts with one S; unary rules leave the number of outstanding S unchanged, binary rules increase it by one, and S→c decreases it by one. Thus nc=v+1, proving C. Also na≥v=nc−1>nc−2, proving B. A fails for w=c, where both a and b counts are 0; D also fails for c, whose c count is 1 and b count 0.

2. Explanation and checks. Each binary rule contributes one b and creates one additional S requiring eventual termination by a c-rule. Starting with one S therefore requires exactly one more terminating c-rule than binary rules. Unary aS rules can add any extra a’s without changing b or c counts. Consequently na−nb equals their nonnegative number; it may be zero, so A’s strict inequality is too strong. In B the weaker strict bound still holds because na≥nc−1 is an integer stronger than na>nc−2.

Original paper, page 36 · Answer key