Question

Consider the following context-free grammar GG.

S→abaABAbbaS \rightarrow abaABAbba
A→aaBBAb∣bBabaaA \rightarrow aaBBAb \mid bBabaa
B→aBb∣abB \rightarrow aBb \mid ab

In the above grammar, SS is the start symbol, aa and bb are terminal symbols, and AA and BB are non-terminal symbols.

Let L(G)L(G) be the language generated by the grammar GG. For a string s∈L(G)s \in L(G), let n1(s)n_1(s) be the number of aa's in ss and n2(s)n_2(s) be the number of bb's in ss.

Which of the following statements is/are true?

Choose every correct option
Official answer and solution
Official answer
B and D
From
Official GATE 2026 answer key

Solution

Count the number of terminal aa's and bb's introduced by each production rule in GG.

Let (Δa,Δb)(\Delta a, \Delta b) denote the number of terminal aa's and bb's directly introduced by each production rule:

  • S→abaABAbbaS \rightarrow abaABAbba: (Δa,Δb)=(3,3)(\Delta a, \Delta b) = (3, 3), which satisfies Δb≤Δa≤2Δb\Delta b \le \Delta a \le 2\Delta b.
  • A→aaBBAbA \rightarrow aaBBAb: (Δa,Δb)=(2,1)(\Delta a, \Delta b) = (2, 1), which satisfies Δb≤Δa≤2Δb\Delta b \le \Delta a \le 2\Delta b.
  • A→bBabaaA \rightarrow bBabaa: (Δa,Δb)=(3,2)(\Delta a, \Delta b) = (3, 2), which satisfies Δb≤Δa≤2Δb\Delta b \le \Delta a \le 2\Delta b.
  • B→aBbB \rightarrow aBb and B→abB \rightarrow ab: (Δa,Δb)=(1,1)(\Delta a, \Delta b) = (1, 1), which satisfies Δb≤Δa≤2Δb\Delta b \le \Delta a \le 2\Delta b.

Since every production rule in GG introduces at least as many aa's as bb's (Δa≥Δb\Delta a \ge \Delta b) and at most twice as many aa's as bb's (Δa≤2Δb\Delta a \le 2\Delta b), summing over all derivation steps of any string s∈L(G)s \in L(G) yields:

n2(s)≤n1(s)≤2n2(s)n_2(s) \le n_1(s) \le 2n_2(s)

Thus (B) and (D) are true, while (A) and (C) are false.

Final answer

Options (B), (D)

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2026 Computer Science and Information Technology - Session 1 (CS1)
Question
52 of 65
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.