0% found this document useful (0 votes)
45 views

Turing 2

Turing Test
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

Turing 2

Turing Test
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Turing Machine 49

The NFA for accepting (0, 1)°01l(0. 1)* is


0,
0
q,

The equivalent DFA is

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

B5 Two-stack PDA and Turing Machine


NO-Slack PDA is already discussed in the pushdown automata chapter. It is also discussed that a
ainot be only two stack but may be more than two stacks (a bcd", n >0). In real, the PDA
poWer ofa PDA increases by adding extra stacks. Here, the following question arises language accept
'is two-stack
Ore than two stacks) PDA as strong as the TM?". In this section, we shall learn about a theorem
Poposed by an American artificial intelligence scientist Marvin Minsky called the Minsky theorem
Which answers this
question.
450
Introductionto AutomataaTheory,,Formal Languagesand Computation
8.5.1 Minsky Theorem
Any language accepted by atwo-stack PDAcan also be accepted by some TM and Vice versa.

8.5.1.1 General Minsky Model


Ageneral Minsky model is shown in the following figure.
WP Tape

Reading Head

Finite
Control
Stack 2 Stack 1

Fig. 8.4 Two Stack PDA


The model in Fig. 8.4 is a two-stack PDA containing an input tape, a reading head, and finite control as
it was in PDA.The additionals are two stacks S, and S,. Let the language be abc" for n> 1. Scanning
'a', the symbols (say X) are put into stack S,.With the stack top X' in S,, 'b' is scanned and the sym
bols (say Y) are put into stack S,. At the time of traversing 'c', the stack symbols must be X(for S,) and
Y(For S,). These are popped for traversing 'c'.
Atwo-stack PDA is capable of accepting (ab'cd, n > 1), (abcdPe", n > 1), and so on, with the
additional stack. Accepting these types of languages is not possible for a single-stack PDA but possible
for a TM. By this process, the two-stack PDA simulates a TM.
The following example shows the acceptance of (a b'cd, n>1) using the two-stack PDA.
Example 8.22 Design atwo-stack PDA for (a"b-ed", n2 1).
Solution: Traversing 'a', Xare put intostack S,. Traversing b' with the stack top X° in S,, '*
popped from S,, and "Y' ispushed intoS,. Traversing 'c with the stack top Y' in S,, Yis poppeu
from S,, and 'Z' is pushed into S, Traversing 'd', "Z' is popped from S,. The transitional functions are
respectively,)
ö(4, 2, 2,, z,) ’ (4,, 2,, z,) (z, and z, are stack bottom symbols of S, and S,,
ö(4,,4, Z,, Z,) ’(4, XZ, 4,)
8(4,, a, X, z) ’ (9, XX, z,)
ö(q,, b, X, z,) ’ (4, , Yz,)
ö(4, b, X, )’(4, 2, YY)
(4,, C, z Y)’ (9, Z, )
S(4,, e, Z, Y) ’ (4,, ZZ, 2)
S(4,, d, Z, z) ’ (4, 4, z)
S(4, d, Z, z,) ’ (4,4, z,)
(4, 4, Z,, 2)’ (4, 2, 2,) lI accepted by the final state
Turing Machine 451

What We Have Learned So Far


combina
Turing machine was proposed by A.M. Turing in 1936 as a model of any possible
1 The the
computational process carried out by the present day's computer can be done on
tion. Any
Turing machine.
languages are
,The Turingmachine is the machine format of unrestrictedlanguage, i.e., alltypes of
machine.
accepted by the Turing
machine can be developed for
: Undecidable problems are not solved by the computer as no Turing
these problems.
The mathematical description of the Turing machine consists of 7 touples (Q, E, T, , qp, B, F),
where O is the finite set of states, is the finite set of input alphabets, I' is the finite set of allow
able tape symbol, d isthe transitional function, g, is the initial state, B is the blank symbol, and F
is the final state.
&The transitional functions of the Turing machine are inthe form QxI’ (QxTx {L, R, H}).
That is, from one state by getting one input from the input tape the machine moves to a state,
writing a symbol on the tape, and moves to left, right, or halts.
6 The mechanical diagram of the Turing machine consists of the input tape, the finite control and
the read-write head.
7. UDon execution ofa transitional function, the machine goes to some state, writes a symbol in the
cellof the input tape from where the input symbol was scanned, and moves the reading head to
the left or right or halts.
8. The instantaneous description (ID) of a Turing machine remembers the contents of all cells from
the rightmost to at least the leftmost, the cellcurrently being scanned by the read-write head, and
the state of the machine at a given instance of time.

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

S(4,, ()’ (4, X, R)


Then, traverse towards the right to find the close parenthesis. Here, the machine may have
to traverse X, which is the replaced symbol for close parenthesis. The transitional function for
traversing this 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

S(q, 'X*)’ (4,, X, L)


Traversing right, if Bappears as an input, then there is noparenthesis (open or close) left at the
right side. Then, traverse left to find if any parenthesis is left at the left side or not. The transitional
function is

8q,, 'B') ’ (4,, B, L)


At the time of left traversing, the machine has to traverse X by the following transilioe
function

a4, 'X*)- (4, B,L)


At the left hand side if it gets B, the machine halts.

4, "B') ’ (4, B,H)


Turing Machine 453

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

start with "a' or may start with 'b.f


Solution: The string consists of 'a' and'b, The string may
with 'a'. The same for "b' also
the string starts with 'a',the reverse of the stringwill end will traverse
Ifthe beginning state is q, and if the string starts with a', the TM 'a'.) right replacing
The
'a' by 'X' and changing the state to 4, (This q, specifies that the symbol was
function is transitional
S(q, a) ’ (q,, X, R)
At the time of traversing right, the machine can get an 'a' or"b'. The transitional functions for
traversing 'a' and 'b' are
o(4,, a) ’ (4, a, R)
84,, b)’ (4,, b, R)
Ifitgets B',it means the string ends. The TM changes the state to 4, and traverses left by the
following transitional function
S(4,, B) ’ (4, B, L)
(which is
The string may end with 'a' or may end with b.As the beginning symbol was 'a'
memorized by the machine by state g., then q,), the end symbol will be replaced by X, whatever
itmay be. But the end symbol willbe the beginning symbol. So, what the end symbol is, it will
be memorized by different states. In this case, if the end symbol is a', itwill be memorized by
changing the state q, to q, and if the end symbol is b', it will be memorized by changing q, to a.
The transitional functions are
ö4,, a) ’ (9, X,L)
S(4, b) ’ (4, X, L)
Traversing left, the TM has to traverse 'a' or 'b.If the state is q., the transitional functions are
8(4, a) ’ (4, a, L)
S(4, b) -’ (9, b, L)
Atthe time of traversing left, the TM may get X' or Y', the replaced symbols of 'a' or 'b.
The machine is in state g., which means the rightmost symbol of the string was 'a'. Upon gettng
Xor Yat the left end, the TM replaces it by Xand changes the state to q,. The transitiond1
functions are
S(4, X) ’ (9,, X, R)
öq, Y) ’ (4,, X, R)
only
If the string starts with 'b', the transitions are the same as the string starts with'a', but
some changes of states. The transitional functions are
Ö(4,.b) ’ (4,, Y, R) search of end ofstring
o4, a) ’ (4,, a, R) // traversing right in
ô(q, b) ’ (4,, b, R)
B)’ (q B, L) // end of the string and traversing lell
o(4,, a) -’ (g, Y, L) /if the end symbol is 'a'
d4, b) -’ (4,, Y, L) /lIl if the end symbol is b'
Turing Machine455

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

(9, X, R) (4,. Y, R) (9, X, R) (9,. Y, R)


(9,B, H)
(4, a, R) (9, b, R) (4, X, L) (4,, Y, L)
(4,, B, L)
(9,, X, L) (4,, X, L) (g, X,R) (4 Y, R)
(4,a, R) (9, b, R) (9, X, L) (9,, Y, L) (4, B, L)
(9,. Y, L) (4, Y, L) (9. X, R) (9, Y, R)
(4,,a, L) (9, b, L) (4, X, R) (4,, X, R)
4 (4, a, L) (q, b, L) (9,,Y, R) (9,, Y, R)
(q, X, R) (4 Y, R) (4, B, L)
(9,, a, L) (9, b, L) (9,B, H)

5. Design a Turing machine for 0P1"0° n> 1. [Cochin University 2000|


Solution: The language consists of0 and 1. Here, n number of 1' are placed in between nnumber
of '0's and n number of "0'. The Turing machine is designed as follows. For each leftmost 0",
search for '1' and the leftmost '0' placed after 1' and again traverse back to the left to search for
the leftmost '0°. 0' is replaced by X, and '1' isreplaced by Y".
When all '0' are traversed and replaced by X,the machine traverses right side to find if any
untraversed '0° or 1'is left or not. Ifnot, the machine gets Yand Xand at last blank. Upon getting
the blank symbol, the machine halts.
The transitional functions are

d(4,, 0) ’ (4,, X, R) Il 0' is traversed


Ð(4,, 0) -’(q,, 0, R) / the remaining '0' s are traversed
4,, 1)’ (4,, Y, R) Il T' is traversed
d4, 1) -’ (q,, 1, R) / the remaining 'l's are traversed
oq,, 0)- (q, X, L) // '0' placed after '1' is traversed
Ö(q,, 1) -’ (9, 1, L) / the remaining 1's are traversed from right to left
d(q,, Y)- (q, Y, L) I/Y, replacement for '1l' is traversed
d(4,, 0) -’ (4,0, L) / the remaining 0's are traversed from right to left
O4, X)’ (9,, X, R) rightmost X,replacement of "0 placed before 1'is traverseo
Y)’ (9,, Y, R) // this is used from the second time onwards
o4, X) ’ (4,, X,R) //this is used from the second time onwards
8(4, X) ’ (g.,X, L) |/this is used from the second time onwards
traversed
d(4,, Y) ’ (q, Y, R) /this is used when all the 0's placed before '1' are
aaabaaa

-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)

Multiple Choice Questions


format c) Finite control
The Turing machine is the machine
1. d) Stack
of language.
a) Type 0 b) Type 1 3. The difference between the Turing machine
c) Type 2 d) Type 3 and the two-way FA is in the
Which i art of the mechanical dia a) Input tape
machine? b) Read write head
c) Finite control
d) All of these

You might also like