Turing 1
Turing 1
(q,,a, R) When the leftmost *b’ is traversed, the state is 4q,- That ‘b’ is replaced by Y, the state is changed tog, and the head is moved to one left. The transitional functional is ™ 8(4,,d) > (qn ¥, L) Then, it needs to search for the second ‘a’ starting from the left, The first ‘a’ is replaced by X, which means the second ‘a’ exists after X. So, it needs to search for the rightmost ‘X”, After traversing the leftmost “b’, the head moves to the left to find the rightmost X. Before that, it has to traverse ‘a’. The transitional function is &(q,, a) > (q,, a, L) After traversing all the ‘a’ we get the rightmost ‘X’, Traversing the X the machine changes its state from q, to q, and the head moves to one right. The transitional function is 5a, X) > (4, X, R) __ From the traversal of the second ‘b’ onwards, the machine has to traverse “Y’. The transitional func- tion is 84, Y) > GY, R) Similarly, after traversing *b’, the machine has to traverse some Y to get the rightmost “X°, 54, ¥) > (4, ¥, L) When all the ‘a’s are traversed, the state is q,, because before that state was q, and the input was xX. The head moves to one ri ight and gets a Y, Getting a Y means that all the ‘a’s are traversed and the same number of ‘b’s are traversed. Traversing right, ifat last the machine gets no ‘b’ but a blank ‘B’, then the machine halts. The transitional functions are wa, ae (qu. Y) > Gy YR) 8a Y) > (Gy YR) 6(q,B) > (q,, B, H)Turing Machine 433 ID for the String ‘eaabbs? First, the tape symbols are Blalajlaj]b]b]b|B 3(q a) — (q,, Xaabbb, R) B/xX|ala|b|b|o|B 8(q,, a) > (q,, Xaabbb, R) B/x|/ajlalb|{[b|o|[B t (q,, a) > (q,, Xaabbb, R) Ble |e |b |b lb |B &(q,, b) — (q,, XaaYbb, L) B/|X]ajalyYy}]bj|b/B t 8(q,, a) > (q,, XaaYbb, L) Bx | eee | Xe |b 8 t 8(q,, a) > (q XaaYbb, L) B eX | edna | ved |b eB 8(q,, X) > (dy XaaYbb, R) Bi xl]afa/y |b |b |B t &(q,, a) > (q,, XXaYbb, R) B;/x|x]a/]yY|b]b/B t &(q,, a) > (q,, XXaYbb, R) BX |X |e | ¥ |b) be 8 8a, ¥) > (q,, XXaYbb, R) Blx|xJa/y|]|b{>b]B La434 | Introduction to Automata Theory, Formal Languages and Computation 8(q,. b) > (q, XXaYYb, L) Pies |< o| a << 8a. Y) 3 (@ XXaYYb,.L) [BY x 8(q,, a) > (q,, XXaYYb, L) B| xX >| —> [>| 8(q,. X) > (q,, XXaYYb, R) B |X &(q,. a) > (q,, XXXYYb, R) Be | ex 4 &(q,. Y) > @,, XXXYYb, R) B &(q,.¥) > (q,. xxxvver) [B] x] x] x] ¥]¥] >] B 5,6) > @, XXXVYYL) | B | x | x |X | ¥ | ¥ |X &(q,, Y) > XXXYYY, L) Boke |e |x ey | Y x B &(q,, ¥) > (Gy XXXYYY,R) | B|X |x| xfyfyfy|sB &(q,, ¥) > (a, Xxxv¥VY.R) |B] x] xP xflylylylsTuring Machine | 435 54. ¥) 3 @,, xxxvvy,r) |B] x | x 8) Y) >, xxxyyy,r) | B | x | x 34, ¥) > @, xxxvvy,R) [Ba] x[ x] x] y¥|¥/¥18 &(q,,B) > (q, Xxxvvy,H) [B |x| x |x| ¥|Y|Y B euuctsem Design a TM to accept the language L= {WW%, where We (2, b)"} | Show an ID for the string ‘abaaaaba’ with tape symbols. "Solution: W* is the reverse of W. If W starts with ‘a’ o ends with ‘a’ or ‘b’, W* starts with ‘a’ or ‘b’, respectively. The If the string W starts with ‘a’, upon traversal, that ‘a’ 1 “b’, W® ends with ‘a’ or “b’, respectively. If W M can be designed as follows. ” is replaced by X with a state change from q, to 4g, and the head moves to one right. The transitional function is 8(qy, a) > (4X RD WF ends with ‘a’ if W starts with ‘a’. The machine the machine needs to traverse the end symbols of W and thi functions are needs to search the end ‘a’ of W®. Before that, beginning symbols of W*. The transitional 8(q,, 2) > aR) &(q,.b) > (8) ‘After the end symbol of W®, there exists the bl: gets a B, it traverses back to the left side and gets lank symbol B. In the traversal process, if the machine the end symbol of W*. The transitional functions are 8g, B) > @y BL) 8a, a) > 4 XL) Now, the machine needs to search for the second Ss; symbol of W. Before that, it has to traverse the beginning symbols of W* and the end symbols of W. The transitional functions are 3(q,, a) > (ay a L) &(qy b) > (yb, L) it sts the ri; * When the machine gets the rightmost X, it recognizes that the next symbol of W exists after that ‘X”. The transitional function is ~~ aa 8a, X) 3 (a, x, R)> sae | rte Automata Theory, Ferma Languges nd Computation If the string W starts wi changed, The transitional functions are (qq: ) 9 (gq, YR) &q,. 4) > (qa. RY Sq, b) > (q,, b, R) &(q,. B) > (q,. B. L) &( qe. b) > YL) 5g. A) 9 (Ie aL) 5(q,. b) > (yb, L) 5(q,. Y) > (Gyr Ys RY ith ‘b’, the transitions are the same as the previous one but with some sta, ey After the first traversal, i.e., from the second traversal onwards, the machine need not traverse yp to the end of W*. In state g, (W starts with ‘a’) or q, (W starts with “b’), if the machine gets X or Y, it traverses back to the left to point the rightmost ‘a’ or ‘b’. The transitional functions are ' 8(q,, X) > @y XL) 8(q, ¥) > @y YL) (a, X) > (qs, X, L) 8a, Y) > s ¥, L) When all the symbols of W and W® are traversed, the machine gets an X or Y in the state q,. The machine halts if in state q, it gets an X or Y. The transitional functions are 8(q, X) > (q, X, H) (4, ¥) > Gp ¥, H) The transitional functions can be given in a tabular format as follows. eee State a B B x Y a (q,X.R) (a, Y.R) ; (a, X,H) (a, ¥.H) 4 (q,,.a,R) (q,,b, R) (qy BL) (a, XL) (aX) 4, (ay XL) a - - - 4, (4,4, L) (q,,b, L) = (dy XR) ~ a (aya, R) (qyb, R) (ay B, L) (ay X, L) (qs YD | 4s (qy Y,L) - = 2 % (ga, L) (qb, L) a 2 (ay ¥. R)Turing Machine | 437 1D. ' : . Jor the String ‘abaaaaba’: (Here, the symbols in bold represent the read-write head position.) (Go abaaaaba) — (q,, Xbaaaaba) > (q,, Xbaaaaba) — (q,, Xbaaaaba) — (q,, Xbaaaaba) > (@, Xbaaaaba) (q,, Xbaaaaba) — (q,, Xbaaaaba) — (q,, XbaaaabaB) — (q,, XbaaaabaB) > (y Xbaaaabx) — (q,, XbaaaabX) > (q,, XbaaaabX) — (q,, XbaaaabX) — (q,, XbaaaabX) > (q;, Xbaaaabx) — (q,, XbaaaabXB) — (q,, XbaaaabX) — (q,, XbaaaabX) — (q,, XYaaaabX) > y XYaaaabx) (q,, XYaaaabX) — (q,, XYaaaabX) > (q,, XYaaaabX) — (q,, XYaaaabX) — (4x, XYaaaabX) — (q,, XYaaaaYX) > (qo, XYaaaaYX) — (q,, XYamaaYX) > (q,, XYaaaaYX) 7 (Qs, XYaaaaYX) — (q,, XYXaaaYX) — (q,, XYXaaaYX) — (q,, XYXaaaYX) + (q,, XYXaaa¥X) > y XYXaaaYX) > (q,, XYXaaXYX) > (q,, XYXaaXYX) — (q,, XYXaaXYX) — (q,, XYXaaXYX) > (G4, XYXXaXYX) — (q,, XYXXaXYX) — (q,, XYXXaXYX) — (q,, XYXXXXYX) > (do, XYXXXXYX) — (q, XYXXXXYX) [Halt] ull dake Design a TM to accept the language L = {set of all palindromes over a, b}. Show the IDs for the null string, ‘a’, ‘aba’, and ‘baab’. Solution: Palindromes are of two types: i) Odd palindromes, where the number of characters is odd ii) Even palindrome, where the number of characters is even. A null string is also a palindrome. Astring which starts with ‘a’ or ‘b’ must end with ‘a’ or ‘b’, respectively, if the string is a palindrome. Ifa string starts with ‘a’, that ‘a’ is replaced by a blank symbol ‘B’ upon traversal with a state change from q, to q, and the right shift of the read—write head. The transitional function is &(q,, a) > (q,, B, R) Then, the machine needs to search for the end of the string. The string must end with ‘a’, and that ‘a’ exists before a blank symbol B at the right hand side. Before getting that blank symbol, the machine needs to traverse all the remaining ‘a’ and *b’ of the string. The transitional functions are &(q,, a) > (q,, a, R) &(q,, b) > (q,, b, R) 8(q,. B) > (q,, B, L) &(q,, a) > (q,, B, L) The machine now needs to search for the second symbol (from the starting) of the string. That symbol exists after the blank symbol B, which is replaced at the first. Before that the machine needs to traverse the remaining ‘a’ and ‘b’ of the string. The transitional functions are 8(q,, a) > (q,, a, L) &(q,, b) > (ay, b. L) &(q,, B) > (,, B, R) If the string starts with ‘b’, the transitional functions are the same as ‘a’ but some states are changed. The transitional functions are Gq, b) > @,, B. R) , &(q,, 2) > (4s, a. R)438 Introduction t0 ‘Autom Languages and Computation 8g, b) > (q..b. R) 5(q,. B) > (q,. B, LY 5(qy b) > Qu BL) [ or dg if the last When all ‘a’ and °D’ are traversed and replaced by B, the states may Be OM of dy or *b’, respectively. Transitional functions for acceptance are &(q,, B) > (a, B, H) 3a, B) > (@,, BH) a null symbol means blank B. In state q,,the machine A null string 1S also a palindrome. On the tape, , The transitional function is gets the symbol. &(q,, B) > (a, B. ) ‘ons in tabular form are represented as follows. The trans jtional funct qy BL) 4, = ( ID for Null String (q,,B) > (4, B) Halt] ID for the String ‘a’ (q, aB) > (4, BB) > (4p BB) > (q,, BB) [Halt] ID for the String ‘aba’ (q,, abaB) — (q,, BbaB) > (4,, BbaB) -> (q,, BbaB) > (ay = (q,, BbBB) > (g,, BBB) > (4, BBBB) [Halt] BbaB) — (4, BbBB) > (a BPBB) ID for the String ‘baab’ (aj, eabB) — (4, BaabB) ~ (4, BaabB) — (4, BaabB) —> (Gs BaabB) — (q,, BaabB) = (qy BaaBB) > (4, BaaBB) — (q,, BaaBB) — (4 , BaaBB) — (q,, BBaBB) > BBaBB oe ppaBB) Gq, BABB) ~(@, BBBBB) [Ha : ) > ) \ tem Design a TM to accept the language L =a"b'c’, where n> 1. \ Solution: This is a context-sensitive language. The language consi: uti : ists of of ‘a’ is equal to the number of *b’ which is equal to the number of ‘c’ . ae erie eee ’ er ‘c’ is followed by ® LyTuring Machine | 439 number of ‘b’ Which a search for *b’ and «g i c : and again traverse back to the left to search for the leftmost ‘a’. ‘a’ is replaced by followed by n number of ‘a’, The TM is designed as follows. For each ‘a’, ‘xX’, ‘dD’ is rep| “ye When allthe a Y’, and ‘c’ is replaced by ‘2’. untraversed ‘b’ or ‘cig ie ersed and replaced by °X’, the machine traverses the right side to find if any blank symbol, the machine halo,” Ne Machine we ¥ andZ andat ests Dian, Upon gexintbe The transitional functions are a ‘ Po XR) 1 istravered ae Ho be a,R) / i remaining ‘a’s are traversed Ly (q,, ¥, R) //‘b’ is traversed &(q,, b) — (q,, b, R) // the remaining ‘b’s are traversed 8(4y, ©) > (Gy Z, L) // ‘cis traversed (q,. b) > (q,, b, L) // the remaining ‘b’s are traversed from right to left &(4,, Y) > (q,, Y, L) //Y, replacement for ‘b’ is traversed &(q,, 8) > (q,,a, L) // the remaining ‘a’s are traversed from right to left (a, X) > (q,, X, R) // rightmost X, replacement of ‘a’ is traversed 8(q,, Y) > (q,, Y, R) // this is used from the second time onwards 5(qy, Z) > (ay, Z, R) // this is used from the second time onwards 5(qy Z) > (QZ, L) // this is used from the second time onwards 8d Y) — (dy, YR) // this is used when all the ‘a’ are traversed 8lgy Y) > (dy ¥, R) // this is used when all the ‘a’ are traversed and the machine is traversing right Z, R) // this is used when all the ‘a’ and *b’ are traversed. this is used when all the ‘a’ and ‘b are traversed and the machine is traversing right to search for the remaining ‘c’ B, H) // this is used when all the ‘a’, ‘b’, and ‘c’ are traversed transitional function, the machine halts. presented as follows. 8s 2) 7 eo 3d Z) 9 (Ay Zs R) // 8(q,, B) > Upon executing the last The transitional functions in tabular form are re] State a b c B X Y Z 4 (a, X,R) = = - - (q, YR) - a yaR) Gy Y,R) = a 7 (qy YR) S 4 - @%R) ZL) - - - (a2) a (yah (ay L) fs - @ XR) @.¥%L) (a, Z, L) a a ~ : - a (ay. ¥R) 2 R) : . eB. H) . - (ZR)formal Languages and Computation concatenation operation on strint awa hee, two 2 the blan! 0 sien * i te 2 a seit and Ws : = : ; : ration on fWO strings W, 2 es the coneatenat the Henk symbol B- ener traversal, 1 are do az The TM One TM SeP Son the t@Pe f the ps eprncatenate d. place od and the wo seri gs al Prnoved an al function” are E The | ig R) traversing sp of be first ae gymbol and converting aie | 5041 eR) 7 graversing ft sepa : sta a, a 1 aeensiog 1 OO second ST got he . sae 2 a2, bl blank ¢ se ee ‘ad verted to «p’ to keep the number aa; BY? (4 ) 1s the Ker” of the seem con Hae fae «at the left side 5 17 Ge 1,L) yr eraversing remaining la ea > Gi, B. HD // halts se x2 Pie : : i , i 2X+ ¥, where =|”, =|w, | [This machine 1S also applicable. for performing ae if itis 1D =i and ¥, = uit and the res eee H1BitltB) > 4 niBilll) Ge 1 1B1111B) > (> 1111111B) ul : : — 2 ea TB 1111 111BB 5, HILIIBB) de 11111 BB) > (4s 1111111 BB) > (er ) 111111BB) > Ge 3g TBE) Ge BETES Show an ID for4—-2=2- forms the s' operation. Here, * and y both are integer num! s of {1’. The two strings are placed on the input tape where W, an Solution: This Pe subtraction |W, | and y = |Wab dW, are the string separated by B. Starting traversal from the left hand si ‘state changed from dy 10 4, : e and traverses left anc raver ‘os the separating “B’ symbol ; ) s and all ‘1’ z ning of the first string, which starts after B at the left hand Ta iy ses aaa + oes continues till all the “I's of the ema the first “1” by are replaced by “B’- traverses right. This pI The transitional functions are Bae» 2 1.R) //all the ‘I's of the first string are traverse ay B) > GG. B.R) // the separating B is traversed aversed oe Ge » a all the ‘1's of the second string are tr " B, L) //to signify the end of the ee second stri nd string MB B with d of the second with state change an g and finds the begin- B and again de ‘1’, the machine moves towards the right. It traverses _In state q,, it again traverses right to find B. d changes the rightmost ‘1’ by B ( that is, the en string. It changes its stat sing left). It travers > (ay > Gs 1111111BB) [Halt] ks ED Design 2 TM to perform the following operation f(x, y) =X > Where * >y bers. Let x =