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 first n states being used to count off an and the last m states is a loop. Q = {q0 , q1 , . . . , qn+m−1 } 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 briefly 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 a’s. 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 .


bb respectively and “remember” it. q3 } b (d) All NFSA (30 pts. it accepts w only if there exist 5 different computation paths for w from the start state to each one of the accepting states.b q5 b a b q4 a q7 b q8 a a a. Solution. a a b a b a start {q0 } {q0 . q1 } {q0 . q5 .b start q0 b q2 a b q6 b b a. (c) Rabin-Scott algorithm (30 pts.ba.ab.b q3 a q1 a a. You may skip any dead or inaccessible states to simplify your answer.b The states all have meanings. The new DFSA obtained by converting the NFSA for L1 is. Show the entire process including the transition table and provide a transition diagram. 2 .) We define an All NFSA to be a NFSA which has no -moves and it accepts a word w if there exist (different) computation paths for w that end in each one of its accepting states.) Convert your NFSA from part 2(a) for language L1 into a DFSA using the Rabin-Scott algorithm. q2 } {q0 . q6 each represent that the input string has been aa.a. for instance q3 . q4 . Thus if an all NFSA has 5 accepting states.

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

Sign up to vote on this title
UsefulNot useful

Master Your Semester with Scribd & The New York Times

Special offer: Get 4 months of Scribd and The New York Times for just $1.87 per week!

Master Your Semester with a Special Offer from Scribd & The New York Times