2
$\begingroup$

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.

  • 0
    I edited your definition of $L$ a bit for better formatting, but I might have changed things that should not have been changed. Could you please check that everything is as it should?2017-01-30
  • 0
    Thank you, @Arthur, your formatting looks great. The original meaning of the question is still intact.2017-01-30

1 Answers 1

1

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.

  • 0
    Really neat, thank you. +12017-01-31