-2
$\begingroup$

My answer : (0+1)* 0 (0+1)* 0 (0+1)*

Why is this incorrect? Can somebody explain to me what the correct answer is and why?

$\endgroup$
  • 10
    $\begingroup$ The regular expression is correct. $\endgroup$ – rgrig May 10 '12 at 17:35
  • 2
    $\begingroup$ Looks good to me. Who says not? $\endgroup$ – David Lewis May 10 '12 at 17:40
  • 2
    $\begingroup$ A simpler expression would be $1^*01^*0(0|1)^*$. $\endgroup$ – Artem Kaznatcheev May 10 '12 at 22:12
  • 2
    $\begingroup$ @kaveh $(0+1)$ is quite standard, I see no confusion here. It is used interchangeably with $(0|1)$ and $(0\cup1)$. $\endgroup$ – Ran G. May 11 '12 at 1:42
  • 1
    $\begingroup$ @Kaveh I have no doubt in your means. Yet, the OP might not understand the ambiguity (especially if the OP is new to this). IMHO, the answer of svick is the one that should be clarified as it uses the plus sign in a non-orthodox way. $\endgroup$ – Ran G. May 11 '12 at 5:43
-2
$\begingroup$

It's incorrect for example because it does not match the string $100$.

The two zeroes would have to match the two zeroes in your regexp that are ouside the parentheses. Because of that, $(0\!+\!1)^*$ would have to match $1$, but it doesn't. That's because $(0\!+\!1)^*$ implies there has to be at least one zero for every $1$.

I think the regular expression that you meant is:

$$(0|1)^* 0 (0|1)^* 0 (0|1)^*.$$

$\endgroup$
  • 4
    $\begingroup$ I think the OP thought that $+$ meant the same as $|$, in fact, I thought that too when I read the question, but checking wikipedia does tell me that I am wrong, since $a+$ just means $aa^*$. $\endgroup$ – Artem Kaznatcheev May 10 '12 at 22:15
  • $\begingroup$ Yeah, that's most likely. And other people here probably thought the same. $\endgroup$ – svick May 10 '12 at 22:16
  • 1
    $\begingroup$ I think it would be helpful if you stressed that in your answer more (i.e. that $a+b$ does not mean $a|b$ but means $aa^*b$). $\endgroup$ – Artem Kaznatcheev May 10 '12 at 22:17
  • 4
    $\begingroup$ What? $a+b$ does mean alternation in most theoretical treatments of regular expressions. E.g., books.google.co.uk/… $\endgroup$ – rgrig May 10 '12 at 22:54
  • 6
    $\begingroup$ @Artem: I am pretty sure $a+b$ is not standard notation for $a a^*b$? Probably $a^+b$ might be. Where on Wikipedia did you see $a+$ meaning $aa^*$? $\endgroup$ – Tara B May 11 '12 at 8:36

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.