GATE / CS ARCHIVE

GATE CSE 2016 SET 1 / QUESTION 16

GATE CSE 2016 Set 1 Q16

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

GATE 2016 Set 1, Q16 1 mark · MCQ
Report issue

Context-Free Grammars & Languages

Question 16, GATE 2016: Which language is generated by S→aS | bS | ε? A: {a^n b^m:n,m≥0}. B: All words over {a,b} with equal numbers of a and b. C: {a^n:n≥0} union {b^n:n≥0} union {a^n b^n:n≥0}. D: {a,b}*.
Tap to enlarge
Your answer
Answer & solution

Official answer: D

At every step S can emit either a or b and recurse, then terminate with epsilon. Every finite binary-alphabet word, including epsilon, is generated, giving {a, b}*, D.

For any desired word w, choose the production beginning with its next character repeatedly, then use S→ε after its final character. For example baba follows S⇒bS⇒baS⇒babS⇒babaS⇒baba. Conversely, every production emits only a or b, so no other alphabet symbols can appear. This two-direction argument proves equality with {a,b}*, rather than merely showing a few example strings are generated. The ε production explicitly includes the empty word.

Original paper, page 8 · Answer key