Finding the set of strings over {,} that ends with an odd number of "a"s

649 Views Asked by At

I need to write a regular expression that identifies the set of all possible strings over Σ={,} that end with an odd number of "a"s.

I'm getting better with regular expressions, but still I'm not sure of this one. So far, I wrote the following expression, but I'm not sure if it is correct or not (and if not, why).

$$ (b^*|(a|b)^*)a(aa)^* $$

well the last part makes sure that it ends with at least 1 or 1+2n "a"s, so I'm pretty sure this is correct. As for the first part, I'm not quite sure.

2

There are 2 best solutions below

0
On

Let $A =\{a, b\}$ and let $1$ be the empty word. A typical word of your language $L$ can be written as $uv$, where $v \in a(aa)^*$ and $u$ does not end with an $a$, that is, $u \in 1 + A^*b$. Altogether, you get $$L = (1 + A^*b)a(aa)^*$$

1
On

@CurlyError: what u have done is correct. Tho, I think (((a|b)b)|eps)a(aa) is better since this leads to a simpler NFA. This form basically says either have a prefix ending in b or eps i.e. no prefix.