Skip to content
Official PYQ · 2016

GATE CS 2016 Set 1 Q16 — Context-free Grammars and Push-down Automata

Explain with AI

Which of the following languages is generated by the given grammar?

S→aS∣bS∣εS \rightarrow aS \mid bS \mid \varepsilon

Choose one option
View worked solution

Answer: D

The given grammar is:

S→aS∣bS∣εS \rightarrow aS \mid bS \mid \varepsilon

Let's analyze the language generated by this grammar:

  • The production S→εS \rightarrow \varepsilon allows generating the empty string (ε\varepsilon).
  • The productions S→aSS \rightarrow aS and S→bSS \rightarrow bS allow us to prepend either 'aa' or 'bb' to any string generated by SS.

By repeatedly applying these productions, we can generate any arbitrary sequence of 'aa's and 'bb's of any length. For example, to generate the string bbabba:

S⇒bS⇒bbS⇒bbaS⇒bbaS \Rightarrow bS \Rightarrow bbS \Rightarrow bbaS \Rightarrow bba

Thus, the language generated by the grammar is the set of all possible strings over the alphabet {a,b}\{a, b\}, which is represented by {a,b}∗\{a, b\}^*.

Why other options are incorrect:

  • Option A: {anbm∣n,m≥0}\{ a^nb^m \mid n,m \geq 0\} represents strings where all aa's must precede all bb's. However, the grammar can generate strings like baba, which do not belong to this language.
  • Option B: This language only contains strings with an equal number of aa's and bb's. The grammar can easily generate strings like aa or aabaab, which have unequal counts.
  • Option C: This language does not contain strings like abaaba or babbab, which are easily generated by the grammar.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Context-free Grammars and Push-down Automata questions