0% found this document useful (0 votes)
79 views39 pages

Turing Machine

ersg wert gwwr tgsret seghserg w
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)
79 views39 pages

Turing Machine

ersg wert gwwr tgsret seghserg w
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/ 39

Theory of computation

TURING MACHINE
Introduction to Turing machine, model, TM as a acceptor, TM as a recognizer, FSM to TM,
TM as a evaluator, Variants of Turing machine, Universal Turing Machine, Power of TM,
Application of TM

INTRODUCTION

The Turing machine (TM) is a simple and powerful mathematical model of computation that
can be used as language acceptor, language translator, and function evaluator. The languages
that the Turing machine can compute are recursively enumerable.

BASICS OF TURING MACHINE

The basic model of Turing Machine is shown in figure

B a a b b B

R/W head

Finite control

Turing machine consist of the input tape which is divided into number of cells. In each cell at
a time one symbol can be stored. The head of Turing machine is read/write head which can
move either in left direction or in right direction.

It can read and also can write one symbol at a time onto the input tape. It has finite set of
states which represents the status of the machine and at a given time machine can reside in
any one of these states. Turing machine consists of finite set of symbols which includes a
special symbol Blank symbol denoted by „B‟. Initially when no input is stored on tape, all
cells of tape consist of the blank symbol.

A move in the Turing machine depends on the current input symbol and the current state A
step in a Turing machine program is an action which is specified as a 5-tuple of the form:
(current state, current input symbol, new state, new symbol, direction of move)
Let us see one example how the transition is denoted:

δ(q0, a) = (q1, X, R)
Current state
Move
Current input
New state New symbol
Formal Definition: The Turing Machine M, is a 7-tuple variable as given below:

Prepared By:Rohini Patil Page 1


Theory of computation

M= {Q, , Г, δ, q0 ,B,F }

where, Q : Finite set of states

 : Finite set of input symbols

Г: Finite set of tape symbols which include the blank symbol

δ: The transition function

q0 : Initial state

B: Blank symbol

F: Finite set of final states

A Turing Machine can be described in following different ways:

1. Transition diagram
2. Transition table
3. Instantaneous description

Transition Diagram:

It is the graphical representation of the transition function. All notations are similar with the
transition diagram of Finite automata; just the way how transitions are labeled is different.

Consider the following example:

Current input

Move
Initial State
Replaced symbol
Transition table:

It is the tabular representation of the transition function. The transition table for transition
diagram shown below


0 1 B
Q
q0 - (q1,X,R) -

q1 (q1,0,R) - (q2,B, L)

Prepared By:Rohini Patil Page 2


Theory of computation

q2* - - -

Instantaneous description:

The working of Turing machine for a particular string is represented using instantaneous
description.

Examples of TM:

1] Design Turing machine for the language L= {anbn | n>0} May-14

Solution: The language becomes,

L= {ab, aabb, aaabbb, aaaabbbb, ……..}

Logic:

1. Each „a‟ is replaced by „X‟ and head movement towards right till „b‟.

2. Each „b‟ is replaced by „Y‟ and head movement towards left.

3. Repeat above two steps for remaining a‟s and b‟s.

Implementation: LetM= (Q, ∑,┌, δ, q0,B, F)

Where, Q = {q0, q1, q2, q3,q4 }


∑={a,b}
┌ ={a,b,X,Y,B}
q0=q0
B=Blank symbol
F={q4}
Working:

q0: Replace „a‟ by „X‟ and head moves towards right

q1:.Search for „b‟ and replace it by „Y‟ and head moves towards left, Bypass all „a‟s &„Y‟s.

q2: Bypass all „a‟s and „Y‟s. Search for „X‟ and replace it by „X‟only and head moves
towards right whenever get „a‟ at qo state repeat the cycle for all a‟s and b‟s.

q3: On q0 state if we get „Y‟ replace it by „Y‟only and head moves towards right Now, move
the head right till we get blank symbol to check that any „b‟ is remaining or not. Bypass all
Y‟s.

q4: After all Y‟s if we get blank symbol means no more b‟s are remaining.

Transition Diagram:

Prepared By:Rohini Patil Page 3


Theory of computation

Transition Table:


a b X Y B
Q
q0 (q1, X, R) - - (q3,Y, R) -

q1 (q1, a, R) (q2, Y, L) - (q1, Y, R) -

q2 (q2, a, L) - (q0, X, R) (q2, Y, L) -

q3 - - - (q3, Y, R) (q4, B, S)

q4* - - - - -

Instantaneous Description:

|- q0aabbB |-XXYq1bB
|- Xq1abbB |-XXq2YYB
|- Xaq1bbB |-Xq2XYYB
|- Xaq2YbB |-XXq0YYB
|- Xq2aYbB |-XXYq3YB
|-q2XaYbB |-XXYYq3B
|-Xq0aYbB |-XXYYq4 (Accept)
|-XXq1YbB

2] Design Turing machine for the language L= {anbn cn | n>0} Dec-11

Solution: The language becomes,

L= {abc, aabbcc, aaabbbccc, aaaabbbbcccc, ……..}

Logic:

1. Each „a‟ is replaced by „X‟ and head movement towards right till „b‟.

Prepared By:Rohini Patil Page 4


Theory of computation

2. Each „b‟ is replaced by „Y‟ and head movement towards right till „c‟.

3. Each „c‟ is replaced by „Z‟ and head movement towards left till „X‟.

4. Repeat the above steps.

Implementation: LetM= (Q, ∑,┌, δ, q0,B, F)

Where, Q = {q0, q1, q2, q3,q4,q5 }


∑={a,b,c}
┌ ={a,b,c,X,Y,Z,,B}
q0=q0
B=Blank symbol
F={q5}
Working:

q0: Replace „a‟ by „X‟ and head moves towards right

q1:.Search for „b‟ and replace it by „Y‟ and head moves towards right, Bypass all „a‟s and
„Y‟s.

q2: Bypass all „b‟s and „Z‟s.

Search for „C‟ and replace it by „Z‟ and head moves towards left

q3: Search for „X‟ and replace it by „X‟only and head moves towards right whenever get „a‟
at qo state repeat the steps.

q4: On q0 state if we get „Y‟ replace it by „Y‟only and head moves towards right Now, move
the head right till we get blank symbol. Bypass all Y‟s and „Z‟s.

q5: After reading all Y‟s and „Z‟s if we get blank symbol means that is final state.

Transition Diagram:

Transition Table:

Prepared By:Rohini Patil Page 5


Theory of computation


Q a b c X Y Z B

q0 (q1, X, R) - - - (q4,Y, R) - -

q1 (q1,a,R) (q2, Y, R) - - (q1, Y, R) - -

q2 - (q2,b,R) (q3,Z,L) - - (q2,Z,R) -

q3 (q3,a,L) (q3,b,L) - (q0,X,R) (q3, Y, L) (q3,Z,L) -

q4 - - - - (q4,Y,R) (q4,Z,R) (q5,B,S)

q5* - - - - - - -

Instantaneous Description:

|-q0abcB |-q3XYZB
|-Xq1bcB |-Xq0YZB
|-Xq1bcB |-XYq4ZB
|-XYq2cB |-XYZq4B
|-XYq3ZB |-XYZq5 (Accept)
|-Xq3YZB

3] Design Turing machine for checking well formedness of parenthesis. May-12

Solution: Well formedness of parenthesis means for every (,{,[ there will be ),},]

Logic:

1. Each „(‟ is replaced by „X‟ and head movement towards right till „)‟.

2. Each „)‟ is replaced by „Y‟ and head movement towards left.

3. Repeat above two steps for remaining ( and ).

Implementation: LetM= (Q, ∑,┌, δ, q0,B, F)

Where, Q = {q0, q1, q2, q3,q4 }


∑= {(, )}
┌ = {(,),X,Y,B}
q0=q0
B=Blank symbol

Prepared By:Rohini Patil Page 6


Theory of computation

F={q4}
Working:

q0: Replace „(‟ by „X‟ and head moves towards right

q1:.Search for „)‟ and replace it by „Y‟ and head moves towards left, Bypass all „(‟s &„Y‟s.

q2: Bypass all „(‟s and „Y‟s. Search for „X‟ and replace it by „X‟ only and head moves
towards right whenever get „(‟ at qo state repeat the cycle for all (‟s and )‟s.

q3: On q0 state if we get „Y‟ replace it by „Y‟only and head moves towards right Now, move
the head right till we get blank symbol to check that any „)‟ is remaining or not. Bypass all
Y‟s.

q4: After all Y‟s if we get blank symbol means no more (‟s are remaining.

Transition Diagram:

Transition Table:


Q ( ) X Y B

q0 (q1, X, R) - - (q3,Y, R) -

q1 (q1, (, R) (q2, Y, L) - (q1, Y, R) -

q2 (q2, (, L) - (q0, X, R) (q2, Y, L) -

q3 - - - (q3, Y, R) (q4, B, S)

q4* - - - - -

Instantaneous Description:

|- q0(( ))B |-XXYq1)B


|- Xq1( ))B |-XXq2YYB

Prepared By:Rohini Patil Page 7


Theory of computation

|- X( q1) )B |-Xq2XYYB
|- X( q2Y )B |-XXq0YYB
|- Xq2( Y )B |-XXYq3YB
|-q2X(Y )B |-XXYYq3B
|-Xq0( Y) B |-XXYYq4 (Accept)
|-XXq1Y )B

4]Design Turing machine for the language L= {anbn+1 | n>0} Dec-14(CBGS)

Solution: The language becomes,

L= {abb, aabbb, aaabbbb, aaaabbbbb, ……..}

Logic:

1 Each „a‟ is replaced by „X‟ and head movement towards right till „b‟.

2. Each „b‟ is replaced by „Y‟ and head movement towards left till „X‟ .

3. Repeat above two steps till all a‟s and b‟s are over..

4. For last „b‟ make it Blank.

Implementation: LetM= (Q, ∑,┌, δ, q0,B, F)

Where, Q = {q0, q1, q2, q3,q4,q5 }


∑={a,b}
┌ ={a,b,X,Y,B}
q0=q0
B=Blank symbol
F={q5}
Working:

q0: Replace „a‟ by „X‟ and head moves towards right

q1:.Search for „b‟ and replace it by „Y‟ and head moves towards left, Bypass all „a‟s and
„Y‟s.

q2: Bypass all „a‟s and „Y‟s. Search for „X‟ and replace it by „X‟only and head moves
towards right whenever get „a‟ at qo state repeat the cycle for all a‟s and b‟s.

q3: On q0 state if we get „Y‟ replace it by „Y‟only and head moves towards right Now, move
the head right to search for the last „b‟. Bypass all Y‟s.

q4: After all Y‟s if we get „b‟ this indicates one extra „b‟ than „a‟ is found.

Prepared By:Rohini Patil Page 8


Theory of computation

q5: After the last „b‟ if we get blank symbol means no more b‟s are remaining.

Transition Diagram:

Transition Table:


a b X Y B
Q

q0 (q1, X, R) - - (q3,Y, R) -

q1 (q1,a, R) (q2, Y, L) - (q1, Y, R) -

q2 (q2, a, L) - (q0, X, R) (q2, Y, L) -

q3 - (q4,B,R) - (q3, Y, R) -

q4 - - - - (q5,B,S)

q5* - - - - -

Instantaneous Description:

|-q0abbB |-Xq0YbB
|-Xq1bbB |-XYq3bB
|-Xq2YbB |-XYBq4B
|-q2XYbB |-XYBq5(Accept)

5] Design Turing machine for the language L= {(ab)n cn | n>=1}

Solution: The language becomes,

L= {abc, ababcc, abababccc, ……..}

Prepared By:Rohini Patil Page 9


Theory of computation

Logic:

1 Each „a‟ is replaced by „a‟ and head movement towards right till „b‟.

2. Whenever reading „b‟ for each „b‟ is replaced by „X‟ and head movement towards right till
„c‟ .

3. Each „c‟ is replaced by „Y‟ and head movement towards left till „X‟

4. Repeat above steps .

Implementation: LetM= (Q, ∑,┌, δ, q0,B, F)

Where, Q = {q0, q1, q2, q3,q4,q5 }


∑={a,b,c}
┌ ={a,b,c,X,Y,B}
q0=q0
B=Blank symbol
F= {q5}
Working:

q0: Replace „a‟ by „a‟ and head moves towards right

q1:.Search for „b‟ and replace it by „X‟ and head moves towards right

q2: Bypass all „a‟s ,‟b‟s and „Y‟s. Search for „c‟ and replace it by „Y‟ and head moves
towards left

q3: Search for „X‟ and replace it by „X‟only and head moves towards right whenever get „a‟
at qo state repeat the steps. Bypass all „a‟s ,‟b‟s and „Y‟s.

q4: On q0 state if we get „Y‟ replace it by „Y‟ only and head moves towards right Now,
move the head right till we get blank symbol. Bypass all Y‟s.

q5: After reading all Y‟s if we get blank symbol means that is final state.

Transition Diagram:

Transition Table:

Prepared By:Rohini Patil Page 10


Theory of computation


Q a b c X Y B

q0 (q1, a, R) - - - (q4,Y, R) -

q1 - (q2, X,R) - - - -

q2 (q2, a, R) (q2, a, R) (q3,Y,L) - (q2, Y, R) -

q3 (q3,a,L) (q3,b,L) - (q0,X,R) (q3, Y, L) -

q4 - - - - (q4, Y, R) (q5,B,S)

q5* - - - - - -

Instantaneous Description:

|-q0abcB |-q3XYB
|-aq1bcB |-Xq0YB
|-Xq2cB |-XYq4B
|-Xq3YB |-XYq5 (Accept

6] Design Turing machine for the language L={x | na(x)=nb(x)} DEC-11

Solution: The language L consist of equal no of a‟s and b‟s

L={ab, ba, abab, abba, …….}

Logic:

1. For each„a‟, replace it as „X‟ and move right till we get blank symbol.

2. After getting blank symbol move left and search for „b‟.

3. For each „b‟, replace it as „X‟ and move left till we get blank symbol.

4. Repeat above steps for remaining a‟s and b‟s.

Implementation: LetM= (Q, ∑,┌, δ, q0,B, F)

Where, Q = {q0, q1, q2, q3,q4 }


∑={a,b }
┌ ={a,b, X, B}
q0=q0
B=Blank symbol
F={q4}
Working:

Prepared By:Rohini Patil Page 11


Theory of computation

q0: Replace „a‟ by „X‟ and head moves towards right

q1: Search for blank symbol, „B ‟is replace with „and head moves towards left. While doing
this skip all a‟s, b‟s and X‟s.

q2: Search for „b‟, replace it by „X‟ and head moves towards left. While doing this skip all
a‟s and X‟s .

q3: Search for blank symbol, keep it as it is and head moves towards right.While doing this
skip all a‟s, b‟s and X‟s.

q4: On q0 state after moving right if we get blank symbol indicates that all a‟s are over. So
move left to check any „b‟ is remaining or not. Skip all X‟s.

q5 : After reading all X‟s if we get blank symbol means that is final state.

Transition Diagram:

Transition Table:


a b X B
Q
q0 (q1, X, R) (q0, b, R) (q0 ,X, R) (q4 ,B ,S)

q1 (q1, a, R) (q1, b, R) (q1, X ,R) (q2 ,B, L)

q2 (q2, a, L) (q3, X, L) (q2, X, L) -

q3 (q3 ,a, L) (q3, b, L) (q3, X, L) (q0, B, R)

q4* - - - -

Instantaneous Description:

Prepared By:Rohini Patil Page 12


Theory of computation

q0abbaB |-Xq3bXaB |-Xq2bXXB


|-Xq1bbaB |-q3XbXaB |-Xq3XXXB
|-Xbq1baB |-Xq0bXaB |-q3XXXXB
|-Xbbq1aB |-Xbq0XaB |-Xq0XXXB
|-Xbbaq2B |-XbXq0aB |-XXq0XXB
|-Xbbq2aB |-XbXXq1B |-XXXq0XB
|-Xbq2baB |-XbXXq2B |-XXXXq0B
|-Xbq3XaB |-XbXq2XB |-XXXXq4
|-Xbq2XXB

7]Design Turing machine for the language L={x | na(x)>nb(x)}

Solution: The language L consist of no of a‟s greater than no of b‟s.

L={aba,aab, aabab, ababa…….}

Logic:

1. For each „a‟, replace it as „X‟ and move right till we get blank symbol.

2. After getting blank symbol move left and search for „b‟.

3. For each „b‟, replace it as „X‟ and move left till we get blank symbol.

4. Repeat above steps for remaining a‟s and b‟s.

Implementation: LetM= (Q, ∑,┌, δ, q0,B, F)

Where, Q = {q0, q1, q2, q3,q5}


∑={a,b }
┌ ={a,b, X, B}
q0=q0
B=Blank symbol
F={q5}
Working:

q0: Replace „a‟ by „X‟ and head moves towards right

q1: Search for blank symbol, „B ‟is replace with „and head moves towards left. While doing
this skip all a‟s, b‟s and X‟s.

q2: Search for „b‟, replace it by „X‟ and head moves towards left. While doing this skip all
a‟s and X‟s .

Prepared By:Rohini Patil Page 13


Theory of computation

q3: Search for blank symbol, keep it as it is and head moves towards right.While doing this
skip all a‟s, b‟s and X‟s.

q5: On q2 state if we read one more a‟s meaning is that no of a‟a greater than b‟s means that
is final state.

Transition Diagram:

Transition Table:


Q a b X B

q0 (q1, X, R) (q0, b, R) (q0 ,X, R) -

q1 (q1, a, R) (q1, b, R) (q1, X ,R) (q2 ,B, L)

q2 (q2, a, L) (q3, X, L) (q2, X, L) (q5, B, S)

q3 (q3 ,a, L) (q3, b, L) (q3, X, L) (q0, B, R)

q5 * - - - -

Instantaneous Description:

|-q0aabB |-Xq3aXB
|-Xq1abB |-q3XaXB
|-Xaq1bB |-Xq0aXB
|-Xabq1B |-XXq1XB
|-Xaq2bB |-XXXq1B
|-Xaq3XB |-XXXq2B
|-XXXq5

Prepared By:Rohini Patil Page 14


Theory of computation

8] Design TM for the language of odd length palindrome over ∑={0,1} i.e WCWR

Solution: The language L consists of all odd length palindrome strings. May-14 (CBGS)

L= {101, 010, 110, 10101,…………….}

Implementation: LetM= (Q, ∑,┌, δ, q0,B, F)

Where, Q = {q0, q1, q2, q3,q4,q5,q6,q7,q8}


∑={0,1 }
┌ ={1,0, X, B}
q0=q0
B=Blank symbol
F={q8}
Logic:

1. For each „0‟ or „1‟, replace it as „X‟ and move right till we get blank symbol.

2. After getting blank symbol move left. If the last character matches with the first
character then mark it as blank symbol and move left

3. Repeat above steps

Transition Diagram:

Working:

q0 : Take the first character (either „0‟ or „1‟), mark it as „X‟ and move right.

q1 & q4: Search for blank symbol, keep it as it is and then move left. While doing this skip all
0‟s, 1‟s &c‟s.

q2 & q5: On q2 & q5 if we get same symbol, mark it as ‟B‟ and move left.

q3 & q6: Bypass 0‟s,1‟s and c‟s and move left.

Prepared By:Rohini Patil Page 15


Theory of computation

q7 : On q3 and q6 states after moving left if we get „X‟ that means all symbols are over.So
move q0 state and from q0 state bypass c‟s.

Transition Table:


0 1 c X B
Q
q0 (q4, X, R) (q1, X, R) (q7, c, R) - -

q1 (q1, 0, R) (q1, 1, R) (q1, c, R) - (q2, B, L)

q2 - (q3, B, L) - - -

q3 (q3, 0, L) (q3, 1, L) (q3, c, R) (q0, X, R)

q4 (q4, 0, R) (q4, 1, R) (q4, c, R) - (q5, B, L)

q5 (q6, B, L) - - - -

q6 (q6, 0, L) (q6, 1, L) (q6, c, L) (q0, X, R) -

q7 - - - - (q8.B,S)

q8* - - - - -

Instantaneous Description:

|-q001c10B |-X1cq61BB |-XXc1q1B


|-Xq41c10B |-X1q6c1B |-XXcq21B
|-X1q4c10B |-Xq61c1B |-XXq3cBB
|-X1cq410B |-q6X1c1B |-Xq3XcB
|-X1c1q40B |Xq01c1B |-XXq0cB
|-X1c10q4B |-XXq1c1B |-XXcq7B
|-X1c1q50B |-XXcq11B |-XXcq8

9] Design Turing machine for the language of even length palindrome i.e.WWR

Solution: The language L consists of all even length palindrome strings.

L= {1001,0110, 0011, 110011,…………….}

Implementation: LetM= (Q, ∑,┌, δ, q0,B, F)

Where, Q = {q0, q1, q2, q3,q4,q5,q6,q7}


∑={0,1 }

Prepared By:Rohini Patil Page 16


Theory of computation

┌ ={1,0, X, B}
q0=q0
B=Blank symbol
F={q7}
Logic:

1. For each „0‟ or „1‟, replace it as „X‟ and move right till we get blank symbol.

2. After getting blank symbol move left. If the last character matches with the first
character then mark it as blank symbol and move left

3. Repeat above steps

Transition Diagram:

Working:

q0 : Take the first character (either „0‟ or „1‟), mark it as „X‟ and move right.

q1 & q4: Search for blank symbol, keep it as it is and then move left. While doing this skip all
0‟s, 1‟s.

q2 & q5: On q2 & q5 if we get same symbol, mark it as ‟B‟ and move left.

q3 & q6: Bypass 0‟s,1‟s and move left. After moving left if we get „X‟ replace it‟X‟ .

q7 : On q0 if we get „B‟ means that is accepted state.

Prepared By:Rohini Patil Page 17


Theory of computation

Transition Table:


0 1 X B
Q
q0 (q4, X, R) (q1, X, R) - (q7,B,S)

q1 (q1, 0, R) (q1, 1, R) - (q2, B, L)

q2 - (q3, B, L) - -

q3 (q3, 0, L) (q3, 1, L) (q0, X, R)

q4 (q4, 0, R) (q4, 1, R) - (q5, B, L)

q5 (q6, B, L) - - -

q6 (q6, 0, L) (q6, 1, L) (q0, X, R) -

q7* - - - -

Instantaneous Description:

|-q00110B |-X11q50B |-XX1q1B


|-Xq4110B |-X1q61BB |-XXq21B
|-X1q410B |-Xq611B |-Xq3XBB
|-X1q410B |-q6X11B |-XXq0B
|-X11q40B |Xq011B |-XXq7
|-X110q4B |-XXq11B

FSM TO TURING MACHINE:

10] Design Turing machine to replace the substring “111” by “101”from a sequence of
0’s and 1’s.
May-10
Solution:

Logic: The given language consists of string such that for every occurrence of 111 by 101.

Implementation: LetM= (Q, ∑,┌, δ, q0,B, F)

Where, Q = {q0, q1, q2, q3,q4,q5 }


∑={0,1 }

Prepared By:Rohini Patil Page 18


Theory of computation

┌ ={0,1, B}
q0=q0
B=Blank symbol
F={q5}
Working:

q0 : If input is „0‟ mark it as „0‟ and move right.

q1: If I/P is „0‟ on q1, mark it „0‟ and move right goto q0.Else if I/P is „1‟ mark it as „1‟ and
move right.

q2: If I/P is „0‟ on q2, mark it „0‟ and move right goto q0. Else if I/P is „1‟ mark it as „1‟ and
move left goto q3.

q3: If I/P is „1‟ on q3, mark it „0‟ and move right goto q4.

q4: If I/P is „1‟ on q4, mark it „1‟ and move right goto q0.On q0 if we get blank symbol
means that is an accepted state.

Transition Diagram:

Transition table:


Q 0 1 B

q0 (q0, 0, R) (q1, 1, R) (q5, B, S)

q1 (q0, 0, R) (q2, 1, R) (q5, B, S)

q2 (q0, 0, R) (q3, 1, L) (q5, B, S)

q3 - (q4, 0 , R) -

q4 - (q0, 1, R) -

q5 -- - -

Prepared By:Rohini Patil Page 19


Theory of computation

Instantaneous Description:

B1110B |-q01110B |-1q1110B |-11q210B |-1q3110B

|-10q410B |-101q00B |-1010q0B |-1010Bq5

11] Design Turing machine for 0(0+1)*11 DEC-10

Solution:

Logic: The given language consists of string that starts with „0‟ and ends with „11‟

L={011,0011,0111,00111……}

Implementation: LetM= (Q, ∑,┌, δ, q0,B, F)

Where, Q = {q0, q1, q2, q3,q4 }


∑={0,1 }
┌ ={0,1, B}
q0=q0
B=Blank symbol
F={q4}
Working:

q0 : If input is „0‟ mark it as „0‟ and move right.

q1: If I/P is „0‟ on q1, bypass „0‟ else if I/P is „1‟ mark it as „1‟ and move right.

q2: If I/P is „0‟ on q2, mark it „0‟ and move right goto q1. If I/P is „1‟ mark it as „1‟ and move
right goto q3.

q3: If I/P is „0‟ on q3, mark it „0‟ and move right goto q1. Bypass „1‟if we get blank symbol
means that is an accepted State q4.

Transition Diagram:

Transition table:

Prepared By:Rohini Patil Page 20


Theory of computation


Q 0 1 B

q0 (q1, 0, R) - -

q1 (q1, 0, R) (q2, 1, R) -

q2 (q1, 0, R) (q3, 1, L) -

q3 (q1, 0, R) (q2, 1, R) (q4, B, S)

q4* - - -

Instantaneous Description:

|-q000111B |-0q10111B |-00q1111B |-001q211B

|-0011q31B |-00111q3B |-00111q4

Note: Unary Representation


1 -> 0
2 -> 00

12] Design Turing machine to perform addition of two unary numbers. i.e m+n

I/P = B0m10nB DEC-14,

May-11
O/P = B0pB where p=m+n

Solution: Let us use the symbol “0” to represent the unary numbers. here we will use symbol
“1” as a separator.
Consider input is 3+2 so the content becomes

I/P B 0 0 0 1 0 0 B

O/P B 0 0 0 0 0 B B

Logic:
1. Bypass all 0‟s and head moves towards right to search for „1‟.
2. When we get the „1‟, replace it with „0‟ and moves towards right till blank symbol.
3. After reaching to blank symbol moves towards left and replace the last „0‟ as „B‟.

Implementation: LetM= (Q, ∑,┌, δ, q0,B, F)

Where, Q = {q0, q1, q2, q3 }

Prepared By:Rohini Patil Page 21


Theory of computation

∑={0,1}
┌ ={0,1, B}
q0=q0
B=Blank symbol
F={q3}
Working:

q0 : Replace the „0‟of by „0‟.on getting „1‟ replace it by „0‟ and move right.

q1: Search for „B‟, and replace „B‟ with „B‟ and moves towards left. Bypass all 0‟s.

q2: Replace the rightmost „0‟ of second number by „B‟.

q3: On q2 we get „B‟ means that is final state.

Transition Diagram:

Transition Table:


0 1 B
Q
q0 (q0, 0, R) (q1, 0, R) -

q1 (q1, 0, R) - (q2, B, L)
q2 (q3, B, S) - -

q3* - - -

Instantaneous Description: consider 2+1

|-B0010B |-000q10B
|-q00010B |-0000q1B
|-0q0010B |-000q20B
|-00q010B |-000Bq3

13] Design Turing machine to perform subtraction of two unary numbers. i.e m-n
defined as, m-n if m>n

Prepared By:Rohini Patil Page 22


Theory of computation

0 if m<=n

I/P = B0m10nB

O/P = B0pB where p=m-n

Solution: Here 3 cases are, m>n, m=n and m<n. Consider input becomes,

3-2 2-2 2-3


B000100B B00100B B001000B
B00100B B0100B B01000B
B0010B B010B B0100B
B010B B10B B100B
B01B B1B B10B
B1 B q0 q0
0 q2

Logic:

1. For first „0‟, replace it with „B‟ and move right till Blank symbol.

2. On receiving Blank symbol as „B‟ move left and replace the rightmost „0‟as „B‟.

3. Move left till blank symbol and repeat above steps.

Implementation: LetM= (Q, ∑,┌, δ, q0,B, F)

Where, Q = {q0, q1, q2, q3,q4,q5 }


∑={0,1}
┌ ={0,1, B}
q0=q0
B=Blank symbol
F={q5}
Working:

q0 : Replace the leftmost „0‟of first number by „B‟ and move right.

q1: Search for „B‟, and replace „B‟ with „B‟ and moves towards left. Bypass all 0‟s and 1‟s.

q2: Replace the rightmost „0‟ of second number by „B‟ and move left.

If we get „1‟ on this state then it indicates that all 0‟s of second number are over so second
number is smaller than first number. Now, replace the „1‟ by „0‟ and move to final state.

Prepared By:Rohini Patil Page 23


Theory of computation

q3: Search for „B‟ and replace „B‟ with „B‟. and moves towards right and go to q0 state to
repeat the cycle. Bypass all 0‟s and 1‟s.

q4: On q0 state after moving right if we get „1‟ that means all 0‟s of first number are over.
Replace the „1‟ by „B‟. Now, move right to check, whether any „0‟ of second number is
remaining. If not then this means that both numbers are equal, so move to final state.

If any „0‟ is found then this indicates that first number is smaller than the second
number. Replace all remaining 0‟s by „B‟and move to final state.

Transition Diagram:

Transition Table:


0 1 B
Q
q0 (q0, B, R) (q4, B, R) -

q1 (q1, 0, R) (q1, 1, R) (q2, B, L)

q2 (q3, B, L) (q5, 0, S) -

q3 (q3, 0, L) (q3, 1, L) (q0, B, R)

q4 (q4, B, R) - (q5, B, S)

q5 - - -

Instantaneous Description: consider m=2,n=1 i.e. 2-1=1

Prepared By:Rohini Patil Page 24


Theory of computation

|-0010B |-B0q31B
|-q00010B |-Bq301B
|-B q1010B |-q3B01B
|-B0q110B |-Bq001B
|-B01q10B |-BBq11B
|-B010q1B |-BB1q1B
|-B01q20B |-Bq21B
|-B0q5

14] Design Turing machine to compare two unary numbers according to following
criteria. If m=n then output is E
DEC-13
If m>n then output is G
If m<n then output is L

I/P = B0m10nB

O/P = BpB where p=E/G/L

Solution: Here 3 cases are, m>n, m=n and m<n logic is similar only the output on tape
will be E, L, or G.

3>2 2=2 2<3

B000100B B00100B B001000B

B00100B B0100B B01000B

B0010B B010B B0100B

B010B B10B B100B

B01B B1B B10B

B1 B q0 BBq0

B q2

Logic:

1. For first „0‟, replace it with „B‟ and move right till Blank symbol.

2. On receiving Blank symbol as „B‟ move left and replace the rightmost „0‟as „B‟ and move
left till blank symbol

Prepared By:Rohini Patil Page 25


Theory of computation

3. Repeat above steps. If we get „1‟ mark it as‟B‟.

Implementation: LetM= (Q, ∑,┌, δ, q0,B, F)

Where, Q = {q0, q1, q2, q3,q4,q5,q6,q7 }


∑={0,1}
┌ ={0,1, B}
q0=q0
B=Blank symbol
F={q7}
Working:

q0 : Replace the leftmost „0‟of first number by „B‟ and move right.
q1: Search for „B‟, and replace „B‟ with „B‟ and moves towards left. Bypass all 0‟s and 1‟s.
q2: Replace the rightmost „0‟ of second number by „B‟ and move left.
If we get „1‟ on this state then it indicates that all 0‟s of second number are over so first
number is greater than second number. Now, replace the „1‟ by „B‟ and move left.
q3: Search for „B‟ and replace „B‟ with „B‟. and moves towards right and go to q0 state to
repeat the cycle. Bypass all 0‟s and 1‟s.
q4: On q0 state after moving right if we get „1‟ Replace that „1‟ by „B‟. If any „0‟ is found
replace „0‟ by „B‟ and moves right. If not that means that both numbers are equal, so move
to final state.
q5: Replace „0‟ by „B‟ and moves right. If any „0‟ is found then this indicates that first
number is smaller than the second number.
q6: Replace „0‟s by „B‟and move left.

Transition Diagram:

Prepared By:Rohini Patil Page 26


Theory of computation

Transition table:

0 1 B
Q
q0 (q1,B,R) (q4,B,R) -

q1 (q1,0,R) (q1,1,R) (q2,B,L)

q2 (q3,B,L) (q6,B,L) -

q3 (q3,0,L) (q3,1,L) (q0,B,R)

q4 (q5,B,R) - (q7,E,S)

q5 (q5,B,R) - (q7,L,S)

q6 (q6,B,L) - (q7,G,S)

q7* - - -

Instantaneous Description: Consider I/P 1=1

|-010B |- Bq31B
|-q0010B |-q3B1B
|-Bq110B |-Bq01B
|-B1q10B |-BBq4B
|-B10q1B |-BBq7
|-B1q20B

15] Design Turing machine to find 1’s complement of Binary number.

Solution:

Logic:

1. Each „0‟ replace with‟1‟ and „1‟ is replace with‟0‟.


2. Repeat the above steps.

Implementation: LetM= (Q, ∑,┌, δ, q0,B, F)

Where, Q = {q0, q1 }
∑={0,1}
┌ ={0,1, B}
q0=q0
B=Blank symbol

Prepared By:Rohini Patil Page 27


Theory of computation

F={q1}
Working:

q0 : Replace the „0‟with‟1‟ and „1‟with‟0‟ and move right. Search for „B‟, and replace „B‟
with „B‟ and moves towards left.

q1: On q0 state after reading all 0‟s and 1,s if we get blank symbol means that is final state.

Transition diagram:

Transition table:


0 1 B
Q
q0 (q0, 1, R) (q0, 0, R) (q1, B, L)

q1* - - -

Instantaneous Description:

B101B

|-q0101B |-0q001B |-01q01B |-010q0B |-010q1

16] Design Turing machine to find 2’s complement of Binary number.

Solution:

Logic:

1. Each rightmost „0‟ replace with‟0‟ and „1‟ is replace with‟1‟.


2. Before trailing „1‟if „0‟is there replace that with „1‟
3. Before trailing „1‟if „1‟is there replace that with „0‟
4. Repeat the above steps.

Implementation: LetM= (Q, ∑,┌, δ, q0,B, F)

Where, Q = {q0, q1,q2,q3 }


∑={0,1}
┌ ={0,1, B}

Prepared By:Rohini Patil Page 28


Theory of computation

q0=q0
B=Blank symbol
F={q3}
Working:

q0 : Replace the „0‟with‟0‟ and „1‟with‟1‟ and move right. Search for „B‟, and replace „B‟
with „B‟ and moves towards left.

q1: Replace „0‟with‟0‟ and „1‟with‟1‟ move towards left. Search for „B‟, and replace „B‟ with
„B‟ and moves towards right.

q2: Replace „0‟with‟1‟ and „1‟with‟0‟ move towards left. Search for „B‟, and replace „B‟ with
„B‟ and moves towards right.

q3: On q2 we get „B‟ means that is final state.

Transition diagram:

Transition table:


0 1 B
Q
q0 (q0, 0, R) (q0, 1, R) (q1, B, L)

q1 (q1, 0, L) (q2, 1, L) (q3, B, R)

q2 (q2, 1, L) (q2, 0, L) (q3, B, R)

q3* - - -

Instantaneous Description:

Prepared By:Rohini Patil Page 29


Theory of computation

|-B101B |-10q21
|-q0101B |-1q201
|-1q001B |-q2111
|-10q01B |-q2B011
|-101q0B |-Bq3011
|-10q1 1

17] Design Turing machine to Increment Binary number by 1.

Logic:

1. Each trailing „1‟ replace with‟0‟.


2. First rightmost „0‟ replace with‟1‟.
3. Remaining bits will as it is

Implementation: LetM= (Q, ∑,┌, δ, q0,B, F)

Where, Q = {q0, q1,q2 }


∑={0,1}
┌ ={0,1, B}
q0=q0
B=Blank symbol
F={q2}
Working:

q0 : Replace the „0‟with‟0‟ and „1‟with‟1‟ and move right. Search for „B‟, and replace „B‟
with „B‟ and moves towards left.

q1: Trailing 1‟s are replace with‟0‟ move towards left. Search for „B‟, and „0‟ from rightmost
end and replace with „1‟ .

q2: On q2 we get „B‟ means that is final state.

Transition Diagram:

Prepared By:Rohini Patil Page 30


Theory of computation

Transition table:


0 1 B
Q
q0 (q0, 0, R) (q0, 1, R) (q1, B, L)

q1 (q2, 1, S) (q1, 0, L) (q2, 1, S)

q2* - - -

Instantaneous Description:

|-B11B |-q011B |-1q01B |-11q0B |-10q1 B

|-1q10 |-11q2

18] Design Turing machine to Decrement Binary number by 1.

Logic:

1. Each trailing „0‟ replace with‟1‟.


2. First rightmost „1‟ replace with‟0‟.
3. Remaining bits will as it is

Implementation: LetM= (Q, ∑,┌, δ, q0,B, F)

Where, Q = {q0, q1,q2 }


∑={0,1}
┌ ={0,1, B}
q0=q0
B=Blank symbol
F={q2}
Working:

q0 : Replace the „0‟with‟0‟ and „1‟with‟1‟ and move right. Search for „B‟, and replace „B‟
with „B‟ and moves towards left.

q1: Trailing 0‟s are replace with‟1‟ move towards left. Search for „1‟, from rightmost end and
replace with „0‟ .keep Blank symbol as it is.

q2: On q2 we get „B‟ means that is final state.

Transition Diagram:

Prepared By:Rohini Patil Page 31


Theory of computation

Transition table:


0 1 B
Q
q0 (q0, 0, R) (q0, 1, R) (q1, B, L)

q1 (q1, 1, L) (q2, 0, S) (q2, B, S)

q2* - - -

Instantaneous Description:

|-B11B |-q011B |-1q01B |-11q0B |-10q1 B

|-1q10 |-1q11 |-10q2

19] Design Turing machine to perform multiplication of two unary numbers. i.e m*n

I/P = B0m10nB

O/P = B0pB where p=m*n

Solution:

Logic:

Multiplication means repetitive addition. In order to multiply two numbers, for each „0‟ of
first number all 0‟s of second number are copied after the second „#‟ symbol. here # is is a
separator.

Example: 2*2

Initially: B 0 0 # 0 0 # B

B X 0 # 0 0 # 0 0 B
Iteration1
1X2=2

Prepared By:Rohini Patil Page 32


Theory of computation

Iteration2 B X X # 0 0 # 0 0 0 0 B
2x2=4
Implementation: LetM= (Q, ∑,┌, δ, q0,B, F)

Where, Q = {q0, q1,q2,q3,q4,q5,q6 }


∑={0,1}
┌ ={0,1,X,#, B}
q0=q0
B=Blank symbol
F={q6}
Working:

q0 : Replace the leftmost „0‟ of first number by „X‟ and move right.

q1: Search for „#‟, keep it as it is and move right. While doing this bypass all 0‟s.

q2: Replace the leftmost „0‟ of second number by „X‟ and move right. On q2 state after
moving right if we get „#‟ that means all 0‟s of second number are over. Now, keep „#‟ as it is
and move left to repeat the same cycle for the next „0‟ of first number.

q3: Search for „B‟, replace it by „0‟ and move left. While doing this bypass all 0‟s and „#”.

q4: Search for „X‟, replace it by „0‟ and move right. Go to q2. While doing this bypass all 0‟s
and „#”.

q5: Search for „X‟, replace it by „0‟ and move right. Go to q0. While doing this bypass all 0‟s
and „#”.

q6: On q0 state after moving right if we get „#‟ that means all 0‟s of first number are over.
Now, keep „#‟ as it is go to the final state.

Transition Diagram:

Transition Table:

Prepared By:Rohini Patil Page 33


Theory of computation


0 # X B
Q
q0 (q1,X,R) (q6,#,S) - -

q1 (q1,0,R) (q2,#,R) - -

q2 (q3,X,R) (q5,#,L) - -

q3 (q3,0,R) (q3,#,R) - (q4,0,L)

q4 (q4,0,L) (q4,#,L) (q2,0,R) -

q5 (q5,0,L) (q5,#,L) (q0,0,R) -

q6* - - - -

Instantaneous Description:

B0#00#B |-BX#Xq40#0B |-BX#0q4X#00


|-q00#00#B |-BX#q4X0#0B |-BX#00q2#00
|-BXq1#00#B |-BX#0q20#0B |-BX#00q5#00
|-BX#q200#B |-BX#0Xq3#0B |-BX#0q50#00
|-BX#Xq30#B |-BX#0X#q30B |-BX#q500#00
|-BX#X0q3#B |-BX#0X#0q3B |-BXq5#00#00
|-BX#X0#q3B |-BX#0X#0q40 |-Bq5X#00#00
|-BX#X0#q40B |-BX#0X#q400 |-B0q0#00#00
|-BX#X0q4#0B |-BX#0Xq4#00 |-B0#q6

Variations of Turing machine :

In order to enhance of power of Turing machine TM has many variations. All these variations
are equivalent to the basic Turing machine with respect to the computing function but, they
may add some sort of extra power to it.

Some of the variations are listed below:

1. Two-way infinite tape Turing machine


2. Multi-Head Turing machine
3. Multi-Tape Turing machine
4. Multidimensional Turing machine
5. Non-deterministic Turing machine

Prepared By:Rohini Patil Page 34


Theory of computation

1] Two-way infinite tape Turing machine:

In standard Turing machine the left end is bounded. In case of Two-way infinite tape Turing
machine the input tape is infinite on both left and right side. There exists infinite continuous
sequence of blank symbols on each of the left-hand and right-hand of the sequences of non-
blanks.

It is possible to move left as possible as required. Regardless of this, the new model doesn‟t
add any extra computational capability to the standard Turing machine.

2] Multi-Head Turing machine:

A Multi head Turing machine can be defined as a Turing machine with a single tape and a
single finite state control but with multiple independent R/W heads.The transition function of
this Multi-head Turing machine can be described as follows:

δ: Q x ┌ Tq x ┌T x {L,R}n

where ┌T =┌ x ┌ x┌ x┌…… and n no of R/W heads.

3] Multi-Tape Turing machine:

This type of Turing machine consists of multiple tapes each having an independent head.
Each head is capable to perform read/ write operations and the movement includes left or
right or no movement. Thus this type of TM is controlled by its own independent R/W head.
There are certain computations like reversing, verification of palindrome string, copying etc.
which can be done more easily with the mutilate Turing machine as compared to standard
Turing machine.

Example: Consider the language L={an bn |n>=1}

In normal TM, head has to move back and forth to match each pair of symbols a and b.On a
multitape TM ,no such movements are needed.

Consider the Turing machine with two tapes and two independent heads. Let I/P =aabb

4] Multi dimensional Turing machine:

A Turing machine is said to be multi-dimensional Turing machine if its tapes can be viewed
as extending infinitely in more than one dimension. This TM does not add s any extra power.
Depending upon the state and the scanned symbol, the device changes states, points new
symbol and move the head in one of the 2k directions.

Prepared By:Rohini Patil Page 35


Theory of computation

The transition function of this Multi-dimensional Turing machine can be described as


follows: δ: Q x ┌ q x ┌ x {L,R,U,D}

where U & D specify movement of R/W head in up and down directions.

5] Non-deterministic Turing machine:

The standard Turing machine is also referred as Deterministic Turing machine. But, for non-
deterministic Turing machine, it is possible that there are multiple transitions from the current
state for the current input.

The Deterministic Turing machine is a special case of non-deterministic Turing machine.


There can be more than one paths reaching to final state. The non-determinism adds
simplicity to the design of standard Turing machine. It doesn‟t enhance the power of standard
Turing machine

Example of NDTM:

Transition function is given by , δ( q0,a)= {(q0,a,R)(q1,X,R)}

Universal Turing Machine: DEC-13

A general purpose computer is able to solve all sorts of problems from all domains. There is
no need to have a separate computer for each problem. In order to solve any problem a
program or sequence of steps along with data is stored in computer‟s memory. The control
unit of computer reads one step at a time and executes it. This process is repeated till the final
result is generated.

A similar approach can be applied to Turing machine. We can construct a single Turing
machine which can solve all sorts of problems. This type of Turing machine is called as
Universal Turing Machine (UTM). Thus, Universal Turing Machine is a Turing Machine
which simulates the behavior of digital computer or any Turing Machine for a given input.

Consider that Universal Turing Machine P is designed to simulate any Turing Machine M.
The input of this Universal Turing Machine consists of:

 Description of transitions of machine M


 Input string of machine M

Universal Turing Machine consists of three different tapes to store all its input. As shown in
figure , the Tape 1 stores description of any other Turing machine M , Tape 2 stores input
string of machine M and Tape 3 stores the states of machine M.

Prepared By:Rohini Patil Page 36


Theory of computation

To store information on tapes of Universal Turing machine uses an encoding process We


encode machine M as a string of symbols. In this encoding process binary numbers are used
to represent the transitions of machine M.

The encoding process is as follows:

 Symbol Encoding: Here one assumption is made that the alphabet always consists of
symbols like {a ,b,c,d,……}. These symbols are encoded as shown below
Symbol „a‟ is encoded as „1', symbol „b‟ as „11‟, symbol „c‟ as „111‟ and so on.

 State Encoding: Here the assumption is all states are always numbered as q1, q2, q3,q4
…. where q1 is initial state and q2 will be always a final state. The encoding scheme
for states is as shown in below

 Move Encoding: The possible moves for the head of Turing machine are left move
and right move. These are encoded as shown in below

 Transition Encoding: The entire transition is encoded using the above discussed
scheme is shown in figure

Prepared By:Rohini Patil Page 37


Theory of computation

Thus, all transitions of machine M are encoded as a binary string and the multiple transitions
are separated by two 0‟s. For example the two transitions: δ(q1 , a) =( q2 , b, L) and
δ(q2 , b) =( q3 , c, R) are stored in the form of binary sequence as shown in figure

Working of Universal Turing Machine:

1] Scan the cell on the state area of the tape and read the symbol from the same area that
reads to start called initial state.
2] Move the tape to the program which contains finite automation table ,find the row which is
headed by the symbol scanned in the previous state.
3] Find the required column.
4] Move the tape to the appropriate square, Replace the symbol ,move the tape ,read the next
symbol, Reach the state area and replace the state by the current state and Repeat the above
steps.

Power of TM over FSM:

1] TM is more powerful than FA

2] TM has memory in the form of tape while FA does not have memory.

3] TM can modify its own input while FA cannot modify its input.

4] TM can perform arithmetic operation while FA cannot used for arithmetic operation.

5]TM can handles all languages like Recursive language ,CSL,CFL,RL while FA can
handles only RL.

Application of Turing Machine:

Turing Machine is used in various ways like,

1] Language Recognition- for recognition ofpalindrome

2] Language generation

3] Computation of some function like addition, multiplication subtraction and division

Prepared By:Rohini Patil Page 38


Theory of computation

May-2014(CBGS)
1 Design TM that recognizes palindrome strings where ∑={0,1} 10
2 Write Short note on variants of TM 05
Dec-2014(CBGS)
1 Design TM to add two binary numbers,and simulate”110+10” 10
2 Design TM as an acceptor for the language L={anbm| m>=0and m>=n} 10
May-2014
1 Design TM for the language L={anbn| n>=1 } 10
Dec-2014
1 Design TM for the language L={0n1n| n>=1 } 10
2 Design TM to find the value of log2n where n is unary number 10
May-13
1 Design TM for the language L={anbn| n>=1 } 10
DEC-13
1 Design TM for the language L={anbn| n>=1 } 10
2 Design Turing machine to compare two unary numbers according to 10
following criteria. If m=n then output is E,If m>n then output is G
If m<n then output is L.
3 Write Short note on Universal Turing Machine 05
May-12
1 Explain different techniques for turing machine 05
2 Design TM for “set of all strings of balanced parenthesis” 10
3 Write Short note on Universal Turing Machine 05
DEC-12
1 What is TM. Give power of TM over FSM .Explain undecidability and 10
incompleteness of TM.
2 Write Short note on Universal Turing Machine 05
May-11
1 Design TM for the language L={anbn| n>=1 } 10
2 Design TM for addition of two unary numbers 10
DEC-11
1 Design TM for the language L={anbn cn| n>=1 } 10
L={X |na(x)=nb(X)}
2 Write Short note on Universal Turing Machine 05
May-10
1 Design Turing machine to replace the substring “111” by “101”from a 10
sequence of 0‟s and 1‟s.
2 Write Short note on Universal Turing Machine 05
DEC-10
1 Design TM for the regular expression 0(0+1)*11 10
2 Write Short note on variants of TM 05

Prepared By:Rohini Patil Page 39

You might also like