Formal Language and Automata Theory: Quiz 1 2013/10/30 Name:_________________ Reg.No.:___Solution________ Score:_______________ 1. [10pts] Let A= {01,1,101} and B = {0,10,110}. 1.1 Which of the following strings are in AB ? (a) 1010 (b) 1100 (c) 0101 (d) 110 (e) 10101 1.2 List all strings x in A3 with |x| < 5. ANS: 111, 0111, 1011, 1101 2. [15pts] Which of the following statements are correct? Let A,B and C are arbitrary languages. (a) If A B then CA CB (b) A (B C) = AB AC. (c) (A*)* = A* (d) If A2 A then A+ = A. (e) {x,y,z}* {xyz}*, where x,y and z are arbitrary strings. 3. [25pts] Given a DFA M shown below as a state transition diagram : M a b 1F 1 2 2 3 4 3 2 1 4F 3 4 (a) Fill the above table to get a complete state transition table for the DFA M. (b) Let M = (Q, , , s, F). Then what are the contents of Q, , , S and F, respectively. Q = _{1,2,3,4}__________ s =__1_________________ = __{a,b}_______________ F =__{1,4}_______________ = { (1,a,1),(2,a,3),(3,a, 2),(4,a,3), (1,b,)(2,b,4),(3,b,1),(4,b,4) } Note: Use triple (p,a,q) to represent the case that (p,a) = q. (c) For each input given in the table below, list the sequence of states traversed while running the machine with the input and determine if the input is accepted. 1 input Sequence of states traversed accepted? q1 yes abba 11243 no baab 12324 yes 4. [35pts] Let = {a,b}. Construct a DFA for each of the following languages. Use state transition diagram for your answer. Note: #c(x) denotes the number of occurrences of symbol c in x. (a) L1 = { x {a,b}* | x starts with a and ends with b }. a b b a a b a,b (b) L2 = { x{0,1}* | x contains the substring 001 0,1 1 0 0 1 0 1 (c) } L3 = { x{0,1}* | x ends with 1001 }. 0 1 1 1 0 1 0 0 1 0 (d) [5pts] Given two arbitrary binary number x= x1x2…xn and y = y1y2…yn of the same length, we want to determine if x > y. Let 2 = { (0,0),(0,1),(1,0),(1,1) }, and for the pair (x,y) of binary number x and y of the same length, let e(x,y)= (x1,y1) (x2,y2) …(xn,yn) be a string over 2. Design a DFA M such that L(M) = { e(x,y) | x and y are binary numbers of the same length and x > y.} ANS: M can be given as follows: (0,0) (1,1) (1,0) (0,1) 1 1 1 2 3 2F 2 2 2 2 3 3 3 3 3 2 5. [25pts] (a) Find a DFA M1 with two states: p,q such that L(M1) = { x | the length of x is odd }. (b) Find a DFA M2 with three states:1,2,3 such that L(M2) = { x | x ends with bb } Note: remember to mark starting and final states! M1 a b M2 a b p q q 1 1 2 qF p p 2 1 3 3F 1 3 (c) Use the product construction to generate a DFA M3 from M1 and M2 with the set of states {p,q}x{1,2,3} such that L(M3) = { x | The length of x is odd and x does not ends with bb. }. Give your answer using state transition table. [15pts] M3 a b p1 q1 q2 q1F p1 p2 p2 q1 q3 q2F p1 p3 p3 q1 q3 q3 p p3 6. [25pts] For a given alphabet , the regular expression over is defined inductively as follows: Basis: 1. The symbol e, , and every symbol a are regular expressions. Recursion: 2. If and are regular expressions, then so are (), (), and *. Given a regular expression , the language L() denoted by is defined inductively as follows: Basis: L(e) = {}, L()= {} and L(a) = {a} for every symbol a . Recursion: L(()) = L() L(), L(()) = L() L(), L(*)= L()*. For any string w = x1x2 · · ·xn, the reverse of w, written rev(w), is the string xn · · ·x2x1 ,i.e.,w written in reverse order. For any language A *, let rev(A) = {rev(w) | w A}. We now want you 3 to construct a mapping R from regular expressions to regular expressions such that if A = L(r) for some regular expression r, then rev(A) = L( R(r) ). The mapping R should be defined recursively as follows: (a) Basis: R(e) = _e___, R()= ___ and R(a) = ___a_______ for every a . (b) Recursion: R(()) = (R() + R()), R(()) = _(R() R())_, R(*)= _R()*__. (c) Show the correctness of your answer by proving that : for all regular expressions , rev(L()) = L( R()). Hint: Use induction on the structure of . [13pts] pf: The proof is by induction on the structure of . Basic cases: = e, , or a . Then rev(L(e)) = rev({}) = {} = L(e) = L(R(e)), rev(L()) = rev({}) = {} = L() = L(R()), and rev(L(a)) = rev({a}) = {a} = L(a) = L(R(a)). Ind. cases: = +, or * for some regular expressions . Then rev(L(+)) = rev(L() U L()) = rev(L()) U rev(L()) = L(R()) U L(R()) -- by ind.hyp. = L(R() + R()) = L(R()). rev(L()) = rev(L()L()) = rev(L()) rev(L()) = L(R()) L(R()) -- by ind.hyp. = L(R()R()) = L(R()). rev(L(*)) = rev(L()*) = (rev(L()))* = (L(R()))* -- by ind.hyp. = L(R()*) = L(R(*)) . 4