in Theory of Computation edited by
5,672 views
25 votes
25 votes

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$
          $B       \rightarrow       y \mid z \mid y \ B \mid z \ B$

$G2 :          S       \rightarrow       y \mid z \mid y \ S \mid z \ S \mid x \ B$
          $B       \rightarrow       y \mid  y \ S $

Which one of the following choices describes the properties satisfied by the strings in these languages?

  1. $G1$ : No $y$ appears before any $x$
    $G2$ : Every $x$ is followed by at least one $y$
  2. $G1$ : No $y$ appears before any $x$
    $G2$ : No $x$ appears before any $y$
  3. $G1$ : No $y$ appears after any $x$
    $G2$ : Every $x$ is followed by at least one $y$
  4. $G1$ : No $y$ appears after any $x$
    $G2$ : Every $y$ is followed by at least one $x$
in Theory of Computation edited by
5.7k views

2 Comments

Meta Note: This question is incorrectly tagged as CFL.
0
0

Regular expression for 

Every y is followed by at least one x :-   (x+z+yx)+  

No x appears before any y  :-   (y+z)+ + (y+z)* x (x+z)+ 

No y appears after any x  :-      (x+z)+ + (y+z)* y (x+z)+ 

Correct me if i am wrong .....

0
0

5 Answers

24 votes
24 votes
Best answer

From Above grammar:

Regular expression for $G1: (x+z)^+ + (x+z)^*y(y+z)^+ $

Regular expression for $G2 :(y+z+xy)^+$

Option A is correct .

edited by

4 Comments

Or

$G_{1} = (X+Y)^{*}(X+Z+Y(Y+Z)^{+}) $
2
2

@Praveen Saini @Sachin Mittal 1 sir why you made one extra state for the final state, it can be S,B both as a final state in DFA constructed by @Sachin Mittal 1?

0
0
@air1ankit..
If S is final state, then machine will accept some extra strings like epsilon...(by extra strings, i mean the strings that are not generated by given grammar)
Similarly if B is final state, then  machine accepts some extra strings like xy which are not in language.
Hence they are not taken as final..
Hope this clears :)
1
1
10 votes
10 votes

G1: $\\(x+z)^*(x+z)+(x+z)^*y(y+z)^*(y+z)$

  $=(x+z)^++(x+z)^*y(y+z)^+$

G2: $\\(y+z+xy)^*xy+(y+z+xy)^*(y+z)$

  $=(y+z+xy)^*(xy+y+z)$

  $=(y+z+xy)^+$

after removing loop:

$Ans:A$

4 votes
4 votes

A)

G1 : No y appears before any x
G2 : Every x is followed by at least one y

1 comment

@Sachin Mittal 1

Hello Sir,

what's the approach of creating final state. As the nfa diagram you provided for the above grammar has F as final state not S and B.

0
0
1 vote
1 vote

For the above question we can see that for all options, properties satisfied by the strings could be defined as some relation between x and y alphabets.
For Grammar 1, Strings with a combination of both x and y can be generated with the following form of production(s) of the grammar only.

S–>xS –>xyB or

S–>zS–>zxS–>zxyB

(In case starting production is S–>x| z| yB, it cannot give both x and y in the string)
Hence in any string with x and y both no y can appear before x can be described as a property satisfied by the strings of the language.

Similarly for Grammar 2, Strings with a combination of both x and y can be generated with the following

form of production(s) of the grammar only.

Answer:

Related questions