Unit-5 Turing Machine
Unit-5 Turing Machine
Theory of Computation
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
Head
𝑞2 𝑞3
𝑞1 𝑞4 Δ b a a b a Δ
Head
𝑞5 𝑞6
Tape
Control portion
Δ 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 Δ
Δ/Δ,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 Δ
𝑞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
Universal Turing Machine
Universal Turing machine
UTM works as a digital computer
Power of digital computer = power of TM
Finite Control
Read Write Head
Fig.: Multi-tape TM
33
Universal Turing machine
The language
is Turing Recognizable
• “Every computation that can be carried out in the real world can
be effectively performed by a Turing Machine.” This statement
usually referred to as Church’s thesis, or the Church-Turing thesis.
The recursive functions can be computable after taking following
assumptions:
• Each and every function must be computable.
• Let ‘F’ be the computable function and after performing some
elementary operations to ‘F’, it will transform a new function
‘G’ then this function ‘G’ automatically becomes the
computable function.
• If any functions that follow above two assumptions must be
states as computable function.
38
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