Sei sulla pagina 1di 5
cor 355 ‘theory of Computing Spring 2021 - colbourn Nideers #1 24 February 2011 NAME [ie Semple ‘ASU ID ‘You have one hour and 15 minutes to complete the exam, Do not open the exam until instructed to do so. No notes, texts, computers, calculators, or communication devices are permitted. Write all answers on the examination paper itself, BUDGET YOUR TIME WELL! SHOW ALL WORK! Gasaioa 1 Gassiont TI - Gacaions To ‘Gassion Tr Gaaaon Toy Teal Ta Grades out of 60 in sorted order ate: $7 56 54 54 50 48 48 48 48.46.46 45 45 45 45 43 43 43 42 42 41 40 40 38 38 38 37 37 36 36 35 35 35 35 34 34 34 34 33.33 33 33 323231 31 31 303030 129 29 28 28 28 2727 27 27 27 26 25 24 24 24 24 23 23.23 2220 18 17 1413 13 1275. ‘Average is 33/60, Grades may be adjusted after the second midterm. Question 1. [15 marks total] For each ofthe following languages, say whether itis regular or not regular, and then show that your answer is correct (@) [5 marks] {cbs iti=ks Aj k> 0) ‘Suppose to the contraty that itis regular, and let p be the pumping constant. Consider the string oFa, ‘Then s has length atleast p and is inthe language. When we waite s=xyz_with [xy at ‘most pand ya east |v must contain only cs, and must contain some number n > 0 of them But then xyz oD, which is not inthe language because n> 0. This contradiction shows ‘thatthe pumping lemma does not apply, so the language is no regular. (0) [5 marks] {cba isis even or iki even} ‘This is egular. Tt means that ifthe number of e's is even, either the number of a's is even or the number of b's is even or both; and ifthe number of e's is odd, ether the number of as is odd or the number of b's is odd or bath. So a regular expression is (eo)¥((bb)*a* LU B*(aa)*) U e(ee)*(o(bb)*a* U bFa(aa)*) coe 355 ‘theory of Computing Spring 2011 ~ colbourn ‘ddtern #1 Page DoF o (©)IS marks] {cbbat i41 orjek) ‘This isnot regular, but you cannot prove it directly using the pumping lemma, because you can ALWAYS pump. (See an exercise on the third homework.) So we will have to use something else to allow us to pump. Call the language L, Then the reverse of L, which we cal R, is (atbe’: iff or jk}. Lis regular if and only if Ris gular ‘Suppose tothe contrary that R is regular, and let p be the pumping constant. Consider the string Pbfc!, ‘Then s has length at least p and isin the language. When we write s=xyz with xy| at ‘most p and jy at least 1, y must contain only c's, and must contain some number n > 0 of them. But then xy'z = a? "bc, which isnot in R because n> O and there isa single c. This contradiction shows thal the pumping lemma does not apply, so R isnot regular. So L isnot regular. (Las not expecting to sce any complete answers here. What I was looking for is the realization ‘that this language can be pumped, but is nonetheless not regular.) Question 2. [15 marks total] (a) [7 marks] Show that iL is accepted by an NFA (possibly with e-transiti regular language, then Lisa ‘The definition of regular language is “accepted by a DFA”, so what we need to dois to convert an arbitrary NFA to a DFA, Let (QE,8.goF) be the NEA, We form a DFA (Q'2,8',qo\F") follows. First for every subset S of Q, define E(S) as follows. Initially set E(S)~ S. Then, as long as there is an state qin for which 8(q,) is nota subset of S, add all states of (4,0) 10S. is initially empty. Set q” = E({qo}), and place gp in Q” As long as there isa state $ in Q” and a symbol x in ¥ for which 6(S,x) has not been defined yet, compute S' = E({r: © 8(q3x) for some qES}). IFS" isnot a state of Q’, add it Then set (5.x) =S.. lterate until 8(S,x) i defined for every state S of Q" and every symbol x in, Finally, set F* SEQ’ :FASisnotemply) (B) [8 marks] Consider the NFA M= (Q= {1,2.3.4,5},2= fab), 8, 1, (2)), where dis given by the following transitions: State | Input_[ New State 1 2 rp} 3 2 |» 2 2 1» 3 cox 955 ‘meory of Computing Spring 2011 - cotboura widters #1 Page 3 oF 6 ‘Draw a state diagram forthe NFA, and use your method from the (a) part to draw a state diagram for a DEA that accepts the same language. DFA o> NEA ith ab Gs) (fF eso” Question 3 {10 marks] Build a DFA to accept (a) [5 marks the language over {a,b,c} of strings that do not contain be or cb. Define a DFA (Q2,8,qaF) with Q=( go, 41, 42,45}, B=fabc}, Fol aa a1, G2} and 8 according to the following transition table S[a [ele i feof. It's fine to draw a state diagram instead. cor 355 ‘mneory of Computing 30) Spring 2021 - cotbourn wdterm #1 Page Core () {5 marks] the language of strings over {a in which the first and fourth symbols are differen, ‘assume that there must be at least four characters, otherwise “the fourth symbot” doesn’t make Define a DFA (Q.2,8,qaF) with Q=f an. 41, 42,45, 45,45,f 1}, B*(0,b}, to the following transition table, f}, and} according It's fine to draw a state diagram instead Question 4 [10 marks] (a) [3 marks] Give a DFA whose language Lis the set ofall strings over (a} containing an even numberof a's and any number of b's, Define a DFA (Q.2,8,q0.) with Q={ qu.a1}, 2=fab }, F=f qo} and 8 according to the following transition table. ESPacy ac} a: | a0 alaol ay tis fine to draw a state diagram instead. (0) [7 marks] Using your answer to the (a) part and a general method to form a regular ‘expression from a DFA, produce a regular expression for L. Describe your method. ‘Lam going to convert it to a GNFA (NFA with transitions labeled by regular expressions) in ‘which the start state has no entering transitions andthe final state has no leaving transitions. 1 vill then repeatedly remove a state q other than the start or final state as follows. For every two sates r,s other than g let A be the label on the transition from to, B the label on the one from, +104 C the label on the one from q to g, and D the label on the one from q tos. Replace the label on the transition from R to $ by AU (BC*D). Once this is done forall states rs other than 4, delete the state Do this until only two states remain, and the final label i the repular expression, I will show the GNFAs by giving the labels on the transitions for each pair of sates. The initial GNFA is cor 355 meory of computing xr Spring 2021 ~ colbourn iideerm #1 Page Sore TFrom To [staré | q0| al | final Sart Ble [oo ‘00 @ lb [a fe al Ola [b |e final S| |o1o Let's get rid of state ql. [From To [start [q0 nal art le zw 0. D_[buwbray |e ‘inal om z Let's get rid of state 0. TFrom To= [start [final ‘start [ou Gbay* ‘inal oo So the answer is (b U (ab*a))*. (Question 5 [10 marks] A grammar (V,2,R,S) is regular when every rule in R has one of the forms ‘A awith A in V and ain; ‘AaB with A,B in V anda ind; A—ewith Ain V. Show that a language is regular (ft is generated by a regular granmar. (By the answer to (a), it is enough to produce an NFA for the language.) In general Lhave to make a DFA to show tha itis regular, but by question 2(a),Ican make an ‘NFA instead! ‘We make an NFA (Q2,8.qnP) where Q=VU ta) ‘q¢ © 8(A.a) if and only if A + a with A in V anda in © 1 2. 3. 4. BE SA.) ifand only if A — aB with A,B in V and ain 2 5 6. qe (A, ) ifand only if A e with A in V. A derivation ofa string in the grammar yields an accepting computation ofthe string, and a ‘computation of the machine leading tothe final state corresponds o a derivation in the grammar. ‘So the language generated by the grammar is the same as that accepted by the NFA. Note: This was covered during our discussion of Chapter 1. It concerns regular languages, not context-free ones

Potrebbero piacerti anche