Construction of Regular Expression

942 Views Asked by At

I have the problem of needing to construct a regular expression corresponding to the set of strings of 0's and 1's whose number of 0's is divisible by five and whose number of 1's is even.

Construction of a regular expression that satisfies either of these conditions is not difficult, but I'm having difficulty constructing one that satisfies both conditions. Any suggestions?

1

There are 1 best solutions below

0
On

Hmm. Only for fun, but not as something remotely practical.

Consider the 64 expressions of the form $\alpha_1 0 \alpha_2 0 \alpha_3 0 \alpha_4 0 \alpha_5 0 \alpha_6$, where $\alpha_i$ is either $(11)^*$ or $(11)^*1$. Together they will represent all strings that have five $0$'s and any number of $1$'s. Group 32 of them into an expression $E$ for an even number of $1$'s and 32 of them into expression $O$ for an odd number of $1$'s. Then your expression is $(E+OE^*O)^*$.

You can halve the size by first considering only strings that end in a $0$ (and omitting $\alpha_6$) and dealing with trailing $1$'s separately.