Unit-5
Turing Machine
Topics to be covered
• What is Turing Machine?
• Formal Definition: Turing Machine
• Design of Turing Machine
• Universal Turing Machine
• Church Turing Thesis
Introduction
Finite Automata Pushdown Automata Turing Machine
• Input Strings • Input Strings • Input Strings
a b a a
• Stack • Tape
• Special symbol
Stack Accept
I/p
Control | Reject • Control portion
Δ a b a a b Δ
Tape
Stack Head
FA Recursively enumerable language
Context free language
Regular language
Turing Machine
Δ b a a
b b a Δ
Head
• The tape is capable of performing following three operations:
• Read a symbol above the tape head.
• Modify/Update a symbol above the tape head.
• Shifting either to previous square or next square.
Turing Machine
𝑞2 𝑞3
𝑞1 𝑞4 Δ b a a b a Δ
Head
𝑞5 𝑞6
Tape
Control portion
Turing Machine = Control portion + Tape
Turing Machine
Operation to be performed by TM:
• Read a symbol above the tape head.
• Modify/Update a symbol above the tape head.
• Shifting either to previous square or next square.
Δ b a a
b b a Δ
Head
Some other Ex:
Update b | a, L
Read Shift (L or R or S) a | Δ, R
a | b, R
𝑞0 𝑞1 a | a, R
a | A, S
Definition: Turing Machine
• A Turing machine is a 5-tuple where,
is a finite set of states, assumed not to contain ha
(Acceptance State) and hr (Rejection State).
: input Symbols
tape alphabets
: is initial state, is an element of Q.
: is a transition function.
Turing Machine Accepting
Design a Turing Machine Accepting
L = {ab*a}
Tape
a
A b a
A
Strings accepting in given L are:
aa Δ B Δ
aba
abba
abbba
Δ A
a B
b b
B a
A Δ
Logic:
1. Read ‘a’, replace ‘a’ by ‘A’ (aA)
2. Read all ‘b’ one by one & replace it by ‘B’ (bB)
Δ A
a a Δ
A
if no ‘b’ found: SKIP step 2
3. Read ‘a’, replace ‘a’ by ‘A’ (aA)
Design a Turing Machine Accepting
Tape
Δ a
A b
B a
A Δ
h𝑟
b|B,R a|A,R
b|B,R b|B,R
𝑞0 Δ|Δ,R
𝑞1 a|A,R
𝑞2 a|A,R
𝑞3 Δ|Δ,S
h𝑎
Control portion
Turing Machine Accepting
Design a Turing Machine Accepting
L = {anbn}
Tape
Strings accepting in given L are:
ab Δ a
A a
A b
B b
B Δ
aabb
aaabbb
Logic:
A a
a A Aa Bb B
b b
1. Read ‘a’, replace ‘a’ by ‘A’ (aA)
2. Move RIGHT to first ‘b’ Δ B Δ
if none : REJECT
3. Replace ‘b’ by ‘B’ (bB)
4. Move LEFT to leftmost ‘a’
5. Repeat the above steps until no more a’s
6. Make sure no more b’s remain.
Design a Turing machine for accepting
Δ A
a Aa b
B b
B Δ
B/B,R B/B,L
a/a,R a/a,L
a/A,R
𝑞0 Δ/Δ,R
𝑞1 𝑞2 b/B,L
𝑞3
B/B,R
A/A,R
𝑞4
B/B,R
Δ/Δ,S
h𝑎
Turing Machine Accepting
Design a Turing machine for accepting
a/a,R b/b,R C/C,L
B/B,R C/C,R a/a,L
Δ A a b
a A B C
B b c Δ
c C
𝑞2 b/B,R
𝑞3 c/C,L
𝑞4 b/b,L
B/B,L
a/A,R A/A,R
𝑞0 Δ/Δ,R
𝑞1 Δ/Δ,S
B/B,R h𝑎
𝑞5 C/C,R Δ/Δ,S
B/B,R
𝑞6
C/C,R
Turing Machine Accepting
Design a TM for accepting Palindrome strings of even & odd length.
L = Palindrome string
Tape
Strings accepting in given L are:
aa Δ a
Δ b
Δ b
Δ a
Δ Δ
bab Even Length
abba
babab
Δ a Δ
Δ Δ
b b Δ b Δ
a Δ
Logic: Odd Length
1. Read leftmost symbol , replace it with Δ
2. Keep moving to the right until the rightmost symbol,
If matched with leftmost symbol then replace it with Δ
Otherwise : REJECT the String
3. Repeat the above steps until no more symbol left in string.
Design a TM for accepting Palindrome strings of even &
odd length.
a/a,R
a b b a
b/b,R Δ/Δ,R (odd pal)
Δ Δ Δ Δ Δ Δ
𝑞2 Δ/Δ,L
𝑞3 a/a,L
b/b,L
a/Δ,R a/Δ,L
𝑞0 Δ/Δ,R
𝑞1 Δ/Δ,R
𝑞4 h𝑎
b/Δ,R b/Δ,L
Δ/Δ,L Δ/Δ,R
𝑞5 𝑞6 (odd pal)
a/a,R
b/b,R
Δ/Δ,R (even pal)
String Tracing
├ (q0,△ a a)
├ (q1,△ a a)
├ (q2,△ △ a )
├ (q2,△ △ a
△ ) 3,△ △ a )
├ (q
├ (q4,△ △ )
├ (q1,△ △ △)
├ (ha, △ △ △
△)
Accept
Exercise
1. aba
2. abab
TM Accepting same no of 0’s and 1’s
Design a TM for accepting same no of 0’s and 1’s
L = Same no. of 0’s and 1’s
1
Strings accepting in given L are: x
Δ 0x x0 1x Δ
01
10
0101 Δ 0x 1
x 1
x 0x 0x 1
x Δ
1100
100011
Logic:
1. Move right, Read first leftmost 0, replace 0 with X (0X)
2. Keep moving to the left until you encounter Δ
3. Move right, Read first leftmost 1, replace 1 with X (1X)
4. Keep moving to the left until you encounter Δ
5. Repeat the above steps until no more 0’s and 1’s left in string.
Design a TM for accepting same no of 0’s and 1’s
Δ 1X 0
X 0X 1
X Δ
1/1,R x/x,L x/x,R x/x,L
x/x,R 1/1,L 0/0,R 0/0,L
Δ/Δ,R
𝑞0 𝑞1 0/x,L
𝑞2 Δ/Δ,R
𝑞3 1/x,L
𝑞4
Δ/Δ,L
Δ/Δ,R
𝑞5 Δ/Δ,S
h𝑎
x/x,L
TM Accepting same no of a’s, b’s & c’s
Design a TM for Accepting
X Xa c
Δ b X cX Xa b
X Δ
x/x,R x/x,L x/x,R x/x,L x/x,R x/x,L
b/b,R b/b,L a/a,R a/a,L b/b,R b/b,L
c/c,R c/c,L c/c,R c/c,L a/a,R a/a,L
𝑞0 Δ/Δ,R
𝑞1 a/x,L
𝑞2 Δ/Δ,R
𝑞3 b/x,L
𝑞4 Δ/Δ,R
𝑞5 c/x,L
𝑞6
Δ/Δ,L Δ/Δ,R
𝑞7 Δ/Δ,S
h𝑎
x/x,L
Turing machine to delete a symbol
Design a Turing machine to delete a symbol
ΔaabΔ
Δ a Δ
b a b Δ
Logic:
1. Replace the symbol you want to delete by Δ.
2. Keep moving to the Right until you encounter Δ.
3. One by one Keep shifting every symbol one step to left until you encounter Δ.
Design a Turing machine to delete a symbol
a Δa
b b
a/a,L
Δ ab Δ Δ
a/a,R 𝑞3
b/b,R
a/Δ,R a/Δ,L Δ/a,S
Δ/Δ,R
b/Δ,R
𝑞0 𝑞1 Δ/Δ,L
𝑞2 b/a,L a/b,L h𝑎
b/Δ,L Δ/b,S
Δ/Δ,S 𝑞4
b/b,L
Turing machine to copy a string
Design a Turing machine to copy a string
aa a b
String:
Δ A bB Δ Δ Δ Δ
Δ ab Δ ab
Original Pasted
Δ bab Δ bab
Δ a
A bB b
B a
A
a Δ a
Δ b
Δ b Δa Δ
Δ
Original Pasted
Design a Turing machine to copy a string
a/a,R a/a,R
b/b,R
aa b a Δb
b/b,R
Δ A B Δ Δ Δ
𝑞2 Δ/Δ,R
𝑞3 a/a,L
Δ/a,L a/a,L b/b,L
b/b,L
a/A,R
𝑞0 Δ/Δ,R
𝑞1 𝑞4 Δ/Δ,L
𝑞5
Δ/Δ,L b/B,R
Δ/b,L
h𝑎 Δ/Δ,S
𝑞8 𝑞6 Δ/Δ,R
𝑞7 a/a,R
a/a,R b/b,R
b/b,R A/A,R
A/a,L
B/b,L B/B,R
Design a TM for Accepting {SS | S ∈ {a,b}*}
Steps:
• Find middle point of the string and convert the string in to the
uppercase.
• Convert first part of the string to lowercase.
• Compare first part and second part.
ss.pptx (click here)
Universal Turing Machine
Universal Turing machine
The language
is Turing Recognizable
• Question : Given the description of a Turing Machine and some
input string, can we decide the machine accepts it?
• Answer: Just Run the TM on the input.
• Possible results:
1. M accepts w: will halt and accept
2. M rejects w: will halt and reject
3. M loops on w: will not halt
Input & Action on Universal Turing machine
Input:
1. M=description of TM
2. w=input string for M
Action:
3. simulate M
4. Behave just like M (May accept, reject or loop)
The UTM is recognizer for
Church Turing Thesis
Church Turing Thesis
• What does computable mean?
• Meaning of term Computable was given by:
1. Alonzo church (Lambda calculus)
2. Allen Turing (Turing Machine)
• Any algorithmic procedure that can be carried out at all, by a
human computer or a team of humans or an electronic computer,
can be carried out by a TM. This statement usually referred to as
Church’s thesis, or the Church-Turing thesis.
Church Turing Thesis
• Here is an informal summary of some of the evidence.
1. Humans normally work with a two-dimensional sheet of paper. A TM tape
could be organized so as to simulate two dimensions; one likely
consequence would be that the TM would require more moves to do what
a human could do in one.
2. Various enhancements of the TM model have been suggested to make the
operation more like that of a human computer, or more convenient &
efficient. The multitape TM is an example.
3. Other theoretical models includes abstract machines with two stacks or
with a queue.
4. Since the introduction of the Turing machine, no one has suggested any
type of computation that ought to be included in the category of
“algorithmic procedure” and cannot be implemented on a TM.
End of Unit-5