0% found this document useful (0 votes)
224 views100 pages

Formal Languages & Automata

Uploaded by

Kamal Thakur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
224 views100 pages

Formal Languages & Automata

Uploaded by

Kamal Thakur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 100
FORMAL LANGUAGES & AUTOMATA PAPER CODE: PCC-CSE-305-G 5th Semester | PREVIOUS YEAR’S SOLVED Ol 0 Tye ey PAPERS For B.Tech. STUDENTS Solved By A TEAM OF EXPERIENCED FACULTY PUBLICATION Website : www.rgpublication.in Email : rgpublishinghouse@gmail.com IRRMAL LANGUAGES & AUTOMATA Model Test Paper - I Paper Code:-PCC-CSE-305-G. ———————————— eee Note : Aitempt five questions in all, selecting one question from each Section. Question No. 1 is compulsory. All questions carry equal marks. Q.1.(a) Explain at least four differences between DFA and NFA. Ans, Differences between DFA and NFA are as follows : (1) “DFA” stands for “Deterministic Finite Automata”, while “NFA” stands for “Nondeterministic Finite Automata.” (2) Both are transition functions of Automata. In DFA the next possible state is distinctly set, while in NFA each pair of state and input symbol can have many possible next states. (3) NFA can use empty string transition, while DFA cannot use empty string transition. (4) NFA is easier to construct, while it is more difficult to construct DFA. (5) Backtracking is allowed in DFA, while in NFA it may or may not be allowed. (6) DFA requires more space, while NFA requires less space. : (7) While DFA can be understood as one machine and a DFA machine can be constructed for every inputand:output, But'NFA can be understood as several little machines that compute together, and there is no possibility of constructing an NFA machine for every input and output. Q.1.(b) Explain Moore machine with the help of transition table and also draw transition diagram: of the. given transition table. Ans. Moore machine : It is the FA in .which;output is. associated with each state. In moore machine every state of this finite machine has a fix output. f Mathematically moore machine is a six-tuple machine and defined as M, = (Q,2,4,8,2',q,) M, is the six-tuple moore machine in which Q : Anonempty finite set of state of M,. mad =: Anonempty finite set of input symbols. A : Anonempty finite set of outputs. & : Itis transition function which takes two arguments as in finite automata, one is input state and another input symbol. The output of this function is a single state, so clearly 8 is the function which is responsible for the transitions in M,. q, : isthe initial state of M, and q, € Q. 2: isamapping function which maps Q to A, giving the output associated with each state. ‘ Let M, be a moore machine and Z is a,, a,, 4, ... a,, 7 > 0 then output of M, for 2 is RG), q), N(G,)oue M(q,)s WhETE Joy Vs Iq» + J, iS the sequence of states such that 8,4) = 4,forl a, B—> 6. Then Gis in Chomsky normal form. een ol Greibach normal form : Greibach normal form (GNF) is another normal form quite free grammer generating the set accepted by useful in some proofs and constructions. A context- a pushdown automation is in Greiback normal form. : ee Definition : A context-free grammer is in Greibach normal form if every production is of the form A — ac, where @ € Vy and a E(amay be A), and SA isin Gif A € L(G). When Ae L(G), we assume that S does not appear on the R.H.S. of any production. For example, G given by S aAB| A, A > bC, Bb, C- cis in GNF. Q.1.(d) Define Turing machine mathematically and also explain its basic structure. Ans. A Turning machine M isa 7-tuple, namely (Q, 2, T, 5, q,, 5, F), where (1) Qisa finite nonempty set of states. (2) Tis a finite nonempty set of tape symbols. (3) be Tis the blank. (4) Zis a nonempty set of input symbols and is a subset of and b ¢ E. (5) Sis the transition function mapping (q, x) onto (q’, y, D) where D denotes the direction of movement of R/W head; D = L or R according as the movement is to the left or right. (6) q€ Qis the initial state, and (7) F CQis the set of final states. The Turning machine can be thought of as finite control connected to a R/W (read/ write) head. It has one tape which is divided into a number of cells. The block diagram of the basic model for thé Turning machine is given in Fig. RW head Tape divided into cells: ‘and of infinite length Finite control Fig. : Turning machine model Each cell can store only one symbol. The input to and the output from the finite state automaton are effected by the R/W head which can examine one cell at a time. In one move, the machine examines the present symbol under the R/W head on the tape and the present state of an automaton to determine 4 (i) anew symbol to be written on the tape in the cell under the R/W head, (i) amotion of the R/ a el Sain he R/W head along the tape: either the head moves one cell left (L), or ii) the next state of the automaton, and (iv) whether to halt or not. Q.1.(e) What are UNIT productions in CFG ? ‘Ans. The unit productions are the productions in which one not non-terminal. For example if n-terminal gives anoths xXoY yoZ ZoXx then X, Yand Zare urlit productions. To optimize the grammer we Need to remove the unit productions. : If A = B is a unit production and B-» X, X, X, -- X, then while removing A > production we should add a rule 4 > X,X, Xo Xp SECTION - A Q.2.(a) M = (fs dy» I3}s Os 1s 8, Cah (43h i 8 NFA, where 6 is given by : 8G 0) = 4,» Ish 8g, 1) = 43 8g 9) = yp 43+ 5(g,s 1) = {93 8g 0) = {9,35 8qy 1) = iy 43 Construct an equivalent DFA. {025 93) OF = {C42 0) Y G3, 93 {992 423 = 4% {99093 VE = {a 1) #93, 3 = {(9U GM} = 4% {p92 0} = (41) V Ga, )} = {9 93 4 I V2} = 9 I» : {DY 4 1) = (7, U9} {44> 99) 13 2%, £945 92043) 9} = £44, 9) UG, 0) U (43, 0)} = (4 3YN DUD) 41404 6144.0) = 4. DUG NGS.) =NUOUGnG = 4% " 92 93 WwW? I I 13 Present state Q.3.(a) Remove the € - transition from the given NFA. (Note : By € - closure method only) 0 oO sl alfa ‘Ans. Taking € closure of all e closure of qy = {491923 = A ; e closure of q) = {44.92} = B e closure of qy = {92} =C => * £99, 91592), 93 = £40 92} * {gop I) Vs = {a3 > * £41.92), 0} = {49} 9d) = {a1} => * £4), 0} = {92} *{@), 1) = 0 So now are have transactions of all three A, B, C as we have considered above. Now relating output and A, B,C closure.of {49,42}= € closure of gy =A © ¢ closure of {q,} = B “e.closure of {q)}) = C e closoure of {g,;} = B e closure of {gy} = C or 11> 92 q cp n OP o ‘O’ — States are the finite states considered final because consists of “gy’ state i.e. the final state given in diagram. Sea | T5#Semester, Model Test Paper-1 e ; MZ Q.3.(b) Take an example of Melay and Moore machine each and string of at least 4 alphabets from these machines and produce the Sate iin ‘Ans. In Mealy machine the output depends on the input states, ing strings. Example : Let us consider the example defined b; (aa ree Input alphabet = (a, 5} y following transition table of Mealy : Output alphabet = {0,1} States = (4g 115 42°93} qq is the initial state. Present state] Input (a)} Output Input (6) | Output > % 93 0 1 1 1 ” % 9 93 93 0 In Moore machine output depends upon the states of the machine. Example : Let us consider an example defined by following transition table of Moore machine. Input alphabet 2 = {a, b} Outputalphabet D = {0,1} States O)= { 941» 9293) qgis the initial states M, = {Q,3,4,5,4, 90) Present state Next state Output Q.3.(c) State and prove Arden’s theorem. ‘Ans. Arden’s theorem : Let P and Q be two regular expression over X. If P does not contain , , then the following equation in Rnamely. R =Q+RP has a unique solution given by R= QP* Proof: @+(QP*)P = Oa + P* P)= OP* Q+ RP = Q+(Q+ RP)P = Q+ OP + RP? = OF OP + OPE ven + OP! + RPI*! = OA TPH PEF cesne + P+ RPI! R= HN tPH PRE cere +piy+Rpit! — Fori20. Formial Languages & Automata SECTION - B Q4.(a) Convert the grammer in GNF. SAAla A >SS|b (Note : by taking S as A, and A as A, method only) Ans. The given grammer is in CNF. Sand A are renamed as 4, and 4,, respectively. So the productions are 4,—> 4,4,jaand 4,—> A,A,[b. As the given grammar has no null productions and is in CNF we need not carry out step 1. So we proceed to step 2. Step 2. (i) A,-productions are in the required form. They are A, —> 4,4, (ii) A, > 4 is in required form. Apply Lemma | to 4, > AA, The resulting productions are A, -> 44,4, 4, > 44,. Thus the 4,-productions are A, AAA, 4,904, A, >. Step 3. We have to apply Lemma 2 to A,-productions as we have 4, > A,A,A,, Let Z, be the new variable. The resulting productions are A,> aA, A,>b A, > aA,Z,, A, > 02, 2,> AA 2,7 AALy Step 4. (i) The A,-productions are A, —> a4 |bad,Z,|52Z,, (i) Among the 4,-productions we retain 4, 4 and eliminate A, — 4,4, using Lemmal .The resulting productions are’ 4;\-» a4,4|bAj, Aj 2 24,2,A,|02,A,. The set of all (modified) A productions is A, —> alad,A,|bA,|aA,Z,4,]0Z,A, Step 5. The Zproductions to be modified are Z, > 4,A,, Z, > 4,4,2,- We apply Lemma 1 and get Z, = aA,A\|bA |aA,Z,A|6Z,A, Z, > aA,A,ZybA Z,aA 2,A,Z,)02,A,Z, Hence the equivalent grammer is G! = (fA, Ay Z,}, {4 b}, P, A\) where P, consists of A, > alaA,A,|bA,|a4,Z,A |bZ,A, A,—> aA |B|ad Z,|bZ, Z,— aA,A\|bA||aA,Z,A |bZ,A, Z, -> aA,A,ZJbA,ZaA,Z,A Z,]0Z,A,Z, Q.4.(b) Discuss the ambiguity in CFG with the help of example. phe Ambiguity in context-free grammars : Sometimes we come across ambiguol® sentences in the language we are using. Consider the following sentence in English: “In books selected information is given.” The word ‘selected’ may refer to books or information. So the sentence may be parsed in two different ways. The same situation may arise in context-free languages. The same terminals string may be the yield of two derivation trees. Definition : Aterminal string w € L(G) is ambiguous if there exist two or more derivation trees for w (or there exist two or more leftmost derivations of w). Consider, for example. G=({S}, {a, 6, +,*}, P, S), where P consists of S 3 $+ SIS* Sjalb. We have two derivation trees for a+a*b given in Fig. The leftmost derivations of a + a * b induced by the two derivation trees are S=3S+S>atS>at+S*S>ata*Saatath S=aS*SS+S*SatS*Ssata*Saata*h Therefore, a + a * b is ambiguous. Fig. : Two derivation trees for a+a*b. Q.5.(a) State the prove pumping lemma for regular languages. Ans. Pumping Leitima : Let M= (Q, § 5, Ge F) be a finite automaton with n states. Let L be the regular set accepted by M. Let w € L and | w |>m. If m>n, then there exists XY, = such that w = xyz, y # A and xy'z € L for each i> 0. Proof: Let Wr aa,..d,, m>n a” Gy a4, 4) = 9, for i= 1,2, ...1m; 2) = (95 I) In) That is, Q, is the fence of states in the path with path value w = 4,4, ... 4,. As there are only n distinct states, at least two states in Q, must coincide. Among the various pairs of Fepeated states, we take the first pair. Let us take them as 4, and 4,(q, = 9,). Then j and k satisfy the condition 0 AB|CA B — Be| AB Ara C > aB\b Ans.Stepls Wie {A,C} as A aand C—> b are productions with a terminal : string on R.H.S. Ws, = {A,C}U {AJA, > with we (ZU (4, CH} a =, {4..C} U {5} as we have S—> CA (4,6, S} U (4, |4, > with we (ZU {S, 4, CH) = {4G S} U6 As W, = W,, Vv’, = W,={5,A, C} P= {A> aA, ae (VU EDF} = (S9CA,A > a,C > by Thus, G, = (KS, 4, C}, (a, b}, {S 3 CA, A a, C — b}, S) Step 2 : We have to apply Theorem to G,. Thus, W, = {8} As we have production S > C4 and Se WW, = {S30 {4, C} As A aand C > bare production with A, Ce W,,W.= ‘s A, C, a, b} , ” ee ASW, - WUE P= (Ss aldc Wp : : Therefore, Ge Ss Ay Ch, (a, b},(S > ©, ist reduced grammar. ‘A, A > a, C > b}, S)is BNEAA Senlesten Model Test Papers Ls SECTION - C Q.6.(a) Design a PDA for the language L = {we (a, 6)*| @ has equal number of a’s and 6's} Ans, We define a pda Mf as follows : M = (ay dibs {as Bb (05 bs 23s 8. dy Zy (443) where dis defined by Sq 2) = (Gy Z)} a1) B(dys 6, 2) = {dys 62Z,)} (2) Blqy» a 6) = {(q AD} (3) 5(qqn bs 6) = {(qyy 6b)} wa) 8. Z) = {a aZ,)} (5) 8, 6.2) = {(q,, a2,)} 6) Sq, a) = {(g,, aay} (7) 8(q,, 6, a) = {(4,, A} (8) The construction can be explained as follows : Ifthe pda M isin the final'state q, it means it has seen more a’s than b’s, On seeing the first a, M changes state (from’q, to q,) ((1)). Afterwards it stores the a’s in PDS without changing state ((5) and ((7)). It stores the initial 6 in PDS ((2)) and also the subsequent b’s ((4)). The pda cancels @ in the input string, with the first (topmost) 5 in PDS ((3)). If all 6’s are matched with stored a’s ,.and M sees the bottom of PDS, M moves from q, to q, ((6)). The b’s in the input string are cancelled on seeing a in the PDS ((8)). Mis deterministic since 5 is not defined for input A. The reader is advised to check that q, is reached on seeing an input string w in L. Q.6.(b) Design a Turing Machine to recognise the language L = {a'b"|n>1} Ans. We are going to design a turing machine accepts a set of string in which every String starts with ‘a’, followed by any number of a’s, every string ends in equal number of b’s as a's. No ‘a’ is encountered after first ‘b’ is read, It will not accepts the strings like €, a, aa, bb, abb, aabbb, aab and so on. Let required turing machine is : T,,={Q, 2,0, d, dy h} OQ = {45 I Vy» Ip AY = = {a, b} T = {a,b #} is initial state and h is halt state. The moves which are unaddressed, leads towards rejecting states. Let us pass the string w= # ab # 1 #abq, | #aq,# f #q,a# F Hag, b HHig, F Hg,# bAYh# the language ? {o0'| we (a, b)*} (ie. without marker in the middle) Ans, Let PDA bow" P = {0,2,0,8,5,F} , Q.7.(a) Design a PDA wl D = Es 61 = = {a,b} F=f) and transition relation 5 is defined as follows : (1) (a, a, €), (S, a) (2) (s, b, €), (S, 6) 3) ((s,€, €), (f €)) > (middle of the input string) 4) (haa), (L€) (5) CF 6, 6), (©) 6) (LE.€) (15) Clearly whenever the machine is in state ‘s’ it can non-deterministically choose either to push the next input symbol on the stack or to switch to state f without consuming any point. Move 6 is for accepting the string. Q.7.(b) Discuss the halting problem and PCP problem of turing machines. Ans. Halting Problem of Turing Machine : This technique is used to prove the undecidability of halting problem of Turing machine. The moves which are unaddressed, leads towards rejecting states. : Let us pass the string w=# ab # AO x #abq, + #aq,# #q,a# + #aq,# Hig, F Hg, fF #Yh# Se NS re Halt state a/aL We say that problem 4 is reducible to problem B if a solution to problem B can be used to solve problem 4. For example, if 4 is the problem of finding some root of x4 — 3x? + 2 = 0 and B is the ee of finding some root of x2 ~ 2= 0, then A is reducible to B. As x2 — 2 is a factor of 4 _ 3x2 +2, a root of x? -2= 0 is also a root of x4 3x2 +2 = 0, Theorem : HALT 74 = {(M, w)| The Turing machine M halts on input w} is undecidable. Proof : We assume that HALT y, is decidable, and get a contradiction. Let My be the TM such that 7(Mj) = HALT yy and let M, halt eventually on all (M, w). We construct a 7M Mz as follows: 1, For M, (M, w) is an input. 2. The TM M, acts on (M, w). 3. IF-M, rejects (M, w) then My rejects (M, w). 4, IM, accepts (M;, w), simulate the 7M M on the input string w until M halds. 5. If M has accepted w, M, accepts (M, w); otherwise Mj rejects (M, w). When Mj accepts (M, w) (in step 4), the Turing machine M halts on w. In this case either an accepting state q or a state q’ such that 5 (¢’, a) is undefined till some symbol a in is reached. In the first case (the first,alternative of setp 5) My accepts (M, w). In the second case (the second alternative of setp 5) My rejects (M, w). It follows from the definition of M, that Mz halts eventually. Also, Ty = {(M, w)| The Turing machine accepts w} : Pare WD This is a contradiction since Ay, is undecidable. PCP problem : The post Correspondence Problem (PCP) was first introduced by Emil Post in 1946. Later, the problem was found to have many applications in the theory of formal languages. The problem over an alphabet belongs > belongs to a class of yes/no problems and is stated as follows : Consider the two lists x = ..%,), P= (Y1.--Y_) Of nonempty strings over an alphabet = {0, 1}. The PCP is to determine whether or not there exist ijn, such that where IS, S>S8,S 38} Therefore, L(G,) is of type-1 or type-3 according as L, and L, are of type-1 or type-3. Let us suppose now a €L,, the proof is similar as in case of a eL,. (c) Concatenation : Suppose L, and L, are two language of same type say i. Let the grammer G, = (V",, 2’, P’, S’) generate the language L, and the grammer G,=(V",, 2”, P”, S’) generates the language L,. Therefore the grammer G, and G, will also be of same type i.e., type-i. The connection of language L, and L, is L,L,. Now our goal is to prove that the type of language LL, is type-i. Let us construct a new grammer G, that will generate the language LL, G.=({V4,0 VW, U {S}, BUR”, PS) Where S is the start symbol such that S¢V’,UY” and P. = P’UP”U{S’SS”). If the language gnerated by grammer G, is L(G) then we have to prove that UG)=L, L, and weL,, w,eL, and w€ LL, then w,w,€ LL, The string w, is derived by grammer G,, such that 5m, and the string w, is derived by the grammer G, such that 52 —G— 5,5, Formal Languages & Altona Now according to grammer G, SSS, and $5, wr Hence LL, <(G,)+ (d) Intersection : If w, € L(G), then to generate the string we the first step is S— S,S,, We assume that V’,, 0 V”,,= and the production in grammer G, or G, involve only noterminals w, = w,w,. Therefore LL, = L(G,). Also grammer G, is of type-0 or type-2 according as G, and G, are of type-2. The above construction is sufficient when G, and G, are also of type-3 or type-1 with AgL,U L,. Let G, and G, be the type-I or type-3 and a¢ L,, A¢ L,. Let us define language L, and L, such that L,=L Then L, L, is defined as, Lyly ULy ifn€ LybutagL, Ly =} Lylg Ly if ve LbutrgL, LylpUOL,ULyry fae Ly Ly * Aswe have shown inthe previous theorem, that L ey, and L,, are closed under union. So concantation of L, and s of type-I or type-3 according as L, and L, are type-I or type-3. Q.9.(a) Discuss in detail Chomsky hierarchy of grammer and also explain the relation between languages ‘of classes, under Chomsky’ classification with the help of diagram. Ans. Chomsky hierarchies of grammars : We can exhibit the relationship between grammars by the Chomsky hierarchy. Chomsky provided an initial classification in to four languages type: Type - 0 (Unrestricted grammar) Type-1 (Context sensitive grammar) Type - 2 (Context free grammar) Type -3 (Regular grammar) Type 0 languages are those generated by unrestricted grammars, that is, the recursivel) enumerable languages. Type | consist of the context-sensitive languages, Type 2 consists ofthe context-free languages and Type 3 consists of the regular languages, Each language family type k is a proper subset of the family of type k~ 1. Following diagram shows the origi Chomsky Hierarchy. Relation between classes of languages : The four classes of languages—recurs” sets, context sensitive languages, context-free languages and regular sets are often referred ” as language of types 0, 1, 2 and 3 respectively. pitachsh Semester Nt Wioul Test Papers] We can find the relation between all these sets of languages through following theorems: Theorem 1 : Every context sensitive language is recursive. Proof : We know that for every recursive language there exists a turning machine for it. But we have not been very specific about how one inputs a grammar into turing machine. Let us imagine that some string of ‘delimiters separating the productions, possibly allowing the production arrow to be tape character as well. Now letus feed this turning machine and W (input string) into universal turing machine. Because W either halts or crashes on the coded turing machine, this procedure will indeed, lead to a decision about W’s membership in the I wage gene ted by G. So we prove that there exists a turning machine for every context: -sensitive language, which can decide that any arbitrary string W can be derived from the given context-sensitive grammar or not, so we can say that every context-sensitive language is recursive. Theorem 2 : There is at least one language. L that is recursive but not context- sensitive. Proof : In the previous theorem, we indicate that there was encoding an entire context- sensitive grammar into a single string of symbols. Let us consider the set of all context-sensitive grammars on V;= {a, b}. Let us assume that each grammar in the set has variable in following form = Vy Voy Vay) Every context-sensitive grammar is completely specified by its productions. We ci can think of them as written as a single string. Ky PVG PI, bn hy Vn We can represent these string in homomorphism as follows : h(a) = 010 h(b) = 0170 A(R) = 1190 hi) = 010 my) = 01780 d uniquely by a string of the Thus, any context-sensitive grammar can be represente : nse that, given any such form L (011*0)*). Further more, the representation is invertible in the se string, there is at most one context-sensitive grammar corresponding to 7 : Let us introduce a proper ordering on (0, 1)°, so we can write strings in the order w,, ¥, etc. A given string w, may not define a context-sensitive grammars if it does, call the grammar G, Now let us define a language. L = {W,:1,defines a CSG G, and W,€ L(G)} Q.9.(6);Défiiie. the’ fo owing : © @, Recursive functions Gi) partial Recursive functions Gii) Primitive Recursive fuinetio i ‘Ans. (i) Recursive Function : A function is recursive if it can be obtained from the initial functions by a finite number of application of ‘composition, recursion and minimization over regular functions. (i) Partial recursive function : A function is partial recursive function if it can be obtained from the initial functions by a finite number of application of composition, recursion and minimization. Partial recursive functions are turing computable. For ex. : f = x/2is prtial recursive function over N. ii) Primitive recursive function : A total function fover Nis called primitive recursiv® (if itis one of three initial functions, Gi) if it can be obtained by applying composition & recursion a finite number of time the set of initial function. = FORMAL LANGUAGES & AUTOMATA Model Test Paper-Il Paper Code:-PCC-CSE-305-G Note : Affempt five questions in all, selecting one question from each Section. Question No. 1 is compulsory. All questions carry equal marks. Q.1.(a) Any two difference between DFA and NFA. Ans. Differences between DFA and NFA are as follows : (1) “DFA” stands for “Deterministic Finite Automata”, wh “Nondeterministic Finite Automata.” ‘| (2) Both are transition functions of Automata. In DFA the next possible si set, while in NFA each pair of state and input symbol can have many possible next states. ile “NFA” stands for tate is distinctly Q.1.(b) Define finite automata with output briefly. Ans. The finite automata have binary output, i.e. either th not accept the string. This acceptability was decided on the basis o by the initial state. Now, we remove this restriction and consider the mo can be chosen from some alphabet. The value of the output function Z(t) in th case is a function of the present state q(t) and the present input x(t), i.e. AH9= Mg(o, x0) where? is called the output function. This generalized model is usually called the Mealy machine. If the output furiction’ Z(t) depends only on the present state and is independent of the current input, the output function may be written as © 2) = GO) This restricted model is called the Moore machine. It is more convenient to use Moore machine in automata theory. ey accept the string or they do reachability of the final state del where the outputs e most general Q.1.(c) Explain closure properties of regular languages. Ans, Closure Properties of Regular Sets : (1) Regular languages are closed under union opration and kleene star operation. Proof : If L, and L, are regular, then there are regular expressions r, and r denoting the languages L, and L, respectively. ci (r, +r) and (r;*) are negular languages denoting the languages LU Ly and L,* Therefore L,UL, and L,* are regular. (2) Regular languages are closed under complement operation and intersection operation. Proof : Suppose that L, and L, are regular over an alphabet 5. There is a DFA M=(Q,3%,5, 4q» Fl accepting L,. Design a DF4 M! = 1,3, 8,4 Fil where F! = Q/F. Now, we have that L(M!) = Z*[L). Hence the complement of L, is regular. Let Ly =2*|L, and L!, = Z4|Ly. The complement of L,! u L,! is regular and is equal to Ly? Ly. Ly’ Ly » regular. Q.1.(d) Give formal definition of a PDA. Ans. A pushdown automaton consists of (i) a finite nonempty set of states denoted by Q, (ii) a finite nonempty set of input symbols denoted by Z, (iii) a finite nonempty set of pushdown symbols denoted by I, (iv) a special state called the initial state denoted by q,, (v) aspecial pushdown symbol called the initial symbol on the pushdown store denoted byZ,, (vi) Bee final states, a subset of Q denoted by F, and (vii)a transition function 5 from Q x (2 U {A}) x ['to the set of finite subsets of Q x I'*. Symbolically, a pda is a 7-tuple, namely (Q, 2,1, 8, dys Zs F) Q.1.(e) State Halting problem of Turing machine. Ans. Halting Problem of Turing Machine : This technique is used to prove the undecidability of halting problem of Turing machine. We say that problem 4 is reducible to problem B if a solution to problem B can be used to solve problem A. For example, if A is the problem of finding some root of x4 — 3x2 + 2= 0 and B is the problem of finding some root of x2 - 2 = 0, then 4 is reducible to B. As x2 — 2 is a factor of x32? +2, a root of x? -2 = 0 is also a root of x4 — 3x2 +2=0. Section — A Q.2.(a) Design a DFA:which accepts even number of a’s over the alphabet {a,b}. , Ans, String bbaba (o> bbaba) > (qq, ba ba) (q,» baba)+ (q,,aba) (qo,aba) + (4, ba) (q,ba) + (q,a) (41.4) (qo) (Final statement) Q.2.(b) Explain the Limitations of Finite Automata. Ans. Limitations of Finite State Automata ; (1) The predictable nature of deterministic FSAs can be unwanted in some domain such as computer games, i (2) Larger systems implemented using a FSM can be difficult to manage and maintain without a well thought out design. The state transitions can cause a fair degree of “spaghetti- factor” when trying to follow the line of execution. re ee fae ee should only be used when a systems behavioy, fined conditions for state transitions, This o be known up and be well defined, hey are fixed. (3) Not suited to all problem domains, can be decomposed into seprate states with well de means that all status, transitions and conditions need t (4) The conditions for state transitions are redged, meaning tl (5) Have no memory of its own. (6) Travels only from left to right. Q.2.(c) State and prove Arden’s method. Ans. Arden’s theorem : Let P and Q be two regu contain , then the following equation in R namely. R =Q+RP has a unique solution given by R= QP* Proof: Q+(QP*)P = O(a + P* P)= OP* O+ RP = Q+(Q+ RP)P Jar expression over Z. If P does nop = Q+OP + RP ; = OF OP + OPE + nnn + OP! + RPI! =Ant+P+Pr+ + Pl) + Rpi*! On +P + P+ +pPi+RpPit! — Fori>o. Q3.(a) Constr ‘t a Finite Automata equivalent to the regular expressions : ‘ba,+(a + bb)a*b bb atbb (a + bb)a* Q.3.(b) Construct a DFA accepting all strings over {a, b} ending in ab. Ans, String accepted - (ab, abab, aaab, bbaab, abaaabab) Section - B Q.4.(a) Prove that a context-sensitive language is recursive. Ans. A context-sensitive language is recursive. Proof : Let G = (V,, 2, P, S) and w € £*. We have to construct an algorithm to test whether w € L(G) or not. If w = A, then w € L(G) iff S — A is in P. As there are only a finite number of productions in P, we have to test whether S > A is in P or not. Let | w | = > 1. The algorithm is based on the construction of a sequence {W} of. subsets of (V,,U Z)*. W, is simply the set of all sentential forms of length less than or equal to rn, derivable in at most i steps. The construction is done recursively as follows : @ W, = {S}. Gi) W,,,=W,U {Be (V, € 5)*! there exists a in W, such that ot => B and | B| 0. (iv) There exists k such that W, = W,, - (v) If kis the smallest integer such that W, = W,, » then W, = {ae (Vy E}|Ss aand|a| w) ifand only ifw € W,, Also, W,, Ww W, can be constructed in a finite number of steps. We give the required algorithm as follows: Py, Algorithm to test whetlier w € L(G). 1. Construct Wi, W, Ui ing the point (i) and (ii). We terminate the construction when 7a, = W, forthe first time. 2. Afwe Wy then we L(G). W, requires at most N ‘Steps). therwike, 2 L(G) (As | W, |< N, testing whether w Q.4.(b) Define leftmost and rightmost derivations. Give examples. ‘Ans. Leftmost derivation and rightmost derivation : Derivation for any string means replacement of non terminal by its appropriate definition. There may be a situation, in which there are many non terminals. Then which non terminal should be replaced by its definition is sometimes confusing to decide. : Hence we normally apply two methods of deriving. The leftmost derivation is a derivation in which the leftmost non terminal is replaced first from the sentential form. ‘The rightmost derivation is a derivation in which rightmost non terminal is replaced first from the sentential form. Let us see how it works. Leftmost derivation Rightmost derivation fer, Model Test Paper-IT M-25 Note that we have replaced first X from left or right in leftmost derivation and XYX the last Xie. the rightmost symbol. Actually, we may use leftmost derivation or rightmost derivation we get the same string. “The type of derivation does not affect on getting of a string. Q.5.(a) Define Chomsky normal form. Simplify the following CFG and convert it into CNF : S— ASB|e€ A—aAS |e B— SbS|A| bb Ans. Chomsky normal form : In the Chomsky normal form (CNF), we have restrictions on the length of R.H.S. and the nature of symbols in the R.H.S. of productions. Definition : A context-free grammar G is in Chomsky normal form if every production is of the form A a, or A BC, and S > A is in Gif A ¢ L(G). When A is in L(G), we assume that S does not appear on the R.H.S. of any production. For example, consider G whose productions are S > AB| A, A> a, B > b. Then Gis in Chomsky normal form. S>ASBle Aaa A Se B—SbS|A/bb eS AE d z S—>ASBSB/|AB|B A >aAS|aS|aAla B->Sbs|Sb|bS|b|bb Now production becomes S> ASB|SB/AB|B A> aAS|aS|aAla BOSbS|Sb|bS|b|bb Cb put this production in above production. Now production becomes : S >ACsg |SB|AB|B AC, AS|C,S/C Ala Bo SCy S| SC, | Cp S]b| Cy CbLA Cy SB C,7a C,>b Put & replace in above equations. Now production becomes S3AC,|SBIABIb AC, Cyl C,81C, Ala BISCKISC1C, S1b1C,C bla Cy >SB Ca C76 C2 AS Cg 2 CS Q.5.(b), State and prove pumping lemma for regular languages. Show that the language. L= {WWA)W (a, b)*} is not regular, Ans, Pumping Lemma : Let M = (Q, 2, 5, dy F) bea finite automaton with n states, Let L be the regular set accepted by M. Let w€ Land | w| 2m. If m2 n, then there exists x, y, z such that w = xyz, y #\ and xy"z € L for each i> 0. Proof : Let W = A, on dy MIN BG AN. a) = 4G, for T= 1,2, 0m Q,= Mn Mr we Gy) That is, Q, is the sequence of states in the path with path value w= d,d, ...d,, As there are only 1 distinet'States, at least two states in Q, must coincide. Among the various pairs of repeated states, ke the first-pair. Let us take them as % and 44, = 4). ‘Then / and k satisfy the condition 0 0, the ton is i a i i i 20, e automaton is ny the a state 4, On applying z, it reaches Ypp @ final state. Hence xy'z€ L. As every state in Q, is obtained by applying an input symbol. y ¥ A Show that L = (ww | we {a, 6}*} is not regular, : : Step 1 : Suppose /is regular. Let 1 be the number of states in the automaton M accepting Step 2 : Let us consider ww = a"ba"b in L. |ww | =2(n + 1) > E lemma to ite ww = xyz with ly ls o layin bw |= 200+ 1) > n, We can apply pumping Step 3 : We want to find / so that xyz ¢ L for getting a c ict bein only ar of the following forms ; Setting a contradiction. The string y can Case 1°: y has no b’s, ie. y = a* for some k> 1, Case 2 : y has only one 5. We may note that y cannot have two b’s. Ifso,| y|>n +2, But| y|<|xy| (G00) §G,1,.0) > (8) 8 Gy 1,0) Gy) 8G, £2) > dy) ‘Stack symbol ‘Transition Z 3 qq» 0 2) (I 92) 0. 3(g,, 0,0) + (4,00) 0 3 (q,, 0,0) > (4,9 0) 0 5(g,. 0,0) H (4,9 0) 0 8 (q,,1,9) Gy» ®) 0 8 Gy 1.0) (@» ®) 0 3 (dy 1,0) > Gy ®) 0 8G, 1,0) Gy ® Zz 8G» 8%) (Gy) Q.7.(a) Define Turning machine, Design-a Turing machine that computes the integer function f defined as follows : fn) = 3" where n is integer and n> 0 Ans. Turning machine : A Turning machine M is a 7-tuple, namely (Q, 2,1, 8 q5,F) where (1) Qisa finite nonempty set of states. (2) Pisa finite nonempty set of tape symbols. (3) b € Tis the blank. (4) Zis a nonempty set of input symbols and is a subset of P and 6 ¢ 5, (5) Sis the transition function mapping (q, x) onto (q’, y, D) where D denotes the direction of movement of R/W head; D = L or R according as the movement is to the left or right. (6) 4, € Qis the initial state, and (7) FC Qis the set of final states. The Turning machine can be thought of as finite control connected to a R/W (read! write) head. It has one tape which is divided into a number of cells. The block diagram of tH? basic model for the Turning machine is given in Fig. Each cell can store only one symbol. The input to and the output from the finite state automaton are effected by the R/W head which can examine one cell at a time. In one move, the machine examines the present symbol under the R/W head on the tape and the present state of an automaton to determine : : (anew symbol to be written on the tape in.the cell under the R/W head, (i) a motion of the R/W head along the tape: either the head moves one cell left (L), or one cell right (R), (iii) the next state of the automaton, and (iv) whether to halt or not. Tape divided into calls and of infinite 'ength Fig. : Turning machine model An) = 3" where n is integer and n> 0 String - { 3,33, 333, 333, woos} Transition table 3 B > 4% q.3.R ay3R £Bq,333BB = BB3q,3318 = B33q,38B = BB 333q,8B Since the turing machine halt in q,. The string 111 is accepted. Q.7.(b) Differentiate between DPDA and NPDA with the help of example. Ans, Cc DPDA NPDA (D itis deterministic (1) Itis non-deterministic (2) DPDA is not generalization of NPDA (2) NPDA are a generalization of DPDA| DPDA (3) Every DPDA can be simultated by an (3) Converse is not true. NPDA Hal Laiigunges & Auton (4) DPDAs can simulate more easily with (4) Complex our deterministic computer. (5) It is always defined that at for a particular (5) It is always See input it will be going to a specific state particular inpul y goto different states. (6) DPDAs are more powerful than NPDAs. (7) But CFLs such as the language of palidromes, that can be accepted by NPDAs. . dentities| (8) Table contain single entities. (9) There is epsilon transition. (6) DPDAs are less powerful than NPDAs. (7) CFLs, such as the language of palidromes, that can’t be accepted by DPDA. (8) Table may contains multiple defines (9) There is no epsilon transition meaning that you are not allowed to change states with out consuming anything from the input. Section - D Q.8. Explain the following with example : (a), Partial recursive functions #(b) Primitive recursive functions Ans, (a) Partial recursive function : A function is partial recursive function if it can be obtained from the initial functions bya finite number of application of ‘composition, recursion and minimization. > J PUBI ICATION Partial recursive functions are turing computable. For ex. : f = x/2 is prtial recursive function over N. (b) Primitive recursive function : A total function fover NV is called primitive recursive (i)_ if itis one of three initial functions. (i) if it can be obtained by applying composition & recursion a finite number of time? the set of initial function. For ex. : f (x, y) = x” isa primitive recursive function. Q.9. What do you mean by computability ? Explain in detail. Ans. Computability : Computability refers to the ability to solve a problem in an effecti® manner. It is a key topic of the field of computability theory within mathematical logic a computer science. The computability ofa problem is closely linked to the existence of an algorith® to solve the problem. computable : In computability theory, a Turing reduction from a problem A to aproble? B, named after Alan Turing, is a reduction which solves A, assuming B is already known. @sten Model Test Paper'-ll BS Computable : Expressible as a yes/no question that can be answered in any case by a computer in finite time, Computable Function : Computable functions are the basic objects of study in computability theory. Computable functions are the formalized analogue of the intuitive notion of algorithm. They are used to discuss computability without referring to any concrete model of computation such as Turing machines or register machines. Any definition, however, must make reference to some specific model of computation but all valid definitions yield the same class of functions. Particular models of computability that give rise to the set of computable functions are the Turing-computable functions and the jt-recursive functions. The class of computable functions can be defined in many equivalent models, including + Turing machine + uerecursive functions + Lambda calcutus * Post machines (Post-Turing machines and tag machines). + Register machines. + Turning Computable Function : Turing machine can be used to compute functions. We adpot the following policy to input any string to a turing mechine. The string W is presented in to the form of # W #, that is string, W is surrounded by blanks symbols from both sides and is placed on the left most square of tape, the head of turing machine is positioned at the right most blank syinbol which immediately follows the string W. This is shown by an underscore that is we use an underscore to show the current position of machine head in the tape. A turing machine is said to halt on input ‘W” ifwe can reach toa halting state ‘h’, after performing some operations, that is if, T, =(Q, 2,1, 8, q,, fi) isa turing machine then Tm is said to halt to on input W ifand only if (q, # W #) yields to (h, # 1 #). Multiple track turing machine : In the case of TM, a single tape was used. In a multiple track TM, a single tape is assumed to be divided into several tracks, Now the tape alphabet is required to consist of k-tuples of tape symbols, k being the number of tracks. Hence the only difference between the standard TM and the TM with multiple tracks is the set of tape symbols. In the case of the standard Turning machine, tape symbols are elements of I; in the» case of TM with multiple track, it is P*. The moves are defined in a similar way. Subroutines : Subroutines are used in computer languages, when some task has to be Tepeatedly. We can implement this facility for TMs as well. First, a TM program for the subroutine is written, This will have an initial state and a ‘return’ state. After reaching the return state, there is a temporary halt. For using a subroutine, new states are introduced. When there is a need for calling the subroutine, moves are effected to enter the initial state for the subroutine (when the return state of the subroutine is reached) and to return to the main program of TM. ——? ‘ORMAL: LANGUAGES & AUTOMATA Model Test Paper-III Paper Code:PCC-CSE-305-G _——$—$—$—$—$—$—$—$$——————— << Note : Attempt five questions in all, selecting one question from each Section. Question No. 1 is compulsory. All questions carry equal marks. Q.1.(a) What are limitations of FSM ? Ans. Limitation of FSM : (i) The defining characteristics of finite automata is that they have only a finite number of states. Hence finite automata can only count a finite number of input scenario. Gi) Finite automata do not have any auxiliary memory so it works in process & forget mode. It can store anything at particular state. There is no finite automata that recognize these string. (iii) The set of binary strings consisting of an equal no. of I’s & 0’s. (iv) Th set of strings over “(“ , “)” that have balanced parenthesis. (v) Finite automata can recognize & process only regular languages. Q.1.(b) Define DFA and NDFA mathematically. : Ans#DFA‘:‘DEA is‘a finite state machine that accepts/rejects finite string of symbols and only produces a unique computation of the automatan for each input string. DFA i§aS.tuple(Q, ©, 8/99, F) Q finite set of, states = Hfinite setofinputs. (| P,) | ¢ Transition function’$ > Q* 2 Q 90 — initial state F final state NDFA: A nondeterministic finite automaton (NDFA) isa 5-tuple (Q, 5, 8, Gy F), where @ Qisa finite nonempty set of states; zg (i) Lisa finite nonempty set of inputs; Gii) 5 is the transition function mapping from Q x into 2° which is the power set of Q, the set of all subsets of Q; (iv) q, € Qs the initial state; and (v) Fc Qis the set of final states. Q.1.(c) Define Decidability. | Ans. A problem with two answers (Yes/No) is decidable if the Corresponding language is recursive. In this case, the language L is also called decidable. A decidable problem is called a solvable problem and an undecidable problem an unsolvable problem by some authors. Q.1.(d) Define PCP, me Ans. PCP problem : The post Correspondence Problem (PCP) was first introduced y Emil Post in 1946. Later, the problem was found to have many applications in the theory of SITTERS, 2 formal languages. The problem over an alphabet belongs > belonee ie Symes ses and is stated as follows : Consider the two lists x= (*y-=%,)¥ = Olan) CUnemnly stings over an alphabet © = {0, 1}. The PCP is to determine whether of no! jovedm, Where ISij Initial state Yes, these machines can work like one another: Procedure for transforming a moore machine into a mealy machine : We modify the acceptability of input string by a Moore machine by neglecting the response of the Moore machine to input A. We thus define that Mealy Machine M and Moore Machine M’ are equivalent if for all input strings w, 62, (wv) = Z,,(w), where b is the output of the Moore machine for its Format Languages & Autogiy initial state, We give the following result : Let M, = (2-2 A, 8,7, g,) be 4 Moore machine, the following procedure may be adopted to construct an equivalent Mealy machine M.. Construction + (i) We have to define the output function x for the Mealy machine ag a function of the present state and the input symbol. We define by 2! (4,4) = 248(4, a) for al states g input symbols a, (i) The transition function is the Example : Construct a Mealy Machine whicl by Table (1). Table (1 Then ame as that of the given Moore machine. his equivalent to the Moore machine given Output Present state Next state 74% % q n 4 qs qs We must follow the reverse procedure of converting a Mealy machine into a Moore machine. In the case of the Moore machine, for every input symbol we form the pair consisting of the next state and the corresponding output and reconstruct the table for the Mealy Machine. For example, the states g, and q, in the next state column should be associated with outputs 0 and 1, respectively. The transition table for the Mealy machine is given by Table (2). Table (2) Present state : v1) Next state | 7% % dn Is 1 0 0 Section — B Q.4.(a) What do you mean by Pumping Lemma and applications of pumpins Lemma ? Using that concept of pumping lemma prove that L = faib/| j= 7} is nota CFL. Ans. Pumping Lemma : Let M = (Q, 2, 8, q,, F) be a finite automaton with n states: Let L be the regular set accepted by M. Let w€ Land|w|>m. If m>n, then there exists %5)* zsuch that w = xyz, y # A and xy'z € L for each i> 0. Proof : Let W =a, m>n Blyy yy 44, FOFT= 1,2 eps Q, = Ly Ay I) Pech S”Semester. Model Test Paper-Ill That is, Q, is the sequence of states in the path with path value w = 4,4, ... a, As there are only 7 distinct states, at least two states in Q, must coincide. Among the various pairs of repeated states, we take the first pair. Let us take them as q, and q,(q, = q,). Then j and k satisfy the condition 0 1. (5) You achieve a contradiction to the pumping lemma by showing, for any u, v and w determined by the adversary that there exit i for which wv! is not in L. It may then concluded and L is not regular. Your selection of i may depend on n, u, v and w. Proof : Let 7 be constant of pumping lemma. Select Z= a"b" . This ensures that Z is in L and |Z|>n. If we write Z = uvwxy, then the possible choices of wx satis: 1 s| vx| 0). p andsince 1 ata*Saatath S=S*S=>S+S*S=atS*S>ata*Saatath Therefore, a + a * b is ambiguous, Q.5(a) What do you mean by Reduced form of a CFG ? Explain with example. Ans. Reduced Form : A grammar is said to be in the reduced form if there are productions of the form w,Aw, — w,, where ‘w’ does not contain a Non-terminal, This should be applicable for all the Non-terminals that at one point or another Non-terminal should result in@ terminal string. Consider the following grammar, Ss > BC Sb Bob Observe that from the start symbol we generate two Non-terminals ‘B’ and ‘C’ and out of the ‘B’ will produce a terminal but we can not eliminate the Non-terminal ‘C’ from the string such a grammar is not in the reduced form. Example : Check whether the following grammar is in reduced form. S + AB . SCA B — BC B- AB Ana C > aBlb Observe that to terminate the generation process we should use any of the following rules, Ana Cb Hence whenever from given Non-terminal we get the Non-terminal ‘4’ and ‘C’ we can generate the string only terminal: Observe that from’*S’ we can generate ‘C4’, hence ‘S’ will generate a terminal string. oe S CA : APU SLIC: Q.5.(b) What are normal forms of CFG ? Explain convert a CFG into CNF. S - AACD, A aAblA, C > aCla, D > aDalbDb|A. Ans. Normal forms for Context-Free Grammars : In a context-free grammer, the R.H.S. ofa production can be any string of variables and terminals. When the productions in G satisfy certain restrictions, then G is said to be a ‘normal form’. Their are mainly normal forms - the Chomsky normal form (CNF) and the Greibach normal form. Chomsky Normal Form : In the Chomsky normal form (CNF), we have restrictions on the length of R.HLS. and the nature of symbols in the R.H.S. of productions. Definition : A context-free grammar G is in Chomsky normal form if every production is of the form 4-9 a, or A> BC, and S— A isin Gif A L(G). When A is in L(G), we assume that S does not appear on the R.H.S. of any production. For example, consider G whose productions are S > AB| A, A > a, Bb, Then Gis in Chomsky normal form. Greibach Normal Form : Greibach normal form (GNF) is another normal form quite useful in some proofs and constructions. Definition : A context-free grammar is in Greibach normal form if every production is of the form A — aa, where 1 € Vyanda€ £(amay be A), and SA isin GifA€ L(G). When A L(G), we assume that S does not appear on the R.H.S. of any production. For example, G given by S—> aAB| L, A bC, Bb, C9 is in GNF. Concersion of CFG into CNF : Let G be the grammar w! th productions S — AACD A > adb|A Cc >aC\a D -»aDa| bDb\ A Let us go through each step of the conversion to NF. (1) Eliminating A-productions : The nullable variables are A and D, produces the grammar with productions 4 5 AACD| ACD | AAC| CD | ACI C A > aAb|ab C7 aCla D — aDa|bDb|aa|bb (2) Eliminating unit productions : Here we may simp S 7aC\a ly add the productions and delete S > C. (3) Restricting the right si two or more variables : This step yields the productions § -» AACD| ACD| AAC| CD | AC| X,C | ati? X AX, |XX, CX Cla Day» X,DX, | X,DX,1%,X,1 XX des of productions to single terminals or strings of # " to mb (4) The final step to CNF : There are six productions whose right sides are too long, Applying our algorithm produces the grammar with productions AT, T, 2 AT, T, > CD 3M, U,30D 3Ay, VAC > CD|AC|X,Cla 7M, W, — Ax, SMVDINF>u4uuDN L a. a 8 Section - C Q.6. Construct a PDA accepting {a" b" a” | m, n> 1} by null store. Construct the corresponding CFG accepting same set. ‘Ans. The pda A accepting {a"ba"| m, n> 1} is defined as follows : Uap Ses i eae 2 A = (£409 9,35 {4, 5}, (a, Z,}, 5, dus Zs 0) where 6 is defined by Ri: Gy a, Zq) = {Gy aZ,)} R, + 8p a, a) = {(q,, aa)} R,: 84, b, a) = {(q,, a)} Ry: 8g, 6,4) = (fq, a)} R,: 8, 4,4) = ({9,, A} Ro: 8G,A,Z,) = ({9,. )} ‘We start storing a’s until a b occurs (Rules R, and R,). When the current input symbol is 6, the state changes, but no change in PDS occurs (Rule R,). Once all the 5’s in the input string are exhausted (using Rule R,), the remaining a’s are erased (Rule R,). Using R,, Z, is erased. So, (oy 2b" A”, Z,) FH (qs As Zp) EQ» As AD This means that aba" € N(A). We can show that N(A) = {a"b"a"| m,n > 1} by using Rules R,-R, Define G=(V,, {a, b}, P, S), where V, consists of [40> Ze» Fads [4s Zyp Gol» [Gor 4 Iolo [9,2 % 4] [de 2 115 Uys Zs Ts [de> a Gh [9 9,1 The productions in P are constructed as follows : The S-productions are 5 PS Ads Zo Gh PS [doZy 4] IQ: 4, Z,) = {(diy.Z,)} induces + FS 3 Go Zp Go) > 440» 4s ll 4o> 2 Gel Pot [or ZG) > aly & FIGs Zp Gl Pst [de ZH) > aly 4 M14» 2 4) Pot Me 2 1) > Ady % HMI Zy 41) 8(g,, 4, a) = {(q,, aa)} yields 1 Gor 4 4) > 4 % Gll4or 4 4] 5 Ger I] > 14> @ YMG» & 9] = [9 % 9) > alg, @ IMG 4 94] Pt [4491 > a4, @ 9,119, % 9%] 5(q,, b, a) = {(q,, a)} gives Pay t [do 4 Go) > FL» & 4] Pit [9 4 9,] > 519, 4 9] 8(q,, b, a) = {(q,, a)} yields Pit [4% 9) > 9, 4 4) Pit [4% G1 > Old a9) 8(q,, 4, a) = {(q,, A)} gives Pit [yaglra » et 5g A, Z,) = {(q,, AD} yields Py t (Zea) A Q.7.(a) Design a TM for subtraction for m— 1, where m > " and both mn>=1, Ans, Step : y : © Step-1 : 1f0 found convert all 0's into 0's and go right then convert Cinto C and gy right. i : © Step-2: IfX found then convert all X into X and go right or if 0 found then conver, 0 into X and go left and go to next step otherwise go to 5th step. i © Step-3 : Then convert all X into X and go left then convert C into C and go left © Step-4 : Then convert all 0°s into 0’s and go left then convert B into B and go right then convert 0 into B and go right and repeat the whole process. / © Step-5 : Otherwise if B found convert B into B and go left then convert all X intoB and go left then convert C into B and go left and then stop the machine. Q.7.(b) Write short note on Halting Problem of TM. Ans, Halting Problem of Turing Machine : This technique is used to prove the undecidability of halting problem of Turing machine. We say that problem 4 is reducible to problem B if a solution to problem B can be used to solve problem A. For example, if 4 is the problem of finding some root of x4 — 3x2 + 2 = 0 and B isthe problem of finding some root of x? ~2=0, then A is reducible to B. As x2 — 2 is a factor! x4 — 3x2 +2, a root of x» -2=0 is also a root of x4~3x2 +2=0, Theorem : HALT yy4 = {(M, w)| The Turing machine M halts on input w} is undecidable Proof : We assume that HALT, is decidable, and get a contradiction. Let M, bet TM such that (M,) = HALT 7, and let My halt eventually on all (M, Ww). We construct a TMM) as follows: 1. For Mp, (M, w) is an input, 2. The TM M, acts on (M, w). 3. If Mj rejects (M, w) then My rejects (M, w). a Se Rn ee aN Oe ML De SO BRIS REO RINIER S ES ERTAEN aee 4. If M, accepts (Mj, w), simulate the TM M onthe input String w until M halds. 5. If M has accepted w, My accepts (M, w); otherwise My rejects (M, w). When M, accepts (M, w) (in step 4), the Turing machine M halts on w. In this case either an accepting state q or a state q’ such that 8(q',a)is undefined till some symbol a in w is reached. In the first case (the first alternative of Setp 5) M accepts (M, w). In the second case (the second alternative of setp 5) My rejects (M, w). It follows from the definition of. My that M, halts eventual ly. Also, (M2) = {(M,w)| The Turing machine accepts w} =A This is a contradiction since ise is undecidable. Section - D Q.8. What are Primitive Recursive Functions ? Explain and prove that the following functions are primitive recursive : (i) Transpose (ii) Concatenation (iii) Identity. Ans. Primitive recursive function : (a) ifitis one of three initial functio (b) ifitcanbe obtained by applying composition & recursion a finite number of time to the set of initial function. > For ex. Atotal function fover Nis called primitive recursive ns, f(%, ») = »isa primitive recursive function. () Transpose Function: The transpose function can be defined by trans(x) = x7, Then “ PUBL if ) trans(A) = A trans(ax) = concat(trans(zx), a(x)) trans(bx) = concat(trans(x), b(x)) Therefore, trans(x) is primitive recursive. (ii) Concatenation Function : The concatenation function.can be defi concat(x,, x,) = x,x, concat(A, x,) = id(x,) concat(ax,, x,) = cons a (concat(x,, x,)) concat(bx,, x,) = cons b (concat(x,, x,)) So concat is defined by recursion using id, cons a and cons b, Therefore, concat is primitive recursive. (iii) Identity Function : Let us denote the identity function by id. Then, id(A) = A id(ax) = cons a(x) id(bx) = cons (x) So id is defined by recursion using cons a and cons b, Therefore, the identity function is Primitive recursive, ined by ies of each class of gramma, Q.9. Write and briefly explain the charact classified according to Chomsky hierarchy. Determine the type of grammar G ; @ Sad, A aAB,B>b,A>a (ii) S > aAB, AB C, A b, B> AB. Ans. Chomsky hierarchies of grammars = grammars by the Chomsky hierarchy. Chomsky provided an inital classificat type: We can exhibit the relationship between ion into four languages Type -0 (Unrestricted grammar) Type — 1 (Context sensitive grammar) Type — 2 (Context free grammar) Type -3 (Regular grammar) Type 0 languages are those generated by unrestricted grammars, that is, the recursively enumerable languages. Type | consist of the context-sensitive languages, Type 2 consists of the context-free languages and Type 3 consists of the regular languages, Each language family of type k is a proper subset of the family of type k - 1. Following diagram shows the original Chomsky Hierarchy, Unrestricted (Type -0) Grammars : The unrestricted grammar is defined as = Vy Vp PS) where = a finite set of non-terminals = a finite set of terminals a 1 = starting non-terminal, Se V n Tech F*Semesier, Molle! Tesi Paper MS and P is set of productions of the following form ap where o and B are arbitrary string of grammar symbols with a # €. These grammars are known as type-O, phase-structure or unrestricted grammars. Context Sensitive Grammar : Let G = (Vi Vp, P, S) be context sentive grammar where V,, = finite set of non-terminals V, = finite set of terminals S = starting non-terminals S € V,, and P is the set of fules called productions defined as a>Bp where B is at least as long as a that is clearly lel < (Bi The term “Context-sentive” comes from a normal form for these grammars, where each production is of the form ct 4 a — a, B a with B # €. Replacement of variable A by string B is permitted in the “Context” of a, and a. Context-Free Grammars : Mathematically context-free grammar is defined as follows: : “A grammar G = (V,, V, P, S) is said to be context-free” where V,, = A finite set of non-terminals, generally represented by capital letters A, B, C, D, . A finite set of terminals, generally represented by small * letters, like a, b,c, def « S = Starting non-terminal, called start symbol of the grammar. S belongs to Vip P = Set of rules or production in CFG. Gis context-free and all production in P have the form a>Bp where a eV, and Be VV," Regular Grammars : A regular grammar may be left linear or right linear.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy