GATE 2017 CS – Question 44
If $G$ is a grammar with productions
$$S \rightarrow SaS \mid aSb \mid bSa \mid SS \mid \epsilon$$
where $S$ is the start variable, then which one of the following strings is not generated by $G$?
Practise this question in The GATE Grind →
Show answer and explanation
Correct answer: (D) $babba$
Explanation
Every production adds at least as many $a$'s as $b$'s, and $SaS$ adds an $a$ with no $b$. So every string generated has at least as many $a$'s as $b$'s. The string $babba$ has 3 $b$'s and only 2 $a$'s, so it cannot be generated.