This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: COMP 2805 — Solutions Assignment 2 Question 1: Give regular expressions describing the following languages. In all cases, the alphabet is { , 1 } . • { w : w contains an odd number of 1s or exactly two 0s } . Solution: * (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: * (1( ∪ ∪ 00 ∪ 000)1( ∪ ∪ 00 ∪ 000)) * 1( ∪ ∪ 00 ∪ 000) • { w : every even position in w is 0 } . (The positions are numbered starting with posi tion 1.) Solution: ∪ ∪ 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 { , 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 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: 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 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 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 M 5 Next, we apply the concatenate construction to...
View
Full
Document
This note was uploaded on 11/03/2011 for the course SCS COMP2805 taught by Professor Michielsmid during the Spring '11 term at Carleton CA.
 Spring '11
 MichielSmid

Click to edit the document details