Homework 1 Due September 20 1. Consider the state diagrams for two DFAs, M1 and M2 M1 M2 a. Give the formal descriptions of the two machines above specifically, specify the elements of the 5-tuple (Q, Σ, δ, q 0, F). For each machine Q =??, Σ =??, δ =??, q 0 =??, F =?? M1 Q={q1, q2, q3} Σ={x,y} q0: q1 F={q1} M2 Q={q1, q2} Σ={x,y} q0: q1 F={q2} q1 q2 q3 x q2 q1 q3 y q1 q3 q3 q1 q2 x q1 q1 y q2 q2 b. What sequence of states does the machine go through on input yyyx M1: q1, q1, q1, q1, q2 M2: q1, q2, q2, q2, q1 c. Are there an infinite number of strings accepted by the machine? M1: yes M2: yes d. Does the machine accept the string xxyyxx? M1: yes M2: no
2.The formal description of a DFA M3 is ({q 1, q 2, q 3, q 4, q 5 }, {0,1}, δ, q 2, {q 1, q 4 }) where δ is provided by the following table 0 1 Give the state diagram for this machine. q1 q3 q4 q2 q1 q5 q3 q2 q2 q4 q2 q5 q5 q1 q4 3. Not all context free grammars define regular languages. However, the following two DO define regular languages. For each grammar below, (a) describe the corresponding language (optimally in 10 words or fewer) and (b) draw the corresponding finite state machine. G1 -> A B A -> xa z B -> y w L={x n z, n>=0 or y or w}
G2 -> CD C -> nnc nn D -> pp L={(nn) k pp, k>0 } 3. Give state diagrams of DFAs recognizing the following languages. In all parts, Σ ={0,1}. a. The empty set b. {w the digits interpreted in binary are evaluated to 8 or higher} c. {w w has an even number of digits} d. {w the digits together sum to a number less than 3 }
4. a. Show that if M is a DFA that recognizes language B, swapping the accept and nonaccept states in M yields a new DFA recognizing the complement of B. Conclude that the class of regular languages is closed under complement. The complement of B (B ) is the language containing every string not in B. Each string not in B will bring you to a state in M that is NOT an accept state. In the machine M, each of these states ARE accept states. Furthermore, every string in B will bring you to an accept state in M; and will bring you to a NON-accept state in M. Thus, M recognizes B it accepts every string in B. Thus B is regular, since there exists a DFA that recognizes it. Therefore, regular languages are closed under complement. b. Show by giving an example that if M is an NFA that recognizes language C, swapping the accept and nonaccept states in M doesn t necessarily yield a new NFA that recognizes the complement of C. Is the class of languages recognized by NFAs closed under complement? Explain your answer. The string y is rejected by this NFA and bye the complement of this NFA The class of languages recognized by NFAs is closed under complement because every language recognized by an NFA is recognized by a DFA, so it is regular. The complement of each regular language is also regular, which means an NFA can be defined to recognize it. 5. Consider the alphabet Σ={0,1,2}. Given this alphabet, let Ak={w w is any sequence of numbers such that the number at the k th position is larger than the number at all previous positions}. For example, A3 includes 0010, 0011, 0012, 1120, 1022; A4 includes 01021, 11120, 00012, 110221. Show that for each k>1, the language Ak is regular. Proof by construction. For a given language Ak, we can define a DFA that recognizes this language. The DFA will contain 2k+3 states, q0,0, qreject, qaccept, qj,0 and qj,1. qj,0 represents that j characters have been entered already, and the largest character entered has been 0. qj,1
represents that j characters have been entered already and the largest character entered has been 1. The transition rules are: If 1<j<k: δ(q j 1,0, 0) = q j,0, δ(q j 1,0, 1) = q j,1, δ(q j 1,0, 2) = q reject δ(q j 1,1, 0) = q j,1, δ(q j 1,1, 1) = q j,1, δ(q j 1,1, 2) = q reject If j==k δ(q j 1,0, 0) = q reject, δ(q j 1,0, 1) = q accept, δ(q j 1,0, 2) = q accept δ(q j 1,1, 0) = q reject, δ(q j 1,1, 1) = q reject, δ(q j 1,1, 2) = q accept qreject transitions only to itself The start state is q0,0 This DFA will recognize language Ak. Because a DFA exists for each Ak, Ak must be regular. 6. Give state diagrams of NFAs with the specified number of states recognizing each of the following languages. In all parts, Σ={c,d} a. Accepts {w w has exactly 1 d s and an even number of c s} using four states. (Example accept strings: ccd, cdccc, d } b. Accepts {w w ends in cdc} using four states. (Example accept strings: cccdc, ddcdcc)
7. Use Theorem 1.45 in the text (also given in class) to provide an NFA state diagram for a machine that recognize the union of the languages L1 and L2 below. Note Σ = {0,1}. L1 = {w every even position in w has 1} L2 = {w w has 3 or more characters, and the second symbol is 1} 8. Use Theorem 1.47 in the text (also given in class) to provide an NFA state diagram for a machine that recognizes the concatenation of the languages in 3c and 3d. 9. Convert the following NFA to a DFA. You may wish to use the lecture/class method used to prove NFA-DFA equivalence.