Discrete Math Quick Regular Expression question!

928 Views Asked by At

For a regular expression (a | b)*, can I write this string: aaaaaaabbbbbbbbbbbabababbb. I was thinking this means that when I choose a, I can have multiple a's and then I can choose b too after choosing multiple a's. Or is it that once I chose a, I cannot go back and choose b after finishing with a?

3

There are 3 best solutions below

1
On BEST ANSWER

Your first interpretation is correct. The second one would correspond to the regular expression $a^*b^*$. But in both cases, don't forget to consider the empty word as well...

2
On

Regular expression (a | b)* indicates that you can choose any number (including 0) of a and b and it doesn't matter whichever is the sequence i.e. you can start with a or b. The second one is ab which means it should or should not start with a (a's occurrence can be 0 or more but once you moved to b there is no turning back to a.

  1. (a|b)* demo

  2. a*b* demo

0
On

$(a|b)*$ means $a$ or $b$ zero or more times. You can only pick $a$ or $b$ at any given iteration

so $bbbbb, aaaaa, ab,$ null, $abaab$ are all correct.