4

Is the language of words containing same number of 101s and 010s regular? If yes, how can I design a DFA for it?

In general, is the language of words containing equal number of strings which one is "one's complement" of the other one is regular (like the language of words containing equal number of 01s and 10s which is regular)? Is there any counterexample?

John L.
  • 39,205
  • 4
  • 34
  • 93
Marzi
  • 65
  • 4

1 Answers1

5

No, the language of words containing same number of 010s and 101s is not regular.

Consider $x_n=(0100)^n$ and $y_n=(1011)^n$. Then $x_iy_j$ contains $i$ number of 010s and $j$ number of $101s$. That is, $x_iy_j$ is in the language if and only if $i=j$.

So $x_i$ represents a distinct Nerode-Myhill equivalence classes for all $i$. Since there are infinitely many such $x_i$, there are infinitely many Myhill-Nerode equivalence classes. By Myhill–Nerode theorem, the language is not regular.


Here are several related exercises. Exercise 2 answers the more general situation in the question. Exercise 3 is a further generalization.

Let $\Sigma=\{0,1\}$.

Exercise 1. The language of words over alphabet $\Sigma$ containing the same number of 01s and 10s is regular. The language of words over alphabet $\{0,1, 2\}$ containing the same number of 01s and 10s is not regular.

Exercise 2. Let nonempty $w\in \Sigma^*$. Let $\overline w$ be the one's complement of $w$. For example, $\overline{010010111}=101101000$. Let $E_w$ be the language of words over $\Sigma$ containing the same number of $w$s and $\overline w$s. Show that $$ E_w\text{ is regular} \iff w=01\text{ or }w=10$$ (It may take a while to do this exercise.)

Exercise 3. Let $u$ and $v$ be two different non-empty words in $\Sigma^*$. Let $E_{u,v}$ be the language of words over $\Sigma$ containing the same number of $u$s and $v$s. Let $N_{u,v}$ be the language of words over $\Sigma$ containing no $u$ nor $v$ as a subword. Show that $$ L_{u,v}\text{ is regular } \iff \{u,v\}=\{01,10\}\text{ or } E_{u,v} = N_{u,v}.$$ (It may take a while to do this exercise.)

John L.
  • 39,205
  • 4
  • 34
  • 93