Module 5
Module 5
March 6, 2025
Outline
1 The Turing Machine Model
Language acceptability of Turing Machine
2 Design of TM
3 Turing Computable
Turing Machine representation
Transition table representation of Turing Machine
Transition Diagram representation of Turing Machine
4 Universal TM
5 Variation of TM
6 Linear Bounded Automata
7 Context Sensitive Language
8 Church’s Machine
9 Recursive and Recursively Enumerable Language
10 Unrestricted Grammars
Turing Machine
A Turing Machine’s storage can be visualized as a single, one
dimensional array of cells, each of which can hold a single
symbol.
This array extends indefinitely in both directions.
Information can be read and changed in any order, such
storage device is called Tape.
Turing Machine has neither an input file nor any special
output mechanism, whatever input and output is required will
be done on machine’s tape.
Turing Machine
Turing Machine
The current state of the control unit and the current tape
symbol being read determines the new state of the control
unit and new tape symbol which replaces the old one and
move the head L or R.
δ(q0 , a) = (q1 , d, R)
Internal state: q0 Internal state: q1
a b c =⇒ d b c
A turing machine is said to halt whenever it reaches a
configuration for which δ is not defined.
=⇒ No transitions are defined for any final state, so the
turing machine will halt whenever it enters a final state.
Turing Machine
Turing Machine
Turing Machine
Turing Computable
Turing Computable
Example
Given two positive integers ’x’ and ’y’. Design a turing machine
that computes x+y
Solution: Using Unary notation in which any positive integer ’x’ is
represented by w(x) ∈ {1}+ such that |w(x)|=x.
So, the required machine is: q0 w (x)0w (y ) ⊢ ∗qf w (x + y )0
Steps: Move the separating 0 to right end of w(y)
Let M=(Q,Σ, τ, q0 , □, F )
Q={q0 , q1 , q2 , q3 , q4 }, F={q4 }
δ(q0 , 1) = (q0 , 1, R), δ(q0 , 0) = (q1 , 1, R), δ(q1 , 1) = (q1 , 1, R),
δ(q1 , □) = (q2 , □, L), δ(q2 , 1) = (q3 , 0, L), δ(q3 , 1) = (q3 , 1, L)
δ(q3 , □) = (q4 , □, R)
Turing Computable
Example
Given two positive integers ’x’ and ’y’. Design a turing machine
that computes x+y
Solution: Using Unary notation in which any positive integer ’x’ is
represented by w(x) ∈ {1}+ such that |w(x)|=x.
So, the required machine is: q0 w (x)0w (y ) ⊢ ∗qf w (x + y )0
Steps: Move the separating 0 to right end of w(y)
Let M=(Q,Σ, τ, q0 , □, F )
Q={q0 , q1 , q2 , q3 , q4 }, F={q4 }
δ(q0 , 1) = (q0 , 1, R), δ(q0 , 0) = (q1 , 1, R), δ(q1 , 1) = (q1 , 1, R),
δ(q1 , □) = (q2 , □, L), δ(q2 , 1) = (q3 , 0, L), δ(q3 , 1) = (q3 , 1, L)
δ(q3 , □) = (q4 , □, R)
Adding 111 to 11
q0 111011 ⊢ 1q0 11011 ⊢ 11q0 1011 ⊢ 111q0 011 ⊢ 1111q1 11 ⊢ . . .
Turing Computable
Q. Design a Turing Machine that copies strings of 1’s. More
precisely, find a machine that performs the following computation:
q0 w ⊢ ∗qf ww for any w ∈ {1}+
Turing Computable
Q. Design a Turing Machine that copies strings of 1’s. More
precisely, find a machine that performs the following computation:
q0 w ⊢ ∗qf ww for any w ∈ {1}+
Solution:
1 Replace every 1 by an ’x’.
2 Find the right most ’x’ and replace it with 1.
3 Travel right end of the current non-blank region and create a
1 there.
4 Repeat step 2 and 3 untill there exist a ’x’.
Let M = (Q, Σ, τ , δ, q0 , □, F)
Q={q0 , q1 , q2 , q3 }, F= {q3 }
Turing Computable
Q. Design a Turing Machine that copies strings of 1’s. More
precisely, find a machine that performs the following computation:
q0 w ⊢ ∗qf ww for any w ∈ {1}+
Solution:
1 Replace every 1 by an ’x’.
2 Find the right most ’x’ and replace it with 1.
3 Travel right end of the current non-blank region and create a
1 there.
4 Repeat step 2 and 3 untill there exist a ’x’.
Let M = (Q, Σ, τ , δ, q0 , □, F)
Q={q0 , q1 , q2 , q3 }, F= {q3 }
δ(q0 , 1) = (q0 , x, R)
Turing Computable
Q. Design a Turing Machine that copies strings of 1’s. More
precisely, find a machine that performs the following computation:
q0 w ⊢ ∗qf ww for any w ∈ {1}+
Solution:
1 Replace every 1 by an ’x’.
2 Find the right most ’x’ and replace it with 1.
3 Travel right end of the current non-blank region and create a
1 there.
4 Repeat step 2 and 3 untill there exist a ’x’.
Let M = (Q, Σ, τ , δ, q0 , □, F)
Q={q0 , q1 , q2 , q3 }, F= {q3 }
δ(q0 , 1) = (q0 , x, R) , δ(q0 , □) = (q1 , □, L)
Turing Computable
Q. Design a Turing Machine that copies strings of 1’s. More
precisely, find a machine that performs the following computation:
q0 w ⊢ ∗qf ww for any w ∈ {1}+
Solution:
1 Replace every 1 by an ’x’.
2 Find the right most ’x’ and replace it with 1.
3 Travel right end of the current non-blank region and create a
1 there.
4 Repeat step 2 and 3 untill there exist a ’x’.
Let M = (Q, Σ, τ , δ, q0 , □, F)
Q={q0 , q1 , q2 , q3 }, F= {q3 }
δ(q0 , 1) = (q0 , x, R) , δ(q0 , □) = (q1 , □, L) , δ(q1 , x) = (q2 , 1, R)
Turing Computable
Q. Design a Turing Machine that copies strings of 1’s. More
precisely, find a machine that performs the following computation:
q0 w ⊢ ∗qf ww for any w ∈ {1}+
Solution:
1 Replace every 1 by an ’x’.
2 Find the right most ’x’ and replace it with 1.
3 Travel right end of the current non-blank region and create a
1 there.
4 Repeat step 2 and 3 untill there exist a ’x’.
Let M = (Q, Σ, τ , δ, q0 , □, F)
Q={q0 , q1 , q2 , q3 }, F= {q3 }
δ(q0 , 1) = (q0 , x, R) , δ(q0 , □) = (q1 , □, L) , δ(q1 , x) = (q2 , 1, R)
δ(q2 , 1) = (q2 , 1, R)
Turing Computable
Q. Design a Turing Machine that copies strings of 1’s. More
precisely, find a machine that performs the following computation:
q0 w ⊢ ∗qf ww for any w ∈ {1}+
Solution:
1 Replace every 1 by an ’x’.
2 Find the right most ’x’ and replace it with 1.
3 Travel right end of the current non-blank region and create a
1 there.
4 Repeat step 2 and 3 untill there exist a ’x’.
Let M = (Q, Σ, τ , δ, q0 , □, F)
Q={q0 , q1 , q2 , q3 }, F= {q3 }
δ(q0 , 1) = (q0 , x, R) , δ(q0 , □) = (q1 , □, L) , δ(q1 , x) = (q2 , 1, R)
δ(q2 , 1) = (q2 , 1, R) , δ(q2 , □) = (q1 , 1, L)
Turing Computable
Q. Design a Turing Machine that copies strings of 1’s. More
precisely, find a machine that performs the following computation:
q0 w ⊢ ∗qf ww for any w ∈ {1}+
Solution:
1 Replace every 1 by an ’x’.
2 Find the right most ’x’ and replace it with 1.
3 Travel right end of the current non-blank region and create a
1 there.
4 Repeat step 2 and 3 untill there exist a ’x’.
Let M = (Q, Σ, τ , δ, q0 , □, F)
Q={q0 , q1 , q2 , q3 }, F= {q3 }
δ(q0 , 1) = (q0 , x, R) , δ(q0 , □) = (q1 , □, L) , δ(q1 , x) = (q2 , 1, R)
δ(q2 , 1) = (q2 , 1, R) , δ(q2 , □) = (q1 , 1, L) , δ(q1 , 1) = (q1 , 1, L)
Turing Computable
Q. Design a Turing Machine that copies strings of 1’s. More
precisely, find a machine that performs the following computation:
q0 w ⊢ ∗qf ww for any w ∈ {1}+
Solution:
1 Replace every 1 by an ’x’.
2 Find the right most ’x’ and replace it with 1.
3 Travel right end of the current non-blank region and create a
1 there.
4 Repeat step 2 and 3 untill there exist a ’x’.
Let M = (Q, Σ, τ , δ, q0 , □, F)
Q={q0 , q1 , q2 , q3 }, F= {q3 }
δ(q0 , 1) = (q0 , x, R) , δ(q0 , □) = (q1 , □, L) , δ(q1 , x) = (q2 , 1, R)
δ(q2 , 1) = (q2 , 1, R) , δ(q2 , □) = (q1 , 1, L) , δ(q1 , 1) = (q1 , 1, L) ,
δ(q1 , □) = (q3 , □, R)
Turing Computable
Q. Design a Turing Machine that copies strings of 1’s. More
precisely, find a machine that performs the following computation:
q0 w ⊢ ∗qf ww for any w ∈ {1}+
Solution:
1 Replace every 1 by an ’x’.
2 Find the right most ’x’ and replace it with 1.
3 Travel right end of the current non-blank region and create a
1 there.
4 Repeat step 2 and 3 untill there exist a ’x’.
Let M = (Q, Σ, τ , δ, q0 , □, F)
Q={q0 , q1 , q2 , q3 }, F= {q3 }
δ(q0 , 1) = (q0 , x, R) , δ(q0 , □) = (q1 , □, L) , δ(q1 , x) = (q2 , 1, R)
δ(q2 , 1) = (q2 , 1, R) , δ(q2 , □) = (q1 , 1, L) , δ(q1 , 1) = (q1 , 1, L) ,
δ(q1 , □) = (q3 , □, R)
Turing Computable
Turing Computable
(0,0,R) (Y,Y,R)
(X,X,R) (0,0,L)
q4
0011. (0,0,L)
(0,0,R) (Y,Y,R)
(X,X,R) (0,0,L)
q4
0011. (0,0,L)
CYK Algorithm
It is a Membership algorithm.
G is the given grammar
W - String of Terminal symbols
-Helps determine whether w is in L(G) or not
Applicable only when grmammar is in CNF.
Invented by J Cocke, D.H. Younger and T. Kasami
CYK Algorithm
It is a Membership algorithm.
G is the given grammar
W - String of Terminal symbols
-Helps determine whether w is in L(G) or not
Applicable only when grmammar is in CNF.
Invented by J Cocke, D.H. Younger and T. Kasami
Steps:
Construct a Triangular Table.
Each row correspnds to one length of substring.
Xii : is set of variable A such that A → wi is a production of G
Xij = ∪: {A:A→ BC , B ∈ Vik , C ∈ Vk+j,j }
where k ∈ {i,i+1,....,j-1}
CYK Algorithm
Q. Let w=aabba. Does w ∈ L(G) for given grammar?
S → AB, A → BB a, B → AB b
CYK Algorithm
Q. Let w=aabba. Does w ∈ L(G) for given grammar?
S → AB, A → BB a, B → AB b
Sol. w =5
ϕ
A ϕ
S,B A ϕ
ϕ S,B A ϕ
A A B B A
a a b b a
X12 = AA = ϕ,
CYK Algorithm
Q. Let w=aabba. Does w ∈ L(G) for given grammar?
S → AB, A → BB a, B → AB b
Sol. w =5
ϕ
A ϕ
S,B A ϕ
ϕ S,B A ϕ
A A B B A
a a b b a
X12 = AA = ϕ, X23 = AB = B, S,
CYK Algorithm
Q. Let w=aabba. Does w ∈ L(G) for given grammar?
S → AB, A → BB a, B → AB b
Sol. w =5
ϕ
A ϕ
S,B A ϕ
ϕ S,B A ϕ
A A B B A
a a b b a
X12 = AA = ϕ, X23 = AB = B, S, X34 = BB = A,
CYK Algorithm
Q. Let w=aabba. Does w ∈ L(G) for given grammar?
S → AB, A → BB a, B → AB b
Sol. w =5
ϕ
A ϕ
S,B A ϕ
ϕ S,B A ϕ
A A B B A
a a b b a
X12 = AA = ϕ, X23 = AB = B, S, X34 = BB = A, X45 = BA = ϕ
CYK Algorithm
Q. Let w=aabba. Does w ∈ L(G) for given grammar?
S → AB, A → BB a, B → AB b
Sol. w =5
ϕ
A ϕ
S,B A ϕ
ϕ S,B A ϕ
A A B B A
a a b b a
X12 = AA = ϕ, X23 = AB = B, S, X34 = BB = A, X45 = BA = ϕ
X13 = A(S, B) ∪ ϕ = AS, AB = S, B
CYK Algorithm
Q. Let w=aabba. Does w ∈ L(G) for given grammar?
S → AB, A → BB a, B → AB b
Sol. w =5
ϕ
A ϕ
S,B A ϕ
ϕ S,B A ϕ
A A B B A
a a b b a
X12 = AA = ϕ, X23 = AB = B, S, X34 = BB = A, X45 = BA = ϕ
X13 = A(S, B) ∪ ϕ = AS, AB = S, B X24 = AA ∪ SB, BB = A
CYK Algorithm
Q. Let w=aabba. Does w ∈ L(G) for given grammar?
S → AB, A → BB a, B → AB b
Sol. w =5
ϕ
A ϕ
S,B A ϕ
ϕ S,B A ϕ
A A B B A
a a b b a
X12 = AA = ϕ, X23 = AB = B, S, X34 = BB = A, X45 = BA = ϕ
X13 = A(S, B) ∪ ϕ = AS, AB = S, B X24 = AA ∪ SB, BB = A
X35 = ϕ ∪ AA = ϕ
CYK Algorithm
Q. Let w=aabba. Does w ∈ L(G) for given grammar?
S → AB, A → BB a, B → AB b
Sol. w =5
ϕ
A ϕ
S,B A ϕ
ϕ S,B A ϕ
A A B B A
a a b b a
X12 = AA = ϕ, X23 = AB = B, S, X34 = BB = A, X45 = BA = ϕ
X13 = A(S, B) ∪ ϕ = AS, AB = S, B X24 = AA ∪ SB, BB = A
X35 = ϕ ∪ AA = ϕ
X14 = AA∪ϕ∪(S, B)B = AA∪ϕ(SB, BB) = A
CYK Algorithm
Q. Let w=aabba. Does w ∈ L(G) for given grammar?
S → AB, A → BB a, B → AB b
Sol. w =5
ϕ
A ϕ
S,B A ϕ
ϕ S,B A ϕ
A A B B A
a a b b a
X12 = AA = ϕ, X23 = AB = B, S, X34 = BB = A, X45 = BA = ϕ
X13 = A(S, B) ∪ ϕ = AS, AB = S, B X24 = AA ∪ SB, BB = A
X35 = ϕ ∪ AA = ϕ
X14 = AA∪ϕ∪(S, B)B = AA∪ϕ(SB, BB) = AX25 = ϕ∪ϕ∪AA = ϕ
CYK Algorithm
Q. Let w=aabba. Does w ∈ L(G) for given grammar?
S → AB, A → BB a, B → AB b
Sol. w =5
ϕ
A ϕ
S,B A ϕ
ϕ S,B A ϕ
A A B B A
a a b b a
X12 = AA = ϕ, X23 = AB = B, S, X34 = BB = A, X45 = BA = ϕ
X13 = A(S, B) ∪ ϕ = AS, AB = S, B X24 = AA ∪ SB, BB = A
X35 = ϕ ∪ AA = ϕ
X14 = AA∪ϕ∪(S, B)B = AA∪ϕ(SB, BB) = AX25 = ϕ∪ϕ∪AA = ϕ
X15 = ϕ ∪ ϕ ∪ ϕ ∪ AA = ϕ
CYK Algorithm
Q. Let w=aabba. Does w ∈ L(G) for given grammar?
S → AB, A → BB a, B → AB b
Sol. w =5
ϕ
A ϕ
S,B A ϕ
ϕ S,B A ϕ
A A B B A
a a b b a
X12 = AA = ϕ, X23 = AB = B, S, X34 = BB = A, X45 = BA = ϕ
X13 = A(S, B) ∪ ϕ = AS, AB = S, B X24 = AA ∪ SB, BB = A
X35 = ϕ ∪ AA = ϕ
X14 = AA∪ϕ∪(S, B)B = AA∪ϕ(SB, BB) = AX25 = ϕ∪ϕ∪AA = ϕ
X15 = ϕ ∪ ϕ ∪ ϕ ∪ AA = ϕ
here, we donot have ”S” in the top row. ∴ w ∈
/ L(G ).
Department of CSE Module 4 March 6, 2025 28/33
Context Sensitive Language
CYK Algorithm
CYK Algorithm
CYK Algorithm
CYK Algorithm
Present state ψ b 1
→ q1 ψRq1 - bRq2
q2 - - bRq1
Present state ψ b 1
→ q1 ψRq1 - bRq2
q2 - - bRq1
Present state ψ b 1
→ q1 ψRq1 - bRq2
q2 - - bRq1
Present state ψ b 1
→ q1 ψRq1 - bRq2
q2 - - bRq1
Present state ψ b 1
→ q1 ψRq1 - bRq2
q2 - - bRq1
Present state ψ b 1
→ q1 ψRq1 - bRq2
q2 - - bRq1
Present state ψ b 1
→ q1 ψRq1 - bRq2
q2 - - bRq1