Skip to content
Official PYQ · 1995

GATE CS 1995 Q2.20 — Context-free Grammars and Push-down Automata

Explain with AI

Which of the following definitions below generate the same language as LL, where L={xnyn such that n≥1}L=\{x^ny^n \text{ such that } n\geq 1 \}?

  1. E→xEy∣xyE \rightarrow xEy\mid xy

  2. xy∣(x+xyy+x y \mid (x^+xyy^+)

  3. x+y+x^+y^+

Choose one option
View worked solution

Answer: A

We analyze each definition to see if it generates the language L={xnyn∣n≥1}L = \{x^n y^n \mid n \ge 1\}:

  • Definition I: The context-free grammar E→xEy∣xyE \rightarrow xEy \mid xy has the base case xyxy (n=1n=1). Each recursive application of E→xEyE \rightarrow xEy adds one xx to the left and one yy to the right, generating exactly xnynx^n y^n for n≥1n \ge 1. Thus, Definition I is correct.
  • Definition II: The expression xy∣(x+xyy+)xy \mid (x^+ x y y^+) generates strings of the form xaybx^a y^b where a,b≥1a, b \ge 1. This includes strings like x2y3x^2 y^3 where the number of xx's and yy's are unequal. Thus, it does not generate LL.
  • Definition III: The regular expression x+y+x^+ y^+ generates all strings with one or more xx's followed by one or more yy's (i.e., xaybx^a y^b for a,b≥1a, b \ge 1). Since the counts of xx and yy do not have to be equal, it does not generate LL.

Therefore, only definition I generates the language LL.

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

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