{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

solutions-ass2 - COMP 2805 Solutions Assignment 2 Question...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
COMP 2805 — Solutions Assignment 2 Question 1: Give regular expressions describing the following languages. In all cases, the alphabet is { 0 , 1 } . • { w : w contains an odd number of 1s or exactly two 0s } . Solution: 0 * (10 * 10 * ) * 10 * 1 * 01 * 01 * • { w : w contains an odd number of 1s and each 1 is followed by at most three 0s } . Solution: 0 * (1( 0 00 000)1( 0 00 000)) * 1( 0 00 000) • { w : every even position in w is 0 } . (The positions are numbered starting with posi- tion 1.) Solution: 0 1 ((0 1)0) * ((0 1)0) * (0 1) Question 2: Use the construction given in class (and described in the notes) to convert the regular expression (0(10) * 1 1) * to an NFA. The alphabet is { 0 , 1 } . Solution: We first consider how the regular expression is “built”: Take the regular expressions 1 and 0, and concatenate them into the regular expression 10. Take the regular expression 10, and take its star to get the regular expression (10) * . Take the regular expressions 0 and (10) * , and concatenate them into the regular ex- pression 0(10) * . Take the regular expressions 0(10) * and 1, and concatenate them into the regular expression 0(10) * 1. Take the regular expressions 0(10) * 1 and 1, and union them into the regular expression 0(10) * 1 1. Take the regular expression 0(10) * 1 1, and take its star to get the regular expression (0(10) * 1 1) * . 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
First, we construct an NFA M 1 that accepts the language described by the regular expression 1: 1 M 1 Next, we construct an NFA M 2 that accepts the language described by the regular ex- pression 0: 0 M 2 Next, we apply the concatenate construction to M 1 and M 2 . This gives an NFA M 3 that accepts the language described by the regular expression 10: M 3 1 0 Next, we apply the star construction to M 3 . This gives an NFA M 4 that accepts the language described by the regular expression (10) * : 1 0 M 4 Next, we apply the concatenate construction to M 2 and M 4 . This gives an NFA M 5 that accepts the language described by the regular expression 0(10) * : 1 0 M 5 0 Next, we apply the concatenate construction to M 5 and M 1 . This gives an NFA M 6 that accepts the language described by the regular expression 0(10) * 1: 2
Background image of page 2
1 0 0 M 6
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.
  • Spring '11
  • MichielSmid
  • Formal language, Formal languages, Regular expression, Regular language, Nondeterministic finite state machine

{[ snackBarMessage ]}