Turing 2
Turing 2
The converted TM is
1, 1, R/ 0, 0, R
1, 1, R 0,0, R
B, B, R 0, 0, R 1, 1, R 1, 1, R
4, 0, 0. R 1,1, R B, B, R
0,0, R
1, 1, R
The modified TM is (converting 011by 100) as
follows. The modifications are denoted in bold.
1, 1, R/ 0, 0, R 1, 1, R/ 0,0, R
B. B, R 0, 1, R 1,0, R 1,0, R 0, 0, R 1,1, R \B, B, R
0,0, R
1, 1, R
Reading Head
Finite
Control
Stack 2 Stack 1
Solved Problems
. Consider the Turing machine's description in the following table below. Draw the computation
sequence of the input string 00. [WBUT 2008]
Present State Tape Symbol :: b Tape Synmbol :: 0 Tape Symbol :: 1
Q 1L4, OR4,
bR4, 0L4; 1L4;
bR44 bR4
OR4, ORA4 1R44
OL4,
Sol(Q,
ution:BO01)
(Q BOOB) -’ (Q,, 00B) ’ (Q,, 00B) ’ (Q,, 001) ’ (Q,, 001) ’ (Q,, B001)
’ (Q, B01) ’ (Q,, B01) ’ (Q, BO1B) ’ (Q, BO10B) ’ (Q,, BO100)
’(Q., BO100) ’ (Q,, BO100) ’ (Q,, BO100) -’ (Q, BO100) ’ (Q, BO100) ’ (Q, BO100)
’(Q, BO100 ’(Q,, BO100B) -’ (Q, BO1000B) ’(Q, BO10000)
By this process, it will continue as there is no halt in the Turing Machine.)
452
Introduction to Automata Theory, Formal Lanquages and Computation
())
Design a Turing Machine to test a string of balanced parenthesis. Show an ID for
Solution: There aretwo types of parenthesesopen parentheses and close parentheses.
parenthesis means that for each open parenthesis there is a close parenthesis. It may be nested Balanced
like ((()) ) or may be non-nested like (() 0) or ()O) or any other form. But for each open
parenthesis, there is a close parenthesis. [The definition that a balanced parenthesis means an
equal number of open and close parentheses is wrong.
As an example, ) ()()(is not abalancedparenthesis.] The string must start with an open Dare
thesis and after that open parenthesis or close parenthesis can appear, but tor any position of the
string, the number of open parenthesis is greater than or equal to the number of iclose
The Turing Machine is designed as follows. Start from the leftmost symbol and parenthesis.
traverse
right
to find the first close parenthesis. The transitional function is
8(4 () ’ (g, (,R)
Upon getting the first close parenthesis, replace it by X, change the state to q,, and move lef
to find the open parenthesis for the replaced close parenthesis. The transitional function is
4, )')’ (4, X, L)
Getting the open parenthesis, replace it by X' and change the state to q,. The transitional func
tion is
ög, 'X) ’ (9 X, R)
For anestedparenthesis like ((0), the machine has to traverse X, which is the replaced symbol
of the open parenthesis at the time of finding the open parenthesis. The transitional function for
traversing this is
IDfor () 0)
lo. BO X))B) >(9 B()O)B)’(4,, B(/(O)B)’ (g, BXX()B)’ (g, BXX(())B)
a. BXXx))B) ’(, BXX()B) -’ (4,, BXX())B) ’ (4, BXX(( X)B)
ia BXX XX)B) ’ (4,, BXX(XX)B) ’ (4,, BX X( XXXB) ’ (g, BX X( XXXB)
lo. BXX(XXXB) ’ (4, BXXXXXXB)- (4,, BXXXXXXB) ’ (q, BXXXXXXB)
BXXXXXXB) ’ (4, BXXXXXXB) 4, BXXXXXXB) ’ (q, BXXXXXXB)
[Halt)
: Design aTuring machine to perforn nmod 2. (Or check whether anumber is odd or even) From
here, by instantaneous description, check whether the number 5is odd or even.
Solution: nisany number of same input alphabets. Let us take n number of 0's. The machine
is in state q, and the read-write head is on the beginning input symbol of the input tape. Getting
input 0', it moves towards the right replacing "0' by B'and changes state to q,. The transitional
function is
S4,, 0) ’ (4,, B, R)
In state q,, by getting the input 0, it moves towards the right replacing 0° by
state to q,. The transitional function is
B'and changes
S(4,, 0) ’ (q, B, R)
By the previous two transitional functions, all the 0's are replaced by
is even, then the
B'.Ifthe number of 0
machine will reach to the end of the string with state q,. At the end, it will get B'
and traversing that the machine will halt (means the number is even).
The transitional function is
8(g,, B) (4,, B, H)
If the number of 0' is even, then the machine will reach
to the end of
With getting input symbol B', it will traverse left by changing the statethe string with state g,.
function is to q.. The transitional
o(4,, B) ’ (4,, B, L)
sate 4,, by getting input B, the machine halts by replacing 'B' to 0' (means the number is
0dd). The transitional
functionis
84,, B) ’(q,,0, H).
0for n= 5: The string is
00000.
(a, 00000B) ’(9,, B0000B) ’ (qg,, BB000B) ’ (q,, BBB00B) ’ (g,, BBBBOB)
>(4,, BBBBBB) ’ (q,, BBBBBB) ’ (9, BBBBOB) (Halt)
Construc aTuring machine to compute the function f(w) =w', where we(a, b)* and wB is the
everse of w. [UPTU2004]
454 Introduction to AutomataTheorv, Formal Lanquages and Computdtio
symboll is "b at the time of traversing left, the transitional functions are
Iftheend
S(4, a) ’ (4,, a, L)
S(4,. b) (4,, b, L)
S(4,, X) ’ (4,, Y, R)
o(4, Y) (4,, Y, R)
previous mentioned transitional functions, the total string is traversed and reversed but
Bythe of'a and'b there are X' and Y',
place
inthe
Fromthesecondtime oftraversing the string, the TM need not findthe symbol 'B' to mark the
rightendof the string. In the state q, or q,, it will get Xor Y, which are representations of the
symbol. The transitional functions are
alreadytraversed
d(4,, X)’ (4, X, L)
o(4,, Y) ’ (4, Y, L)
X) ’ (45 X, L)
8(4, Y) -’ (4, Y, L)
The string may be of even length or odd length. For the odd length string, the middle element
may be 'a' or b'. If the middle element is a, then after replacing the middle element by X, the
TM moves right but it finds either Xor Y° (because all the other symbols are already replaced).
It backs left by changing the state to 4, or q, using the transitional functions mentioned earlier.
At the left, again it gets either "X° or Y°. The TM changes the state to q, and moves right by the
following transitional functions
ô(4,, X) ’ (4, X, R)
a(9, Y) ’ (4,. Y, R)
S(q,, X) ’ (9 X, R)
S(4,, Y) ’ (4,, Y, R)
Ifthe string is of even length, then the machine gets 'X' or 'Y' in the state q, after replacing all
the 'a"' and 'b'.The transitional functions are
S(4,, X) ’ (q, X, R)
S(q,, Y) ’ (4 Y, R)
e machine traverses right to find the end of the string consists of 'X' or Y", When it gets
B,it traverses left by changing the state from q, to 4,
S(q, X) ’ (q, X, R)
S(q,, Y)’ (q, Y, R)
84,, B)’ (4,, B, L)
uS State q, at the time of traversing left, the TM replaces all X's by 'a' and all Y's by b'.
S(4,, X) ’ (4,, a, L)
S(q,, Y) ’ (q,, b,L)
By this process, when it gets the symbol 'B' at the left it halts.
d4,, B) - (q,0 B, H)
456 Introduction to Automata Theory, Formal Languages and Computation
If the string is a blank string (no 'a' and/or b'), the machine gets 'B' in the state q,
and halts
S(4,. B)’ (4,, B, H)
The transitional functions are represented in the tabular format.
State B X Y
-haa
TuringMachine 457
traversedand
before'l'are
when all the 0's placedi
is used traversingright traversed.
R) Il this and '1'are
Y)’(9,,Y, 1')
4.,
the machine is all 0'(placedbefore and'1'are traversed
when '1') remaining 0
R) 1/ this is used all '0 (placed before search for the
X, when
ois X)’(q,, X, R)//this is used is traversingrightto
’ (9,, machine
g,X) andthe traversed.
(placedafter'1'). '1'are
'0' and
whenall
H) / this isused halts.
Sa.B)’(9,,
B, function, the machine position right by
transitional 1) by one [JNTU2008]
.tonexecuting
thelast
input string overalphabet(0,
the
Turing machinethat shifts traversing through
Designa character. B#0110B after
the first string
inserting' as
string BO110B willbe right to the end ofthe two
condition,a to the to
According to the machine, it has to traverseGetting '0'or "1, it changes in the
Calution: the If
machine. To design Then, it hasto traverse signify the traversed symbol.which the
left.
e Turing symbol "B'). respectively. The states
determined by the replaced by the symbol for
S, and S,), 1), it will be
ifferentstates (say, anysymbol (0'or recursively.
gets This is performed
statesthe machine traverse left. right
sateischanged
and
1' is traversed from left to
0/1, R) //0° or
&lg, 0/1) ’ (4,, / end of the
string
symbolis 0"
8g,, B) ’ (4,, B, L)
signifies that theprevious
/ q, symbol is 1'
0) ’ (4,, 0, R) l q,signifies that the previous '0'
S(q, 1)’ (q, 1, R) /B after the string is replaced 1"
by
ôq,, B) -’ (q, 0, L)
I/B after the string is replaced bymachine traverse left
Sg, B) ’ (q,, 1, L) L)/ whatever the symbol (0 or l);replace the next as 0"
og, 0/1) ’ (9,, 0/1, symbol is "0',
’ (4,0, L) /ifthe previous
symbol is '1', replace the next as '1'
Ð4,, 0/1)
/if theprevious
q,, 0/1) -’ (q 1, L) / reached the left end
o4,, B) -’ (g, B, R) Replaced the first symbol by #"
I/
ô(g, 0/1) ’ (9,, #,R) //Traverse right
ð(q,, 0/1) - (q,,0/1, R) /Halt
d4, B) ’ (g,, B, H)
follows.
Diagrammatically, it is represented as 0/0, L
1/1, R
B/0, L
O/0, R O/0,L
O/0, R
1/1, R 1/0, L
B/B, L
B/1, L
B/B, R 1/1,A 1/1,L
O/1, L
\O/0, R
1/1, R
O/#, R
1/#, R B/B, H
458 Introduction to Automata Theory, Formal Languages and Computation
7. Construct a TM over the alphabet {0, 1, #} where 0° indicates blank, which
takes a
string of'l' and # and transfers the rightmost symbol to the left hand end. Thus,
becomes 0001#1#1 #000.
[Jaipur non-20101
000#1#1#1
University n0ul00l
+\
Solution: The machine has to traverse three symbols 0° as blank, 1, and #'.
To
machine, traverse right up to 0° (blank). Getting it, traverse left. The symbol design the
For these two symbols, change to two different states, replace the input by 0 may be 1' or '*.
left to get 0° (blank). Upon getting it, replace it by '1' or # according to the (blank)
state and
The transitional functions are traverse
d4,, 1) ’ (4, 1, R) 1/ traverse right
d9,,#) ’ (9,, #, R) I/ traverse right
4,. 0) (4,, 0, L) l/ right end, traverse left
dq,. 1) -’ (4,0, L) |/ ifthe rightmost symbol is 1', the state is q.
(4,. 1) ’ 4,, 1, L) //traverse left
d(4,, #) ’ (4,, #, L) / traverse left
o4,, 0) -’ (9, 1, R) lreplace the 0° (blank) before the first symbol by 1
g, 1/#) ’ (g., 1/ #, R) 1/ traverse right
(g,, #)’ (4 0, L) I/if the rightmost symbol is #, the state is q.
O4, 1) -’ (4, 1, L)
q, #) ’ (4, #, L)
o(4, 0) ’ (4, #, R) lreplace the 0' (blank) before the first symbol by
#"
öq, B) ’ (4, B, H)
8. Design a Turing machine for (a, b}* {aba} {a,
b}*. [GTU2010]
Solution:
Way 1: This is a non-deterministic
The transitional functions are as Turing machine. The important portion of the string is 'aba'.
follows.
Ð4,,a) -’ (4,, a, R), (4,, a, R)
ö4,, b) ’ (4,, b, R)
ö4,, b) ’ (4,, b, R)
o(4, a) ’ (44, a, R)
d(4,, a) ’ (q, a, R)
84,, b) ’ (4, b, R)
(4, B) (4, B, H)
Way 2: Converting the regular
the following. expression to an equivalent finite automata with e moves we get
a, bt
a, b
b a
Turing Machine 459
Inserting a new initial state q, and final state 4p,the finite automata forms as follows.
a, b a, b
B, B, R b B, B, R
The fnal Turing machine is formed by modifying all inputs by (ip, ip, R).
a, a, R a, a, R
b. b, R b, b,R
a, a, R B, B, R
B, B, R a, a, R b,b, R
[UPTU 200S]
9. Design a Turing machine that accepts L={a"bn, n>0}.
'a' in initial state, replace it by X with the
state
Solution: For each 'a', there are two "b's. Getting traverse
replace it by Ywith the state changed and
changed and traverse right. Getting first b', traverse left. By this process, if it gets Y in initial
Then,
right to replace the second 'b' by Y'. not, halt.
to check whether any b' is left or not. If
state, it means no 'a' is left. Traverse right
The transitional functions for the Turing machine are
and traverse right
4,, a) -’ (q,,X, R) I/ replace a' by Xfind 'b'
right to
dq,, a) ’ (4,, a, R) I/traverse
replace it by Y
öq,, b)’ (4,, Y, R) /l getting 'b', second 'b'by Yand traverse left
dq, b)’ (4,,Y, L) /replace the
/ traverse left
dq, Y) ’ (q,, Y, L)
traverse left in search of X*
dg,,a) ’ (g,, a, L) /
’ (g,, X, R) /getting X, change the state toq, and start the phase again
S(g., X)
Y) ’ (q,, Y, R) // needed from the second move onwards
Sg.,
are replaced by 'X
Sg,, Y) ’ (4, Y, R) /if all'a' right in search of 'b'
traverse
S(g,, Y) ’ (4,, Y, R) //
(4, B) ’ (9, H)