Regular expresson a's and b's

363 Views Asked by At

Need to construct a regular expression that recognizes the following language of strings over the alphabet {a,b}: - The set of all strings over alphabet {a,b} in which every occurrence of b is followed by at least two a's. For example, the empty string is in this language, as is every string consisting solely of a's. The string abaa is in the language, but aba is not.

What i have come up with is a*b*a{2,} but that do not accept the empty string.

2

There are 2 best solutions below

2
On BEST ANSWER

(a*(baa)*)* should work.

We enforce the constraint, as well as allow the whole pattern to be repeated any number of times to allow generation of other legal strings.

0
On

Hint:

  • If you were to treat "baa" as a single symbol, then your language would be the full language.
  • The regular expression for the full language over $\Sigma = \{\alpha, \beta\}$ is $(\alpha\mid \beta)^*$.

I hope this helps $\ddot\smile$