Skip to content
GATEiit

GATE CSE 2026 Session 1 Q52: Counts of a's and b's in strings of a given CFG

Question

Consider the following context-free grammar GG.

S→abaABAbbaA→aaBBAb∣bBabaaB→aBb∣ab\begin{aligned} S &\to abaABAbba \\ A &\to aaBBAb \mid bBabaa \\ B &\to aBb \mid ab \end{aligned}

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?

Try it: multiple select: one or more correct options

Select one or more options
Select all correct options. No negative marking, no partial marks.
Show answer and explanation

Answer: B, D (official GATE 2026 final answer key)

Concept used: Track the difference (and ratio) of aa's and bb's each non-terminal contributes.

First step: BB always yields akbka^k b^k; A→bBabaaA \to bBabaa adds one more aa than bb, and A→aaBBAbA \to aaBBAb adds one more aa than bb per step.

Full step-by-step solution

Detailed working, common mistakes and linked mock tests will be available with a free GATEiit account. Log-in is coming soon.

Share this question

WhatsAppDownload image

Source: official GATE 2026 Session 1 CS question paper and final answer key, organised by IIT Guwahati. Question paper · Answer key