0% found this document useful (0 votes)
45 views3 pages

hw02 Sol

Uploaded by

AC
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views3 pages

hw02 Sol

Uploaded by

AC
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

CS181 Spring 12 - (partial) Solutions to Problem Set 2

1. Formalizing DFSAs (20 pts.) Let LAP (n, m), n 0, m > 0 be the language of strings over = {a} whose lengths are in an arithmetic progression. Formally, LAP (n, m) = {an+km | k 0}. Give a formal (mathematical) description of a DFSA for LAP (n, m) (that is, give the 5-tuple M = (Q, , , q0 , F )). Solution. Consider the following 5-tuple, M = (Q, , , q0 , F ) with = {a}. We will have a total of n + m states in the DFSA with the rst n states being used to count o an and the last m states is a loop. Q = {q0 , q1 , . . . , qn+m1 } F = {qn } (qi , a) = qi+1 , if i = n + m 1 qn , if i = n + m 1

2. Nondeterministic Finite State Machines (20 pts.) Give a NFSA (by transition diagram) for each of the following languages. Also briey explain how your machine works. You may not use -moves. No credit for DFSAs. Verify you answer by performing a sanity check. Assume = {a,b}. (a) L1 = the set of all strings over {a,b} such that the string ends with a b followed by 2 or more as. For example, abaabbaaaa L1 , but abaabba L1 , aaaaa L1 . Solution. The following NFSA accepts L1 . a,b a start q0 b q1 a q2 a q3

(b) L2 = the set of all strings over {a,b} such that the string has atleast 4 characters and the string starts and ends with the same two letters. For example, abab,aabaaa,bbbbb L2 but aaa,abaa,baab L2 . Solution. The following NFSA accepts L2 . Edges analogous to the one from q4 are to be added to q3 , q5 and q6 .

a,b q3 a q1 a a,b start q0 b q2 a b q6 b b a,b q5 b a b q4 a q7 b q8 a a

a,b The states all have meanings, for instance q3 , q4 , q5 , q6 each represent that the input string has been aa,ab,ba,bb respectively and remember it. (c) Rabin-Scott algorithm (30 pts.) Convert your NFSA from part 2(a) for language L1 into a DFSA using the Rabin-Scott algorithm. Show the entire process including the transition table and provide a transition diagram. You may skip any dead or inaccessible states to simplify your answer. Solution. The new DFSA obtained by converting the NFSA for L1 is, a a b a b a

start

{q0 }

{q0 , q1 }

{q0 , q2 }

{q0 , q3 }

b (d) All NFSA (30 pts.) We dene an All NFSA to be a NFSA which has no -moves and it accepts a word w if there exist (dierent) computation paths for w that end in each one of its accepting states. Thus if an all NFSA has 5 accepting states, it accepts w only if there exist 5 dierent computation paths for w from the start state to each one of the accepting states. 2

i. Show that for every DFSA M there exists an all NFSA N that accepts the same language. ii. Given an all NFSA N , construct a DFSA which accepts the same language using the Rabin-Scott algorithm. Specically highlight the dierences between the above conversion and one that involves converting a standard NFSA to a DFSA. Solution. i. Observe that if an All NFSA has only one nal state, then it accepts the same language as when viewed as a standard NFSA. Thus we will convert our DFSA (which may have many nal states) into a NFSA which has only one nal state. This can be done by adding a new nal state and adding -moves to this new state from the old nal states. Then by applying the process of -elimination, we obtain a new NFSA with only one accept state and no -moves which gives us the needed all NFSA. Note that the new nal state that you create will also be an initial state IFF the original DFSA had its initial state as an accept state. ii. We note that the Robin Scott algorithm is exactly applicable for All NFSAs too with one minor modication. The set of nal states in the new DFSA will be any set S which is contains the set of all nal states of the original all NFSA. This will be the only modication that will be necessary.

You might also like