Search code examples
regular-languagedfaautomata-theory

Regular expression in Automata Theory?


I have the following language and its regular expression

{w ∈ {a, b}* : w has bab as a prefix, and babaa as a suffix}

Answer:

Regular expression = bab(a ∪ b)*babaa ∪ babaa ∪ bababaa

Why bold part is needed?


Solution

  • bab is a prefix of babaa, and babaa is obviously a suffix of itself. Therefore, babaa is a possible string.

    babaa is a suffix of bababaa and bab is a prefix of bababaa. Thus, it should also be included.