GATE / CS ARCHIVE

GATE CSE 2016 SET 1 / QUESTION 42

GATE CSE 2016 Set 1 Q42

Theory of Computation · Context-Free Grammars & Languages · Full GATE CSE 2016 Set 1 paper

GATE 2016 Set 1, Q42 2 marks · MCQ
Report issue

Context-Free Grammars & Languages

Question 42, GATE 2016: Consider grammars G1:S→aS|B, B→b|bB; and G2:S→aA|bB, A→aA|B|ε, B→bB|ε. All options describe languages {a^m b^n} with nonnegative integer exponents. Which pair of constraints corresponds to G1,G2 respectively? A:(m>0 or n>0),(m>0 and n>0). B:(m>0 and n>0),(m>0 or n≥0). C:(m≥0 or n>0),(m>0 and n>0). D:(m≥0 and n>0),(m>0 or n>0).
Tap to enlarge
Your answer
Answer & solution

Official answer: D

G1 emits any number of initial a symbols, then at least one b, so its language is am bn with m≥0, n>0. G2 chooses an initial a or b, then permits all remaining a symbols before its b symbols; it generates every nonempty am bn and not epsilon. Thus m>0 or n>0, giving D.

In G1 the only way to eliminate S is to enter B, and B has no ε rule, so a b is compulsory. In G2 the first production emits a or b, ruling out ε; after that, ε rules allow stopping. Once a derivation enters B, it emits only b symbols, so neither grammar can place an a after a b. Witnesses distinguish boundaries: b is in both languages, a is in G2 only, and ε is in neither. These tests select the inequalities in D.

Original paper, page 16 · Answer key