Sei sulla pagina 1di 3

Problem Set 3

Ben Calvin September 23, 2012


1. (5 points)(Same as the textbook Excercise 2.5.2) Consider the -NFA shown below. (a) (1 point) Compute the -closure of each state. p : {p, q, r} q : {q} r : {r} (b) (2 points) Give all the strings of length three or less accepted by the automaton. a b c aa ba ca ab bb cb ac bc cc aaa baa caa aab bab cab aac bac cac aba cba abb cbb abc cbc aca bca cca acb bcb ccb acc bcc ccc

Table 1: Accepted strings of 3 or less. (c) (2 points) Convert the automaton to a DFA. state q0 q1 q2 a {p,q,r} {p,q,r} b {q,r} {r} c {p,q,r} {p,q,r}

{p,q,r} {q,r} {r}

Table 2: DFA Version of given -NFA. a,c b a,c Figure 1: Graphical representation of table 2. b

start

q0

q1

q2

2. (4 points) Design -NFA that accepts the set of strings consisting of either 01 repeated one or more times or 010 repeated one or more times. Try to use -transitions to simplify your design. q1 0 0 start q0 q3 1 q2

Figure 2: Graphical representation of table of the -NFA with inclusive or interpretation. This accepts any string that has 01s and 010s in it, but it can have both.

q1

q2

1 0

q6

start

q0

q3

q4

q5 0

q7

Figure 3: Graphical representation of table of the -NFA with exclusive or interpretation. This accepts any string that has 01s or 010s in it, but once it determines which pattern it follows, it cant deviate. 3. (6 points) Write regular expressions for each of the following languages. (a) (3 points) The set of strings of 0s and 1s with at most one pair of consecutive 1s. (0*10*)*( + 11 + 1)(0*10*)* (b) (3 points) The set of strings of as and bs that contain at lesat two bs that are not followed by an a. (a*b*)*(bb(b + a(a*b*)*bb))(a*b*)* 4. (4 points) Convert the following regular expressions to NFAs with transitions. 2

start

q0 1 q2

q1

q3

q4

q5

Figure 4: -NFA version of (0 + 1)01

start

q0

q1

0 q2 q3

0,1 Figure 5: -NFA version of 00(0+1)* 5. (6 points) GNU Emacs supports ... (a) (3 points) Give a search-and-replace command to change ... Use the command: ]\[ to nd each instance and replace it with ,. (b) (3 points) Emacs employs several extensions ... i. Given a le in which each line is a name in the form Lastname, Firstname change it so that the names appear as Firstname Lastname. Use reg-exp: \([A-Za-z][A-Za-z]*\)\(,\) \([A-Za-z][A-Za-z]*\) Replace with: \3 \1 ii. Swap the rst and third aguments in all calls to the function foo... Use reg-exp: \