recategorized by
2,680 views
4 votes
4 votes

The grammar with production rules $S \rightarrow aSb \mid SS \mid \lambda$ generates language $L$ given by:

  1. $L = \{ w \in \{a, b\}* \mid n_a(w) = n_b(w) \text{ and } n_a(v) \geq n_b(v) \text{ where v is any prefix of w} \}$
  2. $L = \{ w \in \{a, b\}* \mid n_a(w) = n_b(w) \text{ and } n_a(v) \leq n_b(v) \text{ where v is any prefix of w} \}$
  3. $L = \{ w \in \{a, b\}* \mid n_a(w) \neq n_b(w) \text{ and } n_a(v) \geq n_b(v) \text{ where v is any prefix of w} \}$
  4. $L = \{ w \in \{a, b\}* \mid n_a(w) \neq n_b(w) \text{ and } n_a(v) \leq n_b(v) \text{ where v is any prefix of w} \}$
recategorized by

2 Answers

Best answer
4 votes
4 votes

 S→aSb∣SS∣λ

This grammar will generate all strings in which  na(w) = nb(w) .

A prefix is a string of any number of leading symbols.

For example, the string abc has prefix (empty string), a, bc, abc. When we consider the prefix v of w, the number of ‘a’s in it is either greater than or equal to ‘b’s in the string w. 

For example, aab is prefix of the string aabb. Here, number of ‘a’s is more than the number of ‘b’s. ab is a prefix of the string abab. The number of ‘a’ and ‘b’ are equal. So, when we consider the prefix v, the number of ‘a’s and ‘b’s are equal.

 

Hence,Option(A) is the Answer.

selected by
3 votes
3 votes

Ans A

  • Each S produces one a and one b together only.
  • For each a produced, one b will also be produced.

Hence n a  (w)= n (w)

  • Since before each b, one a is produced, number of a's >= number of b's for any substring.

So n a (v) >= n b (v)

Answer:

Related questions

2 votes
2 votes
1 answer
2
go_editor asked Jul 17, 2016
1,482 views
Match the following :$\begin{array} {} \text{a.}& \text{Context sensitive language} & \text{i.} & \text{Deterministic finite automation} \\ \text{b.}& \text{Regular gram...
3 votes
3 votes
1 answer
3
go_editor asked Jul 17, 2016
1,962 views
For every context free grammar (G) there exists an algorithm that passes any $w \in L(G)$ in number of steps proportional to$ln\mid w \mid$$\mid w \mid$$\mid w \mid^2$$\m...