I was looking at the question posed in this stackoverflow link (Regular expression for odd number of a's) for which it is asked to find the regular expression for strings that have odd number of a
over Σ = {a,b}
.
The answer given by the top comment which works is b*(ab*ab*)*ab*
.
I am quite confused - a
was placed just before the last b*
, does this ordering actually matter? Why can't it be b*a(ab*ab*)*b*
instead (where a
is placed after the first b*
), or any other permutation of it?
Another thing I am confused about is why it is (ab*ab*)*
and not (b*ab*ab*)*
. Isn't b*ab*ab*
the more accurate definition of 'having exactly 2 a
'?