• edited by
12,928 views
40 40 votes

Consider the grammar given below:

$S      \rightarrow      x \ B \mid y \ A$
$A      \rightarrow      x \mid x \ S \mid y \ A \ A$
$B      \rightarrow      y \mid y \ S \mid x \ B \ B$

Consider the following strings.

  1. $xxyyx$
  2. $xxyyxy$
  3. $xyxy$
  4. $yxxy$
  5. $yxx$
  6. $xyx$

Which of the above strings are generated by the grammar ?

  1. i, ii and iii
  2. ii, v and vi
  3. ii, iii and iv
  4. i, iii and iv

2 Answers

Best answer
48 48 votes

ii, iii and iv.

So, option C is correct.

Above grammar is for equal no of x and y 

from Non-terminal $S \rightarrow xB$                            

                                   $\Rightarrow xy$    [as $B \rightarrow y$ one $y$ for one $x$]                               

$S \rightarrow xB$

$\Rightarrow xxBB$   [as $B \rightarrow yBB$   one $B$ result in one $y$ for one $x$ ]

$S \rightarrow xB$

$\Rightarrow xyS$ [as $B \rightarrow yS$  one $y$ for one $x$ and start again]

Note: Same applies for string start with $y$ i.e .  $S \rightarrow yA$.

• edited by
4 4 votes

ii) xxyyxy
S → xB
S → xxBB
S → xxyB
S → xxyyS
S → xxyyxB
S → xxyyxy

 

(iii) xyxy
S → xB
S → xyS
S → xyxB
S → xyxy

 

(iv) yxxy
S → yA
S → yxS
S → yxxB
S → yxxy

Answer:
Position:
Show:

Related questions

92 92 votes
3 answers 3 answers
24.9k
24.9k views
Ishrat Jahan asked Oct 30, 2014
24,908 views
Consider the following grammars. Names representing terminals have been specified in capital letters.$$\begin{array}{|llll|}\hline G1 : & \text{stmnt} & \rightarrow & \...
35 35 votes
6 answers 6 answers
10.7k
10.7k views
Ishrat Jahan asked Oct 29, 2014
10,701 views
The two grammars given below generate a language over the alphabet $\{x, y, z\}$$G1 : S \rightarrow x \mid z \mid x \ S \mid z \ S \mid y \ B$$\qquad B \rightarrow y \...
71 71 votes
8 answers 8 answers
23.5k
23.5k views
Ishrat Jahan asked Oct 30, 2014
23,508 views
Consider the regular expression $R = (a + b)^* \ (aa + bb) \ (a + b)^*$Which one of the regular expressions given below defines the same language as defined by the regula...
52 52 votes
8 answers 8 answers
13.5k
13.5k views
Ishrat Jahan asked Oct 30, 2014
13,453 views
Consider the regular expression $R = (a + b)^* (aa + bb) (a + b)^*$Which deterministic finite automaton accepts the language represented by the regular expression $R$?