1
$\begingroup$

I had a question on an assignment where we were supposed to write a regular expression for a language where every $a$ in $w$ is immediately preceded and followed by a $b$. My answer was $\epsilon + (b + bab)^*$. The teacher pointed out that my answer makes an $a$ surrounded by at least two $b$s, which isn't correct. I can't for the life of me figure out how to fix it to make it correct. Can anyone help?

$\endgroup$
  • $\begingroup$ Can you give an example of a word in your language not covered by $(b + bab)^*$? (which is by the way equivalent to $\epsilon + (b + bab)^*$) $\endgroup$ – Yuval Filmus Nov 11 '13 at 20:00
  • $\begingroup$ I believe babab would not be accepted by that regular expression, but it should be. $\endgroup$ – Bryan Nov 11 '13 at 22:35
1
$\begingroup$

Here is a regular expression for your language: $(b(ab)^*)^*$. It's not hard to check that every $a$ is bordered by $b$s in both directions. The other direction is more complicated and left to you.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.