in Theory of Computation edited by
7,932 views
34 votes
34 votes

In the context-free grammar below, $S$ is the start symbol, $a$ and $b$ are terminals, and $\epsilon$ denotes the empty string.

  • $S \to aSAb \mid \epsilon$
  • $A \to bA \mid \epsilon$

The grammar generates the language

  1. $((a + b)^* b)$
  2. $\{a^mb^n \mid m \leq n\}$
  3. $\{a^mb^n \mid m = n)$
  4. $a^* b^*$
in Theory of Computation edited by
7.9k views

4 Comments

How can we generate the string 'b' from this grammar?
0
0

@sristi30 there is no condition that m,n = 0.

0
0
0
0
Start by eliminating options:

Option A –  This expression don't accept Eplison . But grammar given in question accept Eplison .

Option C –   This expression don't accept  strings like abb . But grammar given in question accepts abb .

Option D -This expression accept b as string but grammar given in question can’t accept b as string .

So option B is answer
0
0

5 Answers

72 votes
72 votes
Best answer

$A \to bA \mid \varepsilon$

$\therefore \quad A = b^*$


$S \to aSAb \mid \varepsilon$

$\equiv S \to aSb^*b \mid \varepsilon$

$\equiv S \to aSb^+ \mid \varepsilon$


$S = a^n\left(b^+\right)^n, \quad n\geq 0$

$S = a^nb^nb^*, \quad n\geq 0$

$S = a^mb^n, \quad m\leq n$

Hence, option B is correct.

edited by

17 Comments

Thank you . Awesome approach.
2
2
very nice approach. Awesome.
0
0
edited by

@sushmita @Pragy Agarwal @Ram Sharma1 @Habibkhan @A_i_$_h @Bikram

How (b+)n= bnb∗

what property is this?

3
3

S ---> ε  and A ----> ε  also  so it also accepts ε    , so why not  option D  How can Option B generates ε

0
0

In Option B m<=n, when ε m=0 and m=0 . In option d it says any no. of a's followed by any no. of b's. Try generating aab from option d, it fails

0
0
The grammar never generates all strings with just b*.
For b* we have m=0 and n>=0. But these strings are not generated by the grammar.

Hence the condition needs to be

m<=n for all m>0
m=n for m=0
5
5

@rohith1001: Good observation. You're absolutely correct - the grammar cannot generate $b^+$, hence

$$L = \left \{ a^m n^n \mid \begin{align}
&m = n = 0 \\
&0 < m \leq n
\end{align} \right \}$$

4
4

@Pragy Agarwal how can i draw DFA for the given  grammar.? 

0
0
It is not Regular.
0
0

@Pragy Agarwal @kenzou

How can we write this?

0
0
Option B is also wrong because option B says that we can generate any number of B, but they should be greater than equal to number of A. OPTION B can generate bbb, but  given CFG doesn't.
1
1

ayushsomani

\(S \rightarrow aSb\:|\: \epsilon\) is the grammar which produces language of type \( a^n b^n; \:\:n \geq0\)

So on the similar logic, \(S \rightarrow aSb^+\:|\: \epsilon\) is the grammar which produces language of type \( a^n (b^+)^n; \:\:n \geq0\)

Which further can be written as \( a^n b^n b^*; \:\:n \geq0\)

And leads to an answer as \( a^m b^n; \:\:m \leq n\)

0
0
I think the correct language will be: { $a^{m}b^{n} ; m<=n; m,n>=1$} $\bigcup$ {$\varepsilon $}
0
0

@SougataSarkar The given answer is correct. Actually $\epsilon$ is included in the Language 

$S = a^mb^n, \quad m\leq n$. And we don’t need to mention $m<=n; m,n>=1$ because only if it starts from 0, we will get $\epsilon$.

 

0
0

@Abhrajyoti00 Yes I agree with you that “ϵ” is already there in the language  {$a^{m}b^{n} ; m\leq n$} but this language also generates b* which is not generated by the grammar , that’s why I mentioned the condition m,n$\geq$1 along with “ϵ”

1
1

@SougataSarkar Yes you are correct. The smallest string which is not null is $ab$. Hence $m,n>=1 $ must be mentioned.

0
0
No option correct .
0
0
8 votes
8 votes

1) Epsilon is in grammar but can`t generate from this expression.
2) Can generate the exact language from this expression refer above answer.
3) abb is one of the string that can be generate from the given grammar but not by regular exp CONTRADICTION
4) aaaabb is the string that can be generated by this regular expression but not by grammar.

3 Comments

we can generate epsilon S-> epsilon
0
0
Same thing i mentioned , its the reason why $1^{st}$ one is not representing grammar because $1^{st}$ RE cannot generate $"\epsilon"$.
0
0
thank you
0
0
1 vote
1 vote
Option B is also wrong because option B says that we can generate any number of B, but they should be greater than equal to number of A. OPTION B can generate bbb, but  given CFG doesn't.
1 vote
1 vote

B is correct.

  1.  Incorrect as ((a+b)*b) can generate strings like aaaab which is not possible with given grammar.
  2.  Correct.
  3.  Also incorrect not always we will have a’s and b’s of same length, hence false
  4. a*b* can generate strings where a’s is greater than b false again.
Answer:

Related questions