advertisement

CSC 320 Fall 2013: Assignment #2 Due at beginning of class, Tues. Oct. 8 Draw boxes for your marks. Place a 0 in the corresponding box for any questions you omit. Question 1 2 3 4 5 6 7 Marks It is not the job of the TA to verify complicated regular expressions or automata and either find a counterexample for you or prove that your solution is correct. To get marks for the questions, you must justify the correctness of your solutions. Questions #1 and #2 refer to the following languages: (a) {w ∈ {0, 1}* : w contains 1101110} (b) {w ∈ {a, b}* : w has bab as a prefix, and abb as a suffix} (c) {w ∈ {a, b}* : the number of a’s is odd and the number of b’s is even } (d) {w ∈ {a, b}* : w has both baba and baab as substrings} (e) {w ∈ {0, 1}* : w = does not contain 1111} (f) {w ∈ {0, 1}* : | w | is congruent to 1 or 2 modulo 3} 1. [15] Prove that any five of the above languages are regular by giving regular expressions for them. Clearly indicate the part you choose to omit. 2. [15] Prove that any five of the above languages are regular by designing DFA’s for them. Clearly indicate the part you choose to omit. 3. The exclusive or of two languages L 1 and L 2 , denoted L 1 ⊕ L 2 , is defined to be {w : (w ∈ L 1 or w ∈ L 2 ) and w is not in L 1 ∩ L 2 }. Suppose you are given two DFA’s M 1 = (K 1 , Σ, δ 1 , s1 , F 1 ) and M 2 = (K 2 , Σ, δ 2 , s2 , F 2 ). Your aim is to construct a DFA M = (K , Σ, δ , s, F) which accepts the exclusive or of L(M 1 ) and L(M 2 ). Each state of M corresponds to a pair in K 1 × K 2 and the significance of being in the state labelled (q, r) with q in K 1 and r in K 2 is that M 1 would be in state q and M 2 would be in state r after the same input. (a) [2] Which state should be the start state for M? (b) [2] Which states should be final states? (c) [4] Define the transition function δ of M in terms of δ 1 and δ 2 . -2- 4. (d) [4] Apply your construction to the following two DFA’s. M 1 = ({q 0 , q 1 }, {a, b}, δ 1 , q 0 , {q 1 }), where δ 1 = {(q 0 , a, q 0 ), (q 0 , b, q 1 ), (q 1 , a, q 0 ), (q 1 , b, q 1 )}. M 2 = ({r 0 , r 1 , r 2 }, {a, b}, δ 2 , r 0 , {r 0 , r 1 }), where δ 2 = {(r 0 , a, r 0 ), (r 0 , b, r 1 ), (r 1 , a, r 0 ), (r 1 , b, r 2 ), (r 2 , a, r 2 ), (r 2 , b, r 0 )}. (e) [3] How could you modify this construction to prove that regular languages are closed under intersection? The learning objective for this question is for students to understand reductions. In a reduction, you assume you have an algorithm for one problem, problem A. The goal is to use this algorithm as a black box to solve another problem, problem B. For an arbitrary reduction, it suffices to prove that if there is an algorithm for A then there is one for B. For an NP-completeness reduction, you want to show that if there is a polynomial time algorithm for A, then there is a polynomial time algorithm for B. Suppose you are given a boolean function IsEmpty( M): Input: A DFA M Returns: true if L(M) = φ and false otherwise. (a) [7] Describe a construction which given a DFA M 1 = (K 1 , Σ, δ 1 , s1 , F 1 ) and a string u = σ 1 σ 2 . . . σ k yields a DFA M 2 = (K 2 , Σ, ∆2 , s2 , F 2 ) so that if you call isEmpty(M 2 ) it returns the answer to the question: ‘‘Does M 1 accept any strings which have u as a prefix?’’ (b) [3] Give a regular expression for the language that the DFA M 1 = ({s, p, q, r}, {a, b}, δ 1 , s, {s, r}) accepts where δ 1 is given in this table: State Symbol Next State s a p s b q p a r p b p q a q q b r r a p r b q -3(c) [5] Show how to apply your construction from part (a) to the DFA M 1 from part (b) and the string u = a b a b a and draw a picure of the resulting DFA M 2 . 5. [15] Let M be a NDFA, M = ({ s, p, q, r, t } , {a, b} , ∆ , {s}, { p, r} ), where ∆ = {(s, ε , q), (s, a, p), ( p, a, q), (q, ε , t), (q, b, r), (r, b, t), (t, a, s), }. Use the algorithm in the text (which is the same as the one shown in class) to convert this NDFA to an equivalent DFA. (It would probably help to draw the state diagram first). 6. The goal of this question is to prove that L = {w ∈ {0, 1}* : w = 0r 1s where r ≤ s ≤ 3r} is not a regular language. 7. (a) [3] Describe all ways of factorizing the string w = 0r 12r as xyz so that y is not equal to the empty string. (b) [5] Use w = 0r 12r to prove that L is not regular where all you may assume is that the number of states k of a DFA M accepting L satisfies k ≤ 3r. (c) [2] The proof would be a lot easier (less cases and easier cases) with a different choice for w. Redo the proof with a more judicious choice for w in such a way that you have less cases to consider and all cases can be resolved by either pumping 0 times or pumping twice. Let L = {(abc)r a s : s ≥ r, and r, s ≥ 0}. Let w = ( a b c )n a n for some integers n and k such that k = 3n. (a) [9] Systematically enumerate all ways of factoring w as w = xyz such that | y | ≥ 1 and | xy | ≤ k. Number your cases so that you can refer to them easily for parts (b) and (c). (b) [3] If you use the pumping lemma and this string w to prove that L is not regular, for which cases from (a) can you pump zero times? Show what you get when pumping zero times in each of these cases and explain why the resulting strings are not in L. (c) [3] For the remaining cases, show what you get when you pump twice and explain why the resulting strings are not in L. Bonus: [6] Do questions #1 and #2 for all six languages.