开发者

Finding a regular expression

I have a simple question about finding a regular expression for a given language.

I am given the language L where:

L = {w ∈ {0, 1}* : w has exactly one pair of consecutive zeros}

My first attempt at this was to t开发者_开发百科ry L( (0 + 1)* 00 (0 + 1)*), but I noticed the problem with that would be with where I have (0 + 1)* because if 0 is chosen, it can be zero more more of them, thus leading to more than one pair of consecutive zeros.

I also know, that the possible cases I have are, two zeros in the front, in the middle, and at the end. I just am not quite sure how to create a regular expression for that.

Any help is much appreciated.


Try this:

1* (011*)* 00 (11*0)* 1*

An explanation:

  • 1*: any amount of leading 1’s
  • (011*)*: if there is a 0 before the 00, it must not be followed by another 0, thus only one or more 1’s are allowed; this pattern may be repeated any number of times
  • 00: the two 0’s
  • (11*0)*: if there is a 0 after the 00, it must not preceded by another 0, thus only one or more 1’s; this pattern may be repeated any number of times
  • 1*: any amount of trailing 1’s


The best possible answer for this problem is (1 + 01)* 00 (1 + 10)*


i believe it would be like this

((1*)(01)*))* 00 ((11*)0)*1*


The sequence:

  • Anything but 00, ending with 1
  • 00
  • Anything but 00, starting with 1


My answer would be : (1 + 01) 00 (1 + 10)**

Explanation:

The consecutive zeros shouldn't be preceded or followed by another zero. Hence 00 should be preceded by a 1 which can be either a 1 or 01. It can be followed by a 1 or 10.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜