368 views
3 3 votes

Consider the following context-free grammars:

$$
\begin{aligned}
& G_1: S \rightarrow a S|S b| \epsilon \\
& G_2: S \rightarrow a S b|a A, A \rightarrow a A| \epsilon
\end{aligned}
$$


Which one of the following pairs of languages is generated by $G_1$ and $G_2$, respectively?
 

  1. $\left\{a^m b^n \mid m \geq 0, n \geq 0\right\}$ and $\left\{a^m b^n \mid m=n\right\}$
     
  2. $\left\{a^m b^n \mid m \geq 0, n \geq 0\right\}$ and $\left\{a^m b^n \mid m \geq n, m>0\right\}$
     
  3. $\left\{a^m b^n \mid m>0, n \geq 0\right\}$ and $\left\{a^m b^n \mid m \geq n\right\}$
     
  4. $\left\{a^m b^n \mid m \geq 0, n \geq 0\right\}$ and $\left\{a^m b^n \mid m>n\right\}$

2 Answers

1 1 vote

The correct choice is D.

For $G_1$ : using $a S$ you can generate any number of leading a's, and using $S b$ any number of trailing b's; with $\epsilon$ you can stop - so $G_1$ generates all $a^m b^n$ with $m, n \geq 0$.

For $G_2$ : every use of $a S b$ pairs one a with one b , and the $a A$ branch supplies extra a's (at least one a overall because of the leading $a$ in $a A$ ), so strings satisfy  $m>n$.

• edited by
0 0 votes

Correct options is D

For G1 Language L =  (a+b)^* and for G2 Language = a^na^+b^n which is equal to L= a^mb^n where m>n

Answer:
Position:
Show:

Related questions

3 3 votes
1 1 answer
268
268 views
GO Classes asked Nov 18, 2025
268 views
Consider the following context-free grammars:$$\begin{aligned}& G_1: S \rightarrow a S|B, B \rightarrow b B c| \epsilon \\\\& G_2: S \rightarrow a S b|C, C \rightarrow b ...
3 3 votes
1 1 answer
302
302 views
GO Classes asked Nov 18, 2025
302 views
Let$$S=\{\langle M, w\rangle \mid M \text { is a Turing machine that halts within }|w| \text { steps on input } w\} .$$Is the set $S$ countable or uncountable? Countable,...
3 3 votes
2 2 answers
264
264 views
GO Classes asked Nov 18, 2025
264 views
Let $L_1=\left\{\langle M\rangle \mid M\right. \text{ is a TM that halts on every input of the form} \left.0^n 1^n\right\}$.Which of the following is true about $L_1$ ? $...
1 1 vote
1 1 answer
275
275 views
GO Classes asked Nov 18, 2025
275 views
Let $L_1$ and $L_2$ be two regular languages accepted by DFAs $M_1$ and $M_2$, respectively.Consider the following problems:P1: "Is $L_1 \cap L_2=\emptyset$ ?"P2: "Is $L_...