-2
$\begingroup$

Why is the answer (b + /\)(ab)*aa(ba)*(b + /\) + (a + /\)(ba)*bb(ab)*(a + /\)? I'm confused and I request guidance

$\endgroup$

1 Answer 1

5
$\begingroup$

It took me a while to understand that your alphabet $\Sigma$ is $\{a,b\}$ and by /\ you meant the empty word $\epsilon$.

Your regular expression is the union of two sub-expression, namely:

  • (b + /\)(ab)*aa(ba)*(b + /\) ; and
  • (a + /\)(ba)*bb(ab)*(a + /\).

The first one (resp. second one) matches all the words that contain exactly one double letter, and that double letter is "a" (resp. "b"). Since the two sub-expression are similar (just swap "a" and "b"), I will only describe the first of the two.

A word $w$ that matches the first sub-expression contains exactly one occurrence of "aa" and no occurrence of "bb", and can then be decomposed as $$w = x \circ \, aa \, \circ y,$$ where "$\circ$" denotes concatenation and:

  • $x$,$y$ are strings that contain no double letters;
  • $x$ does not end with "a" (as otherwise you would have 3 consecutive "a"s in $w$).
  • $y$ does not start with "a".

We are then left with the task of finding a regular expression for $x$ and $y$. Let's consider $y$ first. Either $y = \epsilon$, or it must start with a $b$. Moreover, since no two characters in a row can be the same, $y$ is just an alternation of "b"s and "a"s. This can be expressed as $(ba)^*$ if $y$ has even length (i.e., if it ends with an $a$), and as $(ba)^*b$ if $y$ has odd length.

Therefore we can write the following regular expression for $y$: $(ba)^* + (ba)^*b$ and, by factorizing the common prefix, $(ba)^*(b+\epsilon)$.

The argument for $x$ is analogous, with the exception that $x$ is either $\epsilon$ or it must end with a "b". With a similar reasoning we get: $x = (ab)^* + b(ab)^* = (b + \epsilon)(ab)^*$.

Substituting our regular expression for $x$ and $y$ back into the formula for $w$ we obtain:

$$ w = x \circ \, aa \, \circ y = \underbrace{(b + \epsilon)(ab)^*}_x \; aa \; \underbrace{(ba)^*(b+\epsilon)}_y . $$.

$\endgroup$
0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.