Draw a DFA for (a|ba)(a|ba)*

automataregular expressionsregular-language

I met a question concerning draw a DFA for $\left(a\vert ba\right)\left(a\vert ba\right)^\ast$.
I firstly tried to expand the regular expression to a $\varepsilon$-NFA, then plan to transform it to a DFA. However, I feel there is something wrong when I expand $\left(ba\right)^\ast$. Because when I use the closure method to convert my $\varepsilon$-NFA to DFA, some states could not accept b, so even I draw the 'DFA', it may be not the correct DFA.
So is it a normal situation under this $\left(ba\right)^\ast$ condition? Or it is because where I got wrong? Please tell me if you have any thoughts, thank you!
The following is what I have tried for your kind reference.
my trying

Best Answer

Here is a solution. The double circled state is the only accept state. The start state is the one with a nondescript arrow going into it.

enter image description here

As you can see, once two $b$'s follow each other directly, we go to the lower right state, from which no escape is possible. Any other string that is nonempty and ends with an $a$ gets accepted.

Related Question