-1
$\begingroup$

I'm trying to write a regular expression over the alphabet {0,1,2} for the language in which every 1 is preceded by 0. For example 2200201010, 01022020102012 are strings of the language.

I've tried with this:

(0+2)*(01)*(0+2)*(01)*(0+2)*

, where '+' means {0,2,00,02,20,22,.....}. Is this reg-exp correct? Thank you

$\endgroup$
  • $\begingroup$ Why not? The '*' include zero, one or more $\endgroup$ – Alberto Jun 18 '17 at 16:09
  • $\begingroup$ Right. But it doesn't include 01201201. $\endgroup$ – Yuval Filmus Jun 18 '17 at 16:20
  • $\begingroup$ Right. Should I put that expression in another ( ... ) * ? $\endgroup$ – Alberto Jun 18 '17 at 17:18
  • $\begingroup$ Something of this sort. $\endgroup$ – Yuval Filmus Jun 18 '17 at 17:33
  • $\begingroup$ We discourage "please check whether my answer is correct" questions, as only "yes/no" answers are possible, which won't help you or future visitors. See here and here. Can you edit your post to ask about a specific conceptual issue you're uncertain about? As a rule of thumb, a good conceptual question should be useful even to someone who isn't looking at the problem you happen to be working on. If you just need someone to check your work, you might seek out a friend, classmate, or teacher. $\endgroup$ – D.W. Jun 19 '17 at 6:09
1
$\begingroup$

(01+2+0)* this may work because the string will contain any combination of given inputs and a 1 will always be preceded by a 0.

$\endgroup$
  • $\begingroup$ This should be best solution. Thanks :) $\endgroup$ – Alberto Jun 18 '17 at 20:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.