Is this language really regular?

122 Views Asked by At

This question is taken from a past exam :

Write a regular expression to generate the language $L$ over the alphabet $\Sigma = \text{{0, 1}}$ such that $L = \{w \mid \#_0(\text{prefix}(w)) - \#_1(\text{prefix}(w))\leq 1 \}$.

In plain language, $L$ is the language of words over $\text{{0, 1}}$ where any string respects the property that the difference between the number of $0$'s and the number of $1$'s in every prefix of the word is less than or equal to $1$ (this includes negative differences, as well).

My questions is, is this language even regular to begin with? I can't help but think the question is ill-formed.

1

There are 1 best solutions below

1
On BEST ANSWER

If $L$ is regular, then the language $L \cap 1^*0^*$ should be regular. But $$L \cap 1^*0^* = \{ 1^n 0^m \mid m \leqslant n + 1\}$$ is not regular.