02.06.2013 Views

Solutions to Ass. 2 and few more questions from textbook

Solutions to Ass. 2 and few more questions from textbook

Solutions to Ass. 2 and few more questions from textbook

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 5, Exercise 12, pg 72<br />

i)<br />

-<br />

a<br />

b<br />

+<br />

b<br />

a<br />

University of Ottawa<br />

School of Information Technology <strong>and</strong> Engineering<br />

a,b<br />

FIN Not a FA<br />

+<br />

CSI 3104/3504, Winter 2006<br />

Solution of <strong>Ass</strong>ignment #2<br />

a<br />

b<br />

The changed FIN is not a FA because the start state has <strong>more</strong> than one path for a.<br />

ii)<br />

b<br />

a<br />

b<br />

b<br />

-<br />

a<br />

+<br />

FIN NIF<br />

-<br />

+<br />

b<br />

a<br />

a,b<br />

iii) The language accepted by NIF is the reverse of every word in the language accepted by FIN. If there<br />

was a path <strong>from</strong> one state <strong>to</strong> another on FIN by a sequence of letters, then there must be a path on NIF<br />

using the sequence backwards.<br />

iv)<br />

-<br />

+<br />

FIN<br />

a,b<br />

The words accepted by this FA are not limited <strong>to</strong> palindromic words. It accepts the non-palindrome words<br />

ab <strong>and</strong> FIN = NIF.<br />

a<br />

a<br />

-<br />

b


Chapter 5, Exercise 18, pg 74<br />

We start in state 1 <strong>and</strong> remain there until we encounter an a. State 2 = we have just read<br />

an a. Scan any a’s <strong>and</strong> return <strong>to</strong> state 1 on reading c. State 3 = we have read a b following an a. Reading<br />

an a puts us back <strong>to</strong> state 2 <strong>and</strong> reading a b sets us back <strong>to</strong> state 1. However, state 4 = we have just found a<br />

substring abc, <strong>and</strong> if the whole sequence was read the string is accepted.<br />

Now states 4, 5 <strong>and</strong> 6 exactly mirror states 1, 2 <strong>and</strong> 3. Returning <strong>to</strong> state 1 indicates that we just found<br />

another occurrence of the substring abc. Being in one of the first three states means that we have read an<br />

even number of abc substrings (if any) <strong>and</strong> are in the midst of finding another one. Ending in an accepting<br />

state, 4. 5 or 6, means that we have read an odd number of abc's.<br />

Chapter 6, Exercise 20, pg 91<br />

i) In a machine without Λ-edges, every transition consumes at least one letter of input. Therefore, we know<br />

that Step 2 is true. The list in Step 3 is exhaustive; it includes all possible paths through the machine<br />

(where a path is represented by the sequence of integers that number its consecutive edges) <strong>and</strong> also<br />

sequences of integers that cannot represent paths because the edges are discontinuous in the graph. There is<br />

an upper bound on the magnitude of the integers used as edge numbers <strong>and</strong> on the length of the sequence.<br />

Since the list is finite , we can actually check it for the two required characteristics: 1) Does the sequence<br />

represent a path <strong>from</strong> a start state <strong>to</strong> a final state, <strong>and</strong> 2) when we concatenate the edge labels, does the<br />

result match the word we are testing? Since all possible paths are listed, if our test word has a path we must<br />

find it. Since we test paths for validity at Step 4, we are not deceived by matching edge labels on an<br />

invalid path. The list <strong>and</strong> the procedures we apply <strong>to</strong> it are finite <strong>and</strong> so this algorithm must terminate.<br />

(ii) In a machine with Λ-edges, it is not true that every transition consumes at least one letter of input. We can use<br />

infinitely many Λ-transitions without consuming any letters at all, <strong>and</strong> therefore we cannot set an upper<br />

bound on the length of the path that gives us the test word.


Chapter 7, Exercise 1(v), pg 142<br />

a<br />

bb<br />

-<br />

-<br />

a<br />

a<br />

ab<br />

-<br />

!<br />

abb<br />

ba<br />

bb+abb+abba<br />

+<br />

a*(bb+abb+abba)(a+b)*<br />

!<br />

+ a,b<br />

a<br />

bb<br />

a<br />

bb<br />

-<br />

-<br />

abba<br />

The regular expression : a*(bb+abb+abba)(a+b)*<br />

= a*bb(a+b)*<br />

a,b<br />

+<br />

!<br />

abb<br />

!<br />

+<br />

abb+abba<br />

+<br />

!<br />

a,b<br />

a,b


Chapter 7, Exercise 3(ii), pg 143<br />

Old state New State a New State b New State<br />

W1, y1 Z1- W2, y2 Z2+ W1,y3 Z3<br />

W2,y2 Z2+ W2,y4 Z4+ W1,y3 Z3<br />

W1,y3 Z3 W2,y2 Z2+ W1,y4 Z5+<br />

W2,y4 Z4+ W2,y4 Z4+ W1,y4 Z5+<br />

W1,y4 Z5+ W2,y4 Z4+ W1,y4 Z5+<br />

w1 or y1<br />

-<br />

a<br />

b<br />

w2 or y2<br />

+<br />

w1 or y3<br />

Chapter 7, Exercise 5(i), pg 143<br />

b<br />

b<br />

w1 w2 or x1<br />

-<br />

a<br />

a<br />

a<br />

b<br />

a<br />

w2 or y4<br />

+<br />

+<br />

w1 or y4<br />

w2 or x1 or x2<br />

a<br />

b<br />

a<br />

b<br />

w1 or x1<br />

a<br />

b<br />

a<br />

b<br />

b<br />

w1 or x3 or x1<br />

+<br />

b<br />

a<br />

b<br />

w2 or x1<br />

or x2 or x3<br />

+<br />

a


Chapter 7, Exercise 6(ii), pg 144<br />

Old state New state a New state b New state<br />

Z0+/- X2 Z2 X1 Z1<br />

X1 Z1 X2 Z2 X1 Z1<br />

X2 Z2 X2 Z2 X3,x1 Z3+<br />

X3,x1 Z3+ X3,x1,x2 Z4+ X3,x1 Z3+<br />

X3,x1,x2 Z4+ X3,x1,x2 Z4+ X3,x1 Z3+<br />

+<br />

-<br />

a<br />

a<br />

x2<br />

b<br />

a<br />

x1<br />

b<br />

b<br />

+<br />

b<br />

x3 or x1<br />

Chapter 8, Exercise 13, pg 167<br />

i)<br />

a<br />

b<br />

+<br />

a<br />

x1 or x2 or x3<br />

ii) There is no way of knowing when the last letter is read <strong>and</strong> its time <strong>to</strong> print the letter that was read<br />

first.


Chapter 9, Exercise 5, pg 185<br />

L1: (a+b)b(a+b)*, it means all strings that has the second letter <strong>to</strong> be b;<br />

L2: (a+b)*aa(a+b)*, it means all the strings that contain the substring aa;<br />

x1<br />

a,b<br />

x2 x3<br />

- +<br />

FA1<br />

b<br />

a,b<br />

a x4<br />

a,b<br />

w1 w2 w3<br />

a<br />

- +<br />

L1 L2<br />

x1 x2 x3<br />

-<br />

+<br />

a,b<br />

+<br />

FA' 1<br />

The FA of L'1 + L'2:<br />

-<br />

+<br />

a<br />

b<br />

x2 or w2<br />

+<br />

x2 or w1<br />

+<br />

a<br />

b<br />

b<br />

a<br />

b<br />

a<br />

x4 or w3<br />

+<br />

x3 or w1<br />

+<br />

b<br />

x4 or w2<br />

+<br />

a<br />

+<br />

x4<br />

a<br />

a,b<br />

b<br />

b<br />

a,b<br />

a,b<br />

x3 or w2<br />

+<br />

a<br />

x4 or w1<br />

+<br />

a<br />

b<br />

-<br />

+<br />

b<br />

b<br />

a<br />

b<br />

b<br />

+<br />

a<br />

FA'2<br />

a<br />

FA2<br />

w1 w2 w3<br />

x3 or w3<br />

a,b<br />

a,b<br />

a,b


The FA of L1 ∩ L2 = (L'1 + L'2)' is:<br />

x1 or w1<br />

-<br />

a<br />

b<br />

x2 or w2<br />

x2 or w1<br />

a<br />

b<br />

a<br />

x4 or w3<br />

x3 or w1<br />

b<br />

x4 or w2<br />

Simplifying the FA of L1 ∩ L2,<br />

Regular Expression:<br />

(a+b)b(a+b)*aa(a+b)*<br />

b<br />

z1<br />

-<br />

a<br />

a,b<br />

x3 or w2<br />

a<br />

a +<br />

a<br />

b<br />

b<br />

b<br />

a<br />

x4 or w1<br />

z3<br />

z2<br />

a<br />

a,b<br />

b<br />

x3 or w3<br />

b<br />

a,b<br />

a<br />

z4 z5<br />

b<br />

b<br />

a<br />

z6<br />

+<br />

a,b

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!