Describing the language generated by this grammar

1.3k Views Asked by At

I'm working on this discrete math problem

Describe the language generated by the grammar $G = \{\Sigma, \Delta, S, \Pi \}$, where $\Sigma = \{0, 1 \}$, $\Delta = \{S, X, Y, Z \}$ and $\Pi = \{S \rightarrow 0X | 1Y, X \rightarrow 1Y |1Z, Y \rightarrow 0X | 0Z, Z \rightarrow 0|e \}$.

From my understanding, the language generated should be something like this

$$L = \{ 01110111 \}$$

there is no "loop" where a number goes back to the variable. I'm confused on how to solve this, I need enlightenment. Any help would be great.

1

There are 1 best solutions below

4
On BEST ANSWER

For convenience I repeat the list of productions:

$$\begin{align*} S&\to 0X\mid 1Y\\ X&\to 1Y\mid 1Z\\ Y&\to 0X\mid 0Z\\ Z&\to 0\mid\epsilon \end{align*}$$

Notice that every $X$ production adds a $1$ to the string, and every $Y$ production adds a $0$.

Suppose that you begin a derivation by applying $S\to 0X$. Then you can alternately apply $X\to 1Y$ and $Y\to 0X$ as often as you like, but eventually you must apply either $X\to 1Z$ or $Y\to 0Z$, depending on which non-terminal symbol you have at that point. At this point you will have a string that begins with $01$, then alternates $0$s and $1$s, and ends in $Z$. Finally, the $Z$ either disappears or is replaced by $0$.

If you begin by applying $S\to 1Y$, you get a string that begins with $10$, then alternates $1$s and $0$s, and ends in $Z$, and again the $Z$ either disappears or is replaced by $0$.

Thus, at the stage when the string ends in $Z$, the rest of it can be any alternating string of $0$s and $1$s of length at least $2$. Thus, if $L_0$ is the set of strings of alternating $0$s and $1$s of length at least $2$, your language is

$$L=L_0\cup\{x0:x\in L_0\}\;.$$

The shortest strings in $L$ are those produced by the derivations

$$S\Rightarrow 0X\Rightarrow 01Z\Rightarrow 01$$

and

$$S\Rightarrow 1Y\Rightarrow 10Z\Rightarrow 10\;.$$

The shortest non-alternating string is the one produced by the derivation

$$S\Rightarrow 1Y\Rightarrow 10Z\Rightarrow 100\;.$$

The shortest string that has two distinct derivations is $010$, which is derived both by

$$S\Rightarrow 0X\Rightarrow 01Z\Rightarrow 010$$

and by

$$S\Rightarrow 0X\Rightarrow 01Y\Rightarrow 010Z\Rightarrow 010\;.$$