0
$\begingroup$

Let be a language with the following alphabet : $\Sigma=\{a,b\}$

{ $w$ | $w$ does not contains $aa$ nor $bb$}

I know it can be graphed this way :

enter image description here

Can I write it as the following regular expression ?

$$(ab)^*+(ba)^*$$

1 Answers 1

0

No, you're missing $aba$ and $bab$ etc.

Obviously, we're looking for words of one of the forms

  • $ababa…ba$
  • $ababa…b$
  • $baba…ba$
  • $baba…b$

That translates to the RE

$(ab)^*a + (ab)^* + b(ab)^* + b(ab)^*a$

In CS, this is easier written as $a?(ba)^*b?$, when the $?$ modifier is available.

  • 2
    Your CS expression can be written as $(1 + a)(ba)^*(1+b)$, where $1$ is the empty word.2017-02-01
  • 0
    @J.-E.Pin Is the empty word compulsory ?2017-02-07