Question

Consider the context-free grammar GG below

S→aSb∣XX→aX∣Xb∣a∣b,\begin{aligned} S &\rightarrow aSb \mid X \\ X &\rightarrow aX \mid Xb \mid a \mid b, \end{aligned}

where SS and XX are non-terminals, and aa and bb are terminal symbols. The starting non-terminal is SS.

Which one of the following statements is CORRECT?

Choose one option
Official answer and solution
Official answer
B
From
Official GATE 2023 answer key

Solution

Analyze the strings generated by non-terminal XX and their embedding into SS.

  1. Non-terminal XX has productions:

    X→aX∣Xb∣a∣bX \rightarrow aX \mid Xb \mid a \mid b

    This grammar generates any string consisting of one or more characters from {a,b}\{a, b\} where all aa's appear before all bb's, i.e., L(X)=a∗(a+b)b∗=a+b∗∪a∗b+L(X) = a^* (a + b) b^* = a^+ b^* \cup a^* b^+.

  2. Non-terminal SS has productions:

    S→aSb∣XS \rightarrow aSb \mid X

    Applying S→aSbS \rightarrow aSb kk times (k≥0k \ge 0) wraps the string generated by XX with kk leading aa's and kk trailing bb's:

    akXbk=ak[a∗(a+b)b∗]bk=a∗(a+b)b∗a^k X b^k = a^k [a^* (a + b) b^*] b^k = a^* (a + b) b^*

    Because absorbing additional aa's on the left and bb's on the right of a∗(a+b)b∗a^* (a + b) b^* yields precisely the same set a∗(a+b)b∗a^* (a + b) b^*, the language generated is simply L(G)=a∗(a+b)b∗L(G) = a^* (a + b) b^*.

  3. Since a∗(a+b)b∗a^* (a + b) b^* is a regular expression, the language is regular.

Final answer

Option (B)

Common trap

Concluding the language is non-regular due to the S→aSbS \rightarrow aSb production without realizing XX already generates all unbalanced combinations.

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

Source

Paper
GATE 2023 Computer Science and Information Technology (CS)
Question
39 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.