Regular expression for strings with even number of 1's and number of 0's divisible by 5

6.8k Views Asked by At

I am able to write a DFA for this language but don't see any good way to convert this into a regular expression.

This is the DFA I came up with:

enter image description here

1

There are 1 best solutions below

0
On BEST ANSWER

There probably isn't a good way to construct a regular expression for this.

Of course you can always fall back to the systematic algorithm for converting DFAs to regexes, which leads to a horribly huge expression.

As a semi-systematic method, you can start by creating regexes $A$ for "strings with exactly five 0s and an even number of 1s" and $B$ for "strings with exactly five 0s and an odd number of 1s", and then put them together as $$ (A \mid BA^*B)^* \mid (11)^* $$

Somewhat shorter (but more complex to argue for) would be to let $P$ and $Q$ be regexes for strings with exactly five $0$s and even/odd numbers of $1$s that both begin and end with $0$, and put them together as $$ \Bigl( P \,\;\Big|\; (1\mid Q)P^*(1\mid Q) \Bigr)^* $$