Please give details of your calculation. A direct answer without explanation is not counted. Your answers must be in English. Please carefully read problem statements. During the exam you are not allowed to borrow others class notes. Try to work on easier questions first. Problem (5 pts). Consider the following lanagage A = { n n } Give a DFA state diagram for this language (no more than 3 states) Give the formal definition of your DFA 2. Consider the following lanagage B = {() n n } Give a DFA state diagram for this language (no more than 3 states) No need to give the formal definition of your DFA 3. Construct the state diagram of A B using the method used in Theorem.25 (i.e., the method before we introduced NFA). Please remove unnecessary states in final answer. No need to give the formal definition of your DFA., q q, q 2
Formal definition:m = (Q, Σ, δ, q, F ) Q = {q, q, q 2 } Σ = {, } F = {q } δ is described as q q q q q 2 q 2 q 2 q 2 q 2 2. q q 2 q, 3. q q q 2 q q q 2 q, 2 q 2 q 22, The simplified diagram is 2
q q 2 q q 2 q, 2 q 2 q 22, Problem 2 (5 pts). For any regular language A, consider the following way to generate language A.. Find a DFA M (Figure a) which recognizes language A. 2. Add an edge from each accepting state to the initial state with empty character. 3. Since we need to accept empty string, the initial state should also be an accepting state. 4. So we get a new NFA (Figure b). q... other states... q... other states... (a) original DFA M (b) new NFA Figure : A NFA generated from DFA M by the procedure in Problem 2. Give a DFA M with number of states = 2, such that the language generated by the procedure above is not A. You only need to give a state diagram, and you can assume Σ = {, }. 3
2. For a general DFA M = (Q, Σ, δ, q, F ), what is the formal definition of the NFA in Figure?. The following DFA recognizes Σ. q q 2 Following the procedure, we obtain the following NFA, which accepts any string, but we want it to recognize (Σ ) = Σ. q q 2, 2. The new NFA M = (Q, Σ, δ, q, F ), where F = F {q }, and {δ (q, σ)} if σ δ (q, σ) = {q } if σ = and q F φ if σ = and q / F. We intended to use NFA in Figure a, but wrongly stated DFA there. So the problem, while doable, is a bit strange. We grade this problem based on if you made some serious mistakes. Problem 3 (5 pts) Consider following NFA:,, q q 2 q 3 Please convert this NFA to DFA and remove unnecessary state in final answer. 4
, q φ q q 2 q 3, q 2 q 23 q 3, q 23 The simplified diagram is q, q 23 q 3, Problem 4 (2 pts) Given DFA in Figure.4. 2, r, r 2 q 2 q 2, r q 5
Σ = {r,,, 2} and we treat r as a single symbol. Transform it to a GNFA and then obtain a regular expression by sequentially removing state q 2, q, and q. Step, add q s and q a : 2 r r 2 q q 2 q 2 r q s q a Step 2, remove q 2 : ( 2) 2 r ( r) q r 2 ( r) q 2 2 q s q a Step 3, remove q : r 2 ( r) ( 2 2)( ( 2)) (2 r ( r)) q q s q a 6
Step 4, remove q : q s ( r 2 ( r) ( 2 2)( ( 2)) (2 r ( r))) q a The regular expression is ( r 2 ( r) ( 2 2)( ( 2)) (2 r ( r))). Common Mistakes. Forget at the final step. 2. Missing parentheses. For example, someone wrote ( ( 2)) 2 r ( r) rather than ( ( 2)) (2 r ( r)). Problem 5 (5 pts) Is the following language regular? L = { i j gcd(i, j) = }, where gcd(i, j) means the greatest common divider of i and j. Explain your answer clearly. No. Assume the language is regular. By pumping lemma, there is a positive integer p such that for all s L, s = xyz satisfying the following conditions: y xy p for all i, xy i z L Let s = q (q )!, where q is the smallest prime p. Then, gcd(q, (q )!) =. Since q p, y must be k for some k. For i =, xy z = (q k) (q )!, but gcd(q k, (q )!) = q k if k. We have proved xy z / L and got a contradiction, so the language L is not regular. 7
Problem 6 (2 pts) Is the following language regular? L = {uww R v u, v, w {, } +, u v }, where {, } + means the set of strings which are composed of and ( is not included). And w R means the reverse of the string w. Explain your answer clearly. No. Assume the language is regular. By pumping lemma, there is a positive integer p such that for all s L, s = xyz satisfying the following conditions: y xy p for all i, xy i z L Let s = () p () p. We have s L because we can choose w =, u = () p, and v = () p. And the only way to cut s to uw and w R v is to cut between () p and () p. For this case, u = v, uw = () p, w R v = () p. And because () p p, y must be some part of () p. Now we claim for i =, xy z / L. Since u v, uw w R v, and there is no way to cut () p, the possible cut we can find in xy z to let uw longest is the cut we found in s. Since we take off some part of () p (the y), uw < w R v, and u < v. We can claim xy z / L by the above statments and get a controdiction. So the language L is not regular. Other Solutions You can choose s to be () p () p or 2p () p. They can both be used to obtain a contradiction. Common Mistakes. When you choose a string s, you cannot sepcity x, y, or z there. For example, you cannot choose s to be p y y p 2. 2. You can not choose the pumping length. 8