Question:

Consider the following grammar where 𝑆 is the start symbol, and π‘Ž and 𝑏 are
terminal symbols.
𝑆 β†’π‘Žπ‘†π‘π‘† ∣ 𝑏𝑆 ∣ Ο΅
Which of the following statements is/are true?

Show Hint

Since every 'a'-led derivation starts with aSbS, count how many ways the literal 'b' in that production can be matched against the b's in the target string to test ambiguity, then recall that all context-free languages are decidable.
Updated On: Jul 7, 2026
  • The grammar is ambiguous
  • The string π‘Žπ‘π‘ has two distinct derivations in this grammar
  • The string π‘Žπ‘π‘Žπ‘ has only one rightmost derivation
  • The language generated by the grammar is undecidable
Show Solution
collegedunia
Verified By Collegedunia

The Correct Option is A, B, C

Solution and Explanation

The grammar is \(S \to aSbS \mid bS \mid \epsilon\), with S as the start symbol. We must check ambiguity and the derivations of specific strings.

Step 1: Show the grammar is ambiguous (Option A) by finding a string with two distinct parse trees.

Consider the string 'abb'. Since it starts with 'a', the only applicable production is \(S \to aSbS\). After the leading 'a', we need \(S_1\) then a literal 'b' then \(S_2\) to spell out 'bb'. This means the strings derived by \(S_1\) and \(S_2\) together must total just one character, since one 'b' is already accounted for by the production.

Step 2: Find the two ways to split this single extra 'b'.

Way 1: \(S_1 \to \epsilon\) and \(S_2\) must derive 'b', which it does uniquely via \(S_2 \to bS \to b\epsilon\).

Way 2: \(S_1\) must derive 'b' via \(S_1 \to bS \to b\epsilon\), and \(S_2 \to \epsilon\).

Both ways produce the string 'abb' but via different parse trees (the extra 'b' either belongs to the left S or the right S in \(aSbS\)). Hence 'abb' has two distinct derivations, proving both that the grammar is ambiguous (Option A true) and that option B is directly true.

Step 3: Check option (C), whether 'abab' has only one rightmost derivation.

'abab' also starts with 'a', so again \(S \to aSbS\) applies, and after removing the leading 'a' we must generate 'bab' as \(S_1\), then a literal 'b', then \(S_2\). We look for positions where this literal 'b' can split 'bab': either at position 0 (giving \(S_1 \to \epsilon\), and \(S_2\) derives 'ab'), or at position 2 (giving \(S_1\) derives 'ba', and \(S_2 \to \epsilon\)).

For the second split, \(S_1\) would need to derive 'ba', which requires \(S_1 \to bS\) followed by S deriving 'a' alone. But no derivation of S can ever produce a lone 'a' with no accompanying 'b', because every nonempty production either starts with 'b' (from \(bS\)) or is forced to contain a literal 'b' internally (from \(aSbS\)). So this second split is impossible, leaving only the first split as valid: \(S_1 \to \epsilon\), and \(S_2\) derives 'ab' via the unique chain \(S_2 \to aSbS \to a\epsilon b\epsilon\).

Since only one valid split exists, 'abab' has exactly one parse tree and therefore only one rightmost derivation. Option C is true.

Step 4: Check option (D), whether the language is undecidable.

The grammar is a simple context-free grammar. Every context-free language has a decidable membership problem (using, for example, the CYK algorithm), so this language is certainly decidable, not undecidable. Option D is false.

Step 5: Conclude.

Options A, B, and C are true; option D is false.

\[ \boxed{\text{Options A, B and C}} \]
Was this answer helpful?
0
0

Top GATE CS Computer Science and IT Engineering Questions

View More Questions

Top GATE CS Context Free Languages and Pushdown Automata Questions