• edited by
10,366 views
35 35 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$
    $\qquad 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$
    $\qquad 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$

6 Answers

Best answer
31 31 votes

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
1 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.

0 0 votes

The correct choice is A.

Here is a step-by-step analysis of both grammars.

 

Analysis of Grammar G1

 

  • Rules:

    • $S \to x \mid z \mid xS \mid zS \mid yB$

    • $B \to y \mid z \mid yB \mid zB$

  1. Analyze $B$: The rules $B \to (y \mid z) \mid (y \mid z)B$ show that $B$ generates any string consisting of one or more $y$'s and $z$'s. $B$ can never produce an $x$.

  2. Analyze $S$: The rules $S \to (x \mid z) \mid (x \mid z)S$ show that a derivation from $S$ can produce any sequence of $x$'s and $z$'s (e.g., $x, z, xx, xz, \dots$).

  3. The "Switch" Rule: The derivation from $S$ can switch to $S \to yB$.

    • Once this rule is used (e.g., $S \Rightarrow xS \Rightarrow xyB$), the non-terminal $S$ is gone.

    • The derivation must continue from $B$, which can only produce $y$'s and $z$'s.

    • This means that as soon as a $y$ is generated, no more $x$'s can ever be generated in that string.

  4. Conclusion for G1: A string can consist of only $x$'s and $z$'s (e.g., $xxz$), or it can start with $x$'s and $z$'s, but once a $y$ appears, no more $x$'s can follow (e.g., $xzyyz$). Therefore, it is impossible to generate a string where a $y$ appears before an $x$.

    • This matches the property: "No $y$ appears before any $x$."


 

Analysis of Grammar G2

 

  • Rules:

    • $S \to y \mid z \mid yS \mid zS \mid xB$

    • $B \to y \mid yS$

  1. Analyze $S$: The rules $S \to (y \mid z) \mid (y \mid z)S$ show that $S$ can generate any sequence of $y$'s and $z$'s.

  2. The "Switch" Rule: The derivation from $S$ can use the rule $S \to xB$.

    • This rule is the only way to introduce an $x$ into the string.

    • After $x$ is generated, the derivation must continue from $B$.

  3. Analyze $B$: The rules for $B$ are $B \to y \mid yS$.

    • In both cases ($B \to y$ or $B \to yS$), the very next symbol to be generated must be a $y$.

  4. Conclusion for G2: Since every $x$ is introduced by $S \to xB$, and $B$ must immediately produce a $y$, it is guaranteed that every $x$ in any generated string will be followed by at least one $y$.

    • This matches the property: "Every $x$ is followed by at least one $y$."


 

Final Decision

 

  • G1: No $y$ appears before any $x$.

  • G2: Every $x$ is followed by at least one $y$.

This corresponds exactly to Option A.

Answer:
Position:
Show:

Related questions

92 92 votes
3 answers 3 answers
24.4k
24.4k views
Ishrat Jahan asked Oct 30, 2014
24,353 views
Consider the following grammars. Names representing terminals have been specified in capital letters.$$\begin{array}{|llll|}\hline G1 : & \text{stmnt} & \rightarrow & \...
40 40 votes
2 answers 2 answers
12.6k
12.6k views
Ishrat Jahan asked Oct 30, 2014
12,648 views
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...
68 68 votes
8 answers 8 answers
23.1k
23.1k views
Ishrat Jahan asked Oct 30, 2014
23,124 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...
51 51 votes
8 answers 8 answers
13.2k
13.2k views
Ishrat Jahan asked Oct 30, 2014
13,187 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$?