0

I have to write a regular expression that accepts any odd binary number not preceded by a 0. the best I can come up with is $1(0\cup1)^*1$, but that doesn't match just 1. The best it matches is 11.

Raphael
  • 73,212
  • 30
  • 182
  • 400
Mirrana
  • 4,419
  • 6
  • 22
  • 22

1 Answers1

1

First you might just add that single $1$ to your expression as an alternative to what you already have. One obtains $1 \cup 1(0\cup 1)^*1$.

An alternative is $1(0^*1)^*$. That one is shorter, but not necessarily better.

Actually that expression I obtained by starting with the FSA below, and realizing that the rightmost two states could be replaced by iterating $0^*1$.

enter image description here

Hendrik Jan
  • 31,459
  • 1
  • 54
  • 109