homework #3 solutions

9
Homework #3 Solutions

Upload: toyah

Post on 02-Feb-2016

88 views

Category:

Documents


1 download

DESCRIPTION

Homework #3 Solutions. #1. True or False. a a b a matches a* + b* T F b) babab matches b (ab)* T F c) If A = F then A B = F for all languages B T F d) If A = { e } then A B = F for all languages B T F - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Homework #3  Solutions

Homework #3 Solutions

Page 2: Homework #3  Solutions

#1. True or False

a) a a b a matches a* + b* T F

b) babab matches b (ab)* T F

c) If A = then A B = for all languages B T F

d) If A = {} then A B = for all languages B T F

e) If A = a* and = {a,b}, then * - A = b* T F

Page 3: Homework #3  Solutions

#2. Write regular expressions for the set of strings of 0’s and 1’s with at most one pair of consecutive 1’s

• Exercise says “at most one” occurrence of “11”, so start with

( + 1 + 11)

• Now build around it the combination of 1’s and 0’s that will prevent another occurrence of “11”:

In front: (0 +10)*After: (0 + 01)*

• So altogether: (0 +10)* ( + 1 + 11) (0 +10)*

Page 4: Homework #3  Solutions

#3. Draw the graph for the following DFA and then convert to regular expression.

This gives you an idea how messy these are, and how you’d really like to plug them into a computer program!

1. Using Sudkamp method: Eliminating “r”:

p s

q

1

1

0 + 10*1

0

0

Page 5: Homework #3  Solutions

#3 continued

• Then eliminating “s”

• Eliminating “q”

p

q

1

0 0(0 + 10*1)

1(0 + 10*1)

p

1+ (0(0 + 10*1))(1(0 + 10*1))*0

• Now we * the expression on the loop to get the regular expression:(1 + (0(0 + 10*1))(1(0 + 10*1))*0)*Whew!

Page 6: Homework #3  Solutions

#3 continued Using Kozen Method removing qpp

pqrs = ppprs + pq

prs (qqprs )*qp

prs

pp

prs = 1*

pqprs = 1*0 (0 +10*1)

qqprs = 01*0 (0 + 10*1) + 1 (0 +10*1)

qpprs = 01*

So pppqrs = 1* + 1*0 (0 +10*1) (01*0 (0 + 10*1) + 1(0+10*1 )* 01*

I’m sure this can be simplified. If anyone wants to send me their simplification, I’ll post it with full credit to the sender!

Page 7: Homework #3  Solutions

#4. Does (R +S)* S = (R*S)* ? Justify your answer

• No

• Counter-example: if is not in S, then they are not equal.

Page 8: Homework #3  Solutions

#5. What does the Perl expression: s/(^[A_Z]{1})([az]+)\.sgml/\1\2\.html/g tr/a-z/A-Z/ say to do?

• Converts file names with extension “sgml” to file names with extension “html”,

• and changes all letters to upper-case

Page 9: Homework #3  Solutions

#6. What do you think the regular expression on

the Module 3 page represents?

• Looks like “social security numbers”