13,162 views
33 33 votes

Consider the following grammar G:

$S \rightarrow bS \mid aA \mid b$

$A \rightarrow bA \mid aB$

$B \rightarrow bB \mid aS \mid a$

Let $N_a(w)$ and $N_b(w)$ denote the number of a’s and b’s in a string $\omega$ respectively.

The language $L(G)$ over  $\left\{a, b\right\}^+$ generated by $G$ is

  1. $\left\{w \mid N_a(w) > 3N_b(w)\right\}$

  2. $\left\{w \mid N_b(w) > 3N_a(w)\right\}$

  3. $\left\{w \mid N_a(w) = 3k, k \in \left\{0, 1, 2, …\right\}\right\}$

  4. $\left\{w \mid N_b(w) = 3k, k \in \left\{0, 1, 2, …\right\}\right\}$

3 Answers

Best answer
49 49 votes

above CFG generate string $b$, $aaa$..
$b$ will eliminate options A and D
$aaa$ eliminate options B.
C is answer i.e. number of $a = 3k, k =0,1,2$....

• edited by
35 35 votes

becoz it is right-linear grammar, so draw m/c

so number of $a = 3k, k =0,1,2....$

• edited by
1 1 vote
There can be one another way to answer this question i.e.

Here, we have
S → bS
S → baA (S → aA)
S → baaB (A → aB)
S → baaa (B → a)
Therefore, | Na (w) | = 3.
Also, if we use A → bA instead of A → aB,
S → baA
S → babA
To terminate A, we would have to use A→ aB as only B terminates at a (B → a).
S → baA
S → babA
S → babaB
S → babaa
Thus, here also, | Na (w) | = 3. So, C is the correct answer
Answer:
Position:
Show:

Related questions

42 42 votes
2 answers 2 answers
17.0k
17.0k views
Kathleen asked Sep 18, 2014
17,041 views
Consider the grammar with the following translation rules and $E$ as the start symbol$$\begin{array}{lll}E \rightarrow E_ 1\# \: T & \qquad\left\{E.value = E_1.value * ...
31 31 votes
3 answers 3 answers
16.5k
16.5k views
Kathleen asked Sep 18, 2014
16,511 views
Which of the following grammar rules violate the requirements of an operator grammar? $P, Q, R$ are nonterminals, and $r, s, t$ are terminals.$P \rightarrow Q R$$P \right...
63 63 votes
5 answers 5 answers
21.2k
21.2k views
Vikrant Singh asked Nov 12, 2014
21,220 views
Consider the grammar rule $E \rightarrow E1 – E2$ for arith­metic expressions. The code generated is targeted to a CPU having a single user register. The sub­traction ope...
36 36 votes
2 answers 2 answers
9.7k
9.7k views
Kathleen asked Sep 18, 2014
9,735 views
Consider a program $P$ that consists of two source modules $M_1$ and $M_2$ contained in two different files. If $M_1$ contains a reference to a function defined in $M_2$ ...