Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Regular expressions - odd amounts, as opposed to even

Options
  • 30-10-2011 4:14pm
    #1
    Registered Users Posts: 7,860 ✭✭✭


    Can someone answer this for me:

    Give a regular expression for "The set of all strings of 0's and 1's having an odd number of 0's".

    The input alphabet is obviously {0,1}. I understand the question, but I just don't know how to represent an odd amount of 0's in regular expression form. I could even draw a Finite State Machine to represent it!

    Any help appreciated.
    Thanks.


Comments

  • Registered Users Posts: 5,238 ✭✭✭humbert


    This looks like a sufficiently similar example. Although I only took a cursory glance at it.

    I think the approach would be to create an expression to find pairs of 0s that may or may not be consecutive, then find 0 to infinitely many of them, and finally check to make sure that sequence is followed by a 0.


    I'm sure there are other approaches.


Advertisement