edited by
17,483 views
56 56 votes

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$?

  1. $abab$
  2. $aaab$
  3. $abbaa$
  4. $babba$

6 Answers

Best answer
59 59 votes

$S \to SaS \mid aSb \mid bSa \mid SS \mid \epsilon$

If we observe carefully the given grammar is generating all strings over $\Sigma = \{a,b\}$ having number of $b’s$ not exceeding the number of $a’s.$ So, we can straight away give answer as option D. Strings in other options can be generated as shown below.

  1. $abab$
    $S \to a\boxed{S}b$
    ${\to} ab\boxed{S}ab  \to abab$
  2. $aaab$
    $S\to \boxed{S}aS$
    $\to \boxed{S}aSaS$
    $\to a\boxed{S}aS$
    $\to aa\boxed{S}$
    $\to aaa\boxed{S}b$
    $\to aaab$
  3. $abbaa$
    $S \to \boxed{S}S$
    $\to a\boxed{S}bS$
    $\to ab\boxed{S}$
    $\to abb\boxed{S}a$
    $\to abb\boxed{S}aSa$
    $\to abba\boxed{S}a$
    $\to abbaa$

Hence strings in options A, B and C can be generated using the given grammar but not the one in option D. Answer is D.

edited by
73 73 votes
If we notice the productions of this grammar

S->aSb | bSa | SS | ∈

these productions will always produce number of a's and b's equal.

Also , S-> SaS this production may add more number of a's to  number of a's and b's produced by the productions above.

So all, in all this grammar is generating Number of a's = Number of b's or Number of a's are greater than number of b's

If we check option (d), it has more number of b's than a which surely cannot in no way be generated by this grammar.
5 5 votes

strings in options A, B and C can be generated using the given grammar but not the one in option D. Answer is D.

 

3 3 votes
we can generate option a with following sequence of productions :
S->aSb->abSab->abab
for option b:
s->aSb->aSaSb->aSaSab->aaab
for option c:
s->SS->aSbSaS->abbSaa->abbaa

there's no set of productions from which we can babba

so answer will be D
3 3 votes
Both productions S → aSb | bSa implies that if b will be there then atleast that many a's as number of b's will be there. And thus option D rule out with this observation.
0 0 votes

If you see the grammar the production is not present, S->SbS, because of this , babba won’t be generated  [ it contains more b’s than a’s ].

if that production had been there then option D) babba was generated

Answer:
Position:
Show:

Related questions

58 58 votes
8 answers 8 answers
23.8k
23.8k views
Arjun asked Feb 14, 2017
23,778 views
Consider the following languages over the alphabet $\Sigma = \left \{ a, b, c \right \}$. Let $L_{1} = \left \{ a^{n}b^{n}c^{m}\mid m,n \geq 0 \right \}$ and $L_{2} = \le...
72 72 votes
10 answers 10 answers
19.2k
19.2k views
Arjun asked Feb 14, 2017
19,161 views
Consider the context-free grammars over the alphabet $\left \{ a, b, c \right \}$ given below. $S$ and $T$ are non-terminals.$G_{1}:S\rightarrow aSb \mid T, T \rightarrow...
115 115 votes
11 answers 11 answers
34.6k
34.6k views
Arjun asked Feb 14, 2017
34,587 views
Consider the following context-free grammar over the alphabet $\Sigma = \{a,b,c\}$ with $S$ as the start symbol:$$S \rightarrow abScT \mid abcT$$$$T \rightarrow bT \mid ...
89 89 votes
12 answers 12 answers
28.6k
28.6k views
Arjun asked Feb 14, 2017
28,555 views
A cache memory unit with capacity of $N$ words and block size of $B$ words is to be designed. If it is designed as a direct mapped cache, the length of the $\textsf{TAG}$...