StreakPeaked· Practice

ExamsGATETechnical

Consider the following context-free grammars: G1: S → aS|B, B → b|bB G2: S → aA|bB, A → aA|B|ε, B → bB|ε Which one of the following pairs of languages is generated by G1 and G2, respectively?

  1. {a^m bⁿ | m > 0 or n > 0} and {a^m bⁿ | m > 0 and n > 0}
  2. {a^m bⁿ | m > 0 and n > 0} and {a^m bⁿ | m > 0 or n > 0}
  3. {a^m bⁿ | m ≥ 0 or n > 0} and {a^m bⁿ | m > 0 and n > 0}
  4. {a^m bⁿ | m ≥ 0 and n > 0} and {a^m bⁿ | m > 0 or n > 0}

Correct answer: {a^m bⁿ | m ≥ 0 and n > 0} and {a^m bⁿ | m > 0 or n > 0}

Solution

The correct option accurately describes the languages generated by the grammars: G1 allows for any number of 'a's followed by at least one 'b', while G2 requires at least one 'a' or one 'b', ensuring that both languages have the specified conditions on the counts of 'a's and 'b's.

Related GATE Technical questions

⚔️ Practice GATE Technical free + battle 1v1 →