0% found this document useful (0 votes)
25 views85 pages

Module 5

This document outlines Module IV on Turing Machines, detailing their model, design, and computability. It covers the structure of Turing Machines, including their states, transition functions, and various representations, as well as examples of Turing Machines that perform specific computations. Additionally, it discusses concepts such as language acceptability, universal Turing Machines, and recursive languages.

Uploaded by

Zaid Z.Khan
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)
25 views85 pages

Module 5

This document outlines Module IV on Turing Machines, detailing their model, design, and computability. It covers the structure of Turing Machines, including their states, transition functions, and various representations, as well as examples of Turing Machines that perform specific computations. Additionally, it discusses concepts such as language acceptability, universal Turing Machines, and recursive languages.

Uploaded by

Zaid Z.Khan
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/ 85

Module IV: Turing Machine

Dr. Vibha Nehra


Department of Computer Science and Engineering

Amity School of Engineering and Technology


Amity University Uttar Pradesh, Noida

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

Department of CSE Module 4 March 6, 2025 2/33


The Turing Machine Model

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.

Department of CSE Module 4 March 6, 2025 3/33


The Turing Machine Model

Turing Machine

A Turing machine M is defined by M=(Q, Σ, τ, δ, q0 , □, F )


where, Q = set of internal states
Σ = Input alphabet; Σ ⊆ τ − {□}
τ = Finite set of symbols called tape alphabet
δ = Transition function Q × τ → Q × τ × {L, R}
□ ∈ τ = special symbol called ”blank”
q0 ∈ Q =initial state
F ⊆ Q = set of final states

Department of CSE Module 4 March 6, 2025 4/33


The Turing Machine Model

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.

Department of CSE Module 4 March 6, 2025 5/33


The Turing Machine Model Language acceptability of Turing Machine

Turing Machine

Consider the turing machine defined by: Q={q0 , q1 },


Σ={a,b}, τ = {a, b, □}, F ={q1 } and δ(q0 , a) = (q0 , b, R)
δ(q0 , b) = (q0 , b, R)
δ(q0 , □) = (q1 , □, L)

Department of CSE Module 4 March 6, 2025 6/33


The Turing Machine Model Language acceptability of Turing Machine

Turing Machine

Consider the turing machine defined by: Q={q0 , q1 },


Σ={a,b}, τ = {a, b, □}, F ={q1 } and δ(q0 , a) = (q0 , b, R)
δ(q0 , b) = (q0 , b, R)
δ(q0 , □) = (q1 , □, L)
Q={q0 , q1 }, Σ={a,b}, τ = {a, b, □}

Department of CSE Module 4 March 6, 2025 6/33


The Turing Machine Model Language acceptability of Turing Machine

Turing Machine

Consider the turing machine defined by: Q={q0 , q1 },


Σ={a,b}, τ = {a, b, □}, F ={q1 } and δ(q0 , a) = (q0 , b, R)
δ(q0 , b) = (q0 , b, R)
δ(q0 , □) = (q1 , □, L)
Q={q0 , q1 }, Σ={a,b}, τ = {a, b, □}
Let F be empty. Define δ by:
δ(q0 , a) = (q1 , a, R)
δ(q0 , b) = (q1 , b, R)
δ(q0 , □) = (q1 , □, R)
δ(q1 , a) = (q0 , a, L)
δ(q1 , b) = (q0 , b, L)
δ(q1 , □) = (q0 , □, L)

Department of CSE Module 4 March 6, 2025 6/33


Design of TM

Design of Turing Machine I


Question: For Σ= {a,b}, design a turing machine that accepts
L={an b n : n ≥ 1}
Design of TM

Design of Turing Machine II


Q={q0 , q1 , q2 , q3 , q4 }, F={q4 }
Σ = {a, b}, τ = {a, b, x, y , □}
δ(q0 , a) = (q1 , x, R) =⇒ replaces ’a’ by ’x’
δ(q1 , a) = (q1 , a, R) =⇒ move right
δ(q1 , y ) = (q1 , y , R) =⇒ move right
δ(q1 , b) = (q2 , y , L) =⇒ ’a’ paired with ’b’
Move left to find ’x’
δ(q2 , y ) = (q2 , y , L) =⇒ move left
δ(q2 , a) = (q2 , a, L) =⇒ move left
δ(q2 , x) = (q0 , x, R) =⇒ placed at first ’a’
Check for all ’a’ and ’b’ are replaced
δ(q0 , y ) = (q3 , y , R)
δ(q3 , y ) = (q3 , y , R)
δ(q3 , □) = (q4 , □, R)
For input ’aabb’
q0 aabb ⊢ xq1 abb ⊢ xaq1 bb ⊢ xq2 ayb ⊢ q2 xayb ⊢ xq0 ayb ⊢ xxq1 yb ⊢ xxyq1 b ⊢
xxq2 yy ⊢ xq2 xyy ⊢ xxq0 yy ⊢ xxyq3 y ⊢ xxyyq3 ⊢ xxyy □q4 □
Design of TM

Design of turing machine

Question: Design a Turing Machine that accepts


L={an b n c n : n ≥ 1}

Department of CSE Module 4 March 6, 2025 9/33


Design of TM

Turing Computable

A function ’f’ with domain ’D’ is said to be turing computable or


just computable, if there exists some turing machine M=(Q,
Σ, τ, δ, q0 , □, F) such that q0 w ⊢∗M qf f (w ), qf ∈ F for all w∈ D.

Department of CSE Module 4 March 6, 2025 10/33


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)

Department of CSE Module 4 March 6, 2025 11/33


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)
Adding 111 to 11
q0 111011 ⊢ 1q0 11011 ⊢ 11q0 1011 ⊢ 111q0 011 ⊢ 1111q1 11 ⊢ . . .

Department of CSE Module 4 March 6, 2025 11/33


Turing Computable

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}+

Department of CSE Module 4 March 6, 2025 12/33


Turing Computable

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 }

Department of CSE Module 4 March 6, 2025 12/33


Turing Computable

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)

Department of CSE Module 4 March 6, 2025 12/33


Turing Computable

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)

Department of CSE Module 4 March 6, 2025 12/33


Turing Computable

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)

Department of CSE Module 4 March 6, 2025 12/33


Turing Computable

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)

Department of CSE Module 4 March 6, 2025 12/33


Turing Computable

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)

Department of CSE Module 4 March 6, 2025 12/33


Turing Computable

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)

Department of CSE Module 4 March 6, 2025 12/33


Turing Computable

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)

Department of CSE Module 4 March 6, 2025 12/33


Turing Computable

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)

Department of CSE Module 4 March 6, 2025 12/33


Turing Computable

Turing Computable

Q. Let x and y be two positive integers represented in unary


notation. Construct a turing maching that will halt in final
state qy if x ≥ y and that will halt in non-final state qn if
x < y . More specifically, the machine is to perform the
computation:
q0 w (x)0w (y ) ⊢∗ qy w (x)0w (y ): if x ≥ y
q0 w (x)0w (y ) ⊢∗ qn w (x)0w (y ): if x < y

Department of CSE Module 4 March 6, 2025 13/33


Turing Computable

Turing Computable

Q. Let x and y be two positive integers represented in unary


notation. Construct a turing maching that will halt in final
state qy if x ≥ y and that will halt in non-final state qn if
x < y . More specifically, the machine is to perform the
computation:
q0 w (x)0w (y ) ⊢∗ qy w (x)0w (y ): if x ≥ y
q0 w (x)0w (y ) ⊢∗ qn w (x)0w (y ): if x < y
Q. Construct a Turing machine to compute the function:
f (w ) = w R , where w ∈ {0, 1}+

Department of CSE Module 4 March 6, 2025 13/33


Turing Computable Transition table representation of Turing Machine

Transition Table representation of Turing Machine


if δ(q, a)=(γ, α, β), then we write αβγ under a-column and q-row.

Department of CSE Module 4 March 6, 2025 14/33


Turing Computable Transition table representation of Turing Machine

Transition Table representation of Turing Machine


if δ(q, a)=(γ, α, β), then we write αβγ under a-column and q-row.
Q. Consider the Turing machine description given in table. Draw
the computation sequence of input string 00b.
Present State Tape Symbols
b 0 1
→ q1 1Lq2 0Rq1 -
q2 bRq3 0Lq2 1Lq2
q3 - bRq4 bRq5
q4 0Rq5 0Rq4 1Rq4
q5 0Lq2 - -

Department of CSE Module 4 March 6, 2025 14/33


Turing Computable Transition table representation of Turing Machine

Transition Table representation of Turing Machine


if δ(q, a)=(γ, α, β), then we write αβγ under a-column and q-row.
Q. Consider the Turing machine description given in table. Draw
the computation sequence of input string 00b.
Present State Tape Symbols
b 0 1
→ q1 1Lq2 0Rq1 -
q2 bRq3 0Lq2 1Lq2
q3 - bRq4 bRq5
q4 0Rq5 0Rq4 1Rq4
q5 0Lq2 - -
Solution. q1 00b ⊢ 0q1 0b ⊢ 00q1 b ⊢ 0q2 01 ⊢ q2 001 ⊢ q2 b001 ⊢
bq3 001 ⊢ bbq4 01 ⊢ bb0q4 1 ⊢ bb01q4 b ⊢ bb010q5 ⊢
bb01q2 00 ⊢ bb0q2 100 ⊢ bbq2 0100 ⊢ bq2 b0100 ⊢ bbq3 0100 ⊢
bbbq4 100 ⊢ bbb1q4 00 ⊢ bbb10q4 0 ⊢ bbb100q4 b ⊢
bbb1000q5 b ⊢ bbb100q2 00 ⊢ bbb10q2 000 ⊢ bbb1q2 0000 ⊢
bbbq2 10000 ⊢ bbq2 b10000 ⊢ bbbq3 10000 ⊢ bbbbq5 0000
Department of CSE Module 4 March 6, 2025 14/33
Turing Computable Transition Diagram representation of Turing Machine

Transition Diagram representation of Turing


Machine

Represents states by Vertices.


Directed edges are used to represent transition of States.
Labels on edges are triples of the form (α, β, γ), where
α, β ∈ τ , γ ∈ {L, R}
if δ(qi , α) = (qj , β, γ)
=⇒ ∋ a directed edge from qi to qj with label (α, β, γ)
∴ Every edge in the transition system can be represented by a
5-tuple(qi , α, β, γ, qj ).
Department of CSE Module 4 March 6, 2025 15/33
Turing Computable Transition Diagram representation of Turing Machine

Transition Diagram representation of TM


Q. Given a transition system which represents a turing machine. Obtain
the computation sequence of M for processing the input string
(b,b,R)
(Y,Y,R) (Y,Y,L)

(0,X,R) (1,Y,L) (X,X,R) (b,b,R)


q1 q2 q3 q5 q6

(0,0,R) (Y,Y,R)
(X,X,R) (0,0,L)

q4

0011. (0,0,L)

Sol. Initially the input tape contains b0011b:

Department of CSE Module 4 March 6, 2025 16/33


Turing Computable Transition Diagram representation of Turing Machine

Transition Diagram representation of TM


Q. Given a transition system which represents a turing machine. Obtain
the computation sequence of M for processing the input string
(b,b,R)
(Y,Y,R) (Y,Y,L)

(0,X,R) (1,Y,L) (X,X,R) (b,b,R)


q1 q2 q3 q5 q6

(0,0,R) (Y,Y,R)
(X,X,R) (0,0,L)

q4

0011. (0,0,L)

Sol. Initially the input tape contains b0011b:


(0,X ,R) (0,0,R) (1,Y ,L)
bq1 0011b −−−−→ bXq2 011b −−−−→ bX 0q2 11b −−−−→
(0,0,L) (X ,X ,R) (0,X ,R)
bXq3 0Y 1b −−−−→ bq4 X 0Y 1b −−−−−→ bXq1 0Y 1b −−−−→
(Y ,Y ,R) (1,Y ,L) (Y ,Y ,L)
bXXq2 Y 1b −−−−−→ bXXYq2 1b −−−−→ bXXq3 YYb −−−−−→
(X ,X ,R) (Y ,Y ,R) (Y ,Y ,R)
bXq3 XYYb −−−−−→ bXXq5 YYb −−−−−→ bXXYq5 Yb −−−−−→
(b,b,R)
bbXXYYq5 b −−−−→ bXXYYbq6 b
Department of CSE Module 4 March 6, 2025 16/33
Turing Computable Transition Diagram representation of Turing Machine

Q. Consider the turing machine M described by the transition table


given. Describe the processing of a) 011, b) 0011, c) 001 using
Instanteous description. Which of the above strings are accepted
by M.
Present State Tape Symbols
0 1 X Y b
→ q1 XRq2 - - - bRq5
q2 0Rq2 YLq3 - YRq2 -
q3 LRq4 - XRq5 YLq3 -
q4 0Lq4 - XRq1 - -
q5 - - - YRq5 bRq6
q6 - - - - -
Sol. a. q1 011 ⊢ Xq2 11 ⊢ q3 XY 1 ⊢ Xq5 Y 1 ⊢ XYq5 1 ⊢ (M halts
here as δ(q5 , 1) is not defined)

Department of CSE Module 4 March 6, 2025 17/33


Turing Computable Transition Diagram representation of Turing Machine

Q. Consider the turing machine M described by the transition table


given. Describe the processing of a) 011, b) 0011, c) 001 using
Instanteous description. Which of the above strings are accepted
by M.
Present State Tape Symbols
0 1 X Y b
→ q1 XRq2 - - - bRq5
q2 0Rq2 YLq3 - YRq2 -
q3 LRq4 - XRq5 YLq3 -
q4 0Lq4 - XRq1 - -
q5 - - - YRq5 bRq6
q6 - - - - -
Sol. b. q1 011 ⊢ Xq2 011 ⊢ X 0q2 11 ⊢ Xq3 0Y 1 ⊢ q4 X 0Y 1 ⊢
XXq2 Y 1 ⊢ XXYq2 1 ⊢ XXq3 YY ⊢ Xq3 XYY ⊢ XXq5 YY ⊢
XXYq5 Y ⊢ XXYq5 Y ⊢ XXYYq5 b ⊢ XXYYbq6 (M halts here as
δ(q6 , b) is not defined) ACCEPTED.

Department of CSE Module 4 March 6, 2025 18/33


Turing Computable Transition Diagram representation of Turing Machine

Q. Consider the turing machine M described by the transition table


given. Describe the processing of a) 011, b) 0011, c) 001 using
Instanteous description. Which of the above strings are accepted
by M.
Present State Tape Symbols
0 1 X Y b
→ q1 XRq2 - - - bRq5
q2 0Rq2 YLq3 - YRq2 -
q3 LRq4 - XRq5 YLq3 -
q4 0Lq4 - XRq1 - -
q5 - - - YRq5 bRq6
q6 - - - - -
Sol. c.

Department of CSE Module 4 March 6, 2025 19/33


Turing Computable Transition Diagram representation of Turing Machine

Q. Design a turing machine to recognise all strings consisting of


even number of 1’s.

Department of CSE Module 4 March 6, 2025 20/33


Turing Computable Transition Diagram representation of Turing Machine

Q. Design a turing machine to recognise all strings consisting of


even number of 1’s.
Sol. Steps:
Assume q1 as initial state and final state.
If machine reads 1, replace it by b and convert state to q2 .
If machine reads 1 in state q2 , replace it with b and convert
state to q1 .

Department of CSE Module 4 March 6, 2025 20/33


Turing Computable Transition Diagram representation of Turing Machine

Q. Design a turing machine to recognise all strings consisting of


even number of 1’s.
Sol. Steps:
Assume q1 as initial state and final state.
If machine reads 1, replace it by b and convert state to q2 .
If machine reads 1 in state q2 , replace it with b and convert
state to q1 .
∴ In the end all input symbols must be read and machine must be
in final state.

Department of CSE Module 4 March 6, 2025 20/33


Turing Computable Transition Diagram representation of Turing Machine

Q. Design a turing machine to recognise all strings consisting of


even number of 1’s.
Sol. Steps:
Assume q1 as initial state and final state.
If machine reads 1, replace it by b and convert state to q2 .
If machine reads 1 in state q2 , replace it with b and convert
state to q1 .
∴ In the end all input symbols must be read and machine must be
in final state.
let M =({q1 , q2 }, {1}, {1,b}, δ, q1 , b, {q1 })
Present state 1
→ q1 bq2 R
q2 bq1 R

Department of CSE Module 4 March 6, 2025 20/33


Turing Computable Transition Diagram representation of Turing Machine

Q. Design a turing machine to recognise all strings consisting of


even number of 1’s.
Sol. Steps:
Assume q1 as initial state and final state.
If machine reads 1, replace it by b and convert state to q2 .
If machine reads 1 in state q2 , replace it with b and convert
state to q1 .
∴ In the end all input symbols must be read and machine must be
in final state.
let M =({q1 , q2 }, {1}, {1,b}, δ, q1 , b, {q1 })
Present state 1
→ q1 bq2 R
q2 bq1 R
Let the assumed string be 11

Department of CSE Module 4 March 6, 2025 20/33


Turing Computable Transition Diagram representation of Turing Machine

Q. Design a turing machine to recognise all strings consisting of


even number of 1’s.
Sol. Steps:
Assume q1 as initial state and final state.
If machine reads 1, replace it by b and convert state to q2 .
If machine reads 1 in state q2 , replace it with b and convert
state to q1 .
∴ In the end all input symbols must be read and machine must be
in final state.
let M =({q1 , q2 }, {1}, {1,b}, δ, q1 , b, {q1 })
Present state 1
→ q1 bq2 R
q2 bq1 R
Let the assumed string be 11
q1 11 ⊢ bq2 1 ⊢ bbq1
Thus, the string is accepted.

Department of CSE Module 4 March 6, 2025 20/33


Universal TM

Universal Turing Machines


A general purpose turing machine is usually called Universal
Turing Machine which is powerful enough to simulate the
behaviour of any computer, including any turing machine
itself.

Department of CSE Module 4 March 6, 2025 21/33


Universal TM

Universal Turing Machines


A general purpose turing machine is usually called Universal
Turing Machine which is powerful enough to simulate the
behaviour of any computer, including any turing machine
itself.
A universal turing machine can simulate the behaviour of any
arbitrary turing machine over any σ.

Department of CSE Module 4 March 6, 2025 21/33


Universal TM

Universal Turing Machines


A general purpose turing machine is usually called Universal
Turing Machine which is powerful enough to simulate the
behaviour of any computer, including any turing machine
itself.
A universal turing machine can simulate the behaviour of any
arbitrary turing machine over any σ.
The simple machines which we designed till now as not
necessarily most efficient. Even the very well designed turing
machines take a large number of states for simulating even
the simplest behaviour.

Department of CSE Module 4 March 6, 2025 21/33


Universal TM

Universal Turing Machines


A general purpose turing machine is usually called Universal
Turing Machine which is powerful enough to simulate the
behaviour of any computer, including any turing machine
itself.
A universal turing machine can simulate the behaviour of any
arbitrary turing machine over any σ.
The simple machines which we designed till now as not
necessarily most efficient. Even the very well designed turing
machines take a large number of states for simulating even
the simplest behaviour.
The possible modifications can be:

Department of CSE Module 4 March 6, 2025 21/33


Universal TM

Universal Turing Machines


A general purpose turing machine is usually called Universal
Turing Machine which is powerful enough to simulate the
behaviour of any computer, including any turing machine
itself.
A universal turing machine can simulate the behaviour of any
arbitrary turing machine over any σ.
The simple machines which we designed till now as not
necessarily most efficient. Even the very well designed turing
machines take a large number of states for simulating even
the simplest behaviour.
The possible modifications can be:
Increase number of Read/write heads.
Making the tape multi-dimensional i.e. 2-d or 3-d.
Adding some memory such as stack or special purpose registers.
This increases speed but donot aid to computational power.

Department of CSE Module 4 March 6, 2025 21/33


Variation of TM

Non-Deterministic Turing Machine


The basic turing machine model said that turing machine is
deterministic i.e. processing an inputsymbol results in
transition to an unique ID.

Department of CSE Module 4 March 6, 2025 22/33


Variation of TM

Non-Deterministic Turing Machine


The basic turing machine model said that turing machine is
deterministic i.e. processing an inputsymbol results in
transition to an unique ID.
The processing of string is as under
ID ⊢ ID1 ⊢ ID2 ⊢ ID3 ⊢ . . . ⊢ IDn

Department of CSE Module 4 March 6, 2025 22/33


Variation of TM

Non-Deterministic Turing Machine


The basic turing machine model said that turing machine is
deterministic i.e. processing an inputsymbol results in
transition to an unique ID.
The processing of string is as under
ID ⊢ ID1 ⊢ ID2 ⊢ ID3 ⊢ . . . ⊢ IDn
This can be generalized as:
ID, ID1 , ID2 , ID3 , . . . or IDn
This generalized model is called Non-Deterministic Turing
Machine.
A string ’w ’ in Σ∗ is said to be accepted by a
non-deterministic TM, if there exists a sequence of moves
from initial ID to an accepting state.
The set of Languages accepted by a Non-deterministic TM is
a subset of the set of languages accepted by deterministic
TM(s).
Infact, these sets of languages are equal.
Department of CSE Module 4 March 6, 2025 22/33
Linear Bounded Automata

Model of Linear Bound Automaton


An Automaton which use a linear function to restrict or bound
the length of the tape is called Linear Bound Automaton.

Department of CSE Module 4 March 6, 2025 23/33


Linear Bounded Automata

Model of Linear Bound Automaton


An Automaton which use a linear function to restrict or bound
the length of the tape is called Linear Bound Automaton.
A linear bounded automaton is a non-deterministic turing
machine which has a single tape whose length is not infinite
but bounded by a linear function of the length of the input
string.
The model can be described formally by the following set
format:
M=(Q, Σ, τ, δ, q0 , b, ψ, $, F)
where, Σ contains two special symbols ψ and $ are left end
marker and right end marker respectively.

Department of CSE Module 4 March 6, 2025 23/33


Linear Bounded Automata

Linear Bound Automata

The model can be described formally by the following set


format:
M=(Q, Σ, τ, δ, q0 , b, ψ, $, F)
Let we have input string ”w” such that length(w)=n-2
Input string ’w’ cab be recognised by an LBA, if it can also be
recognised by a turing machine using no more than k × n cells
of input tape
where k is contant specified in as property of the machine. It
doesnot depend on Input String.
Department of CSE Module 4 March 6, 2025 24/33
Linear Bounded Automata

Linear Bounded Automata

There exist two tapes:


Input tape: head is read only and can move only right
Working tape: head is read/write.

Department of CSE Module 4 March 6, 2025 25/33


Linear Bounded Automata

Linear Bounded Automata

There exist two tapes:


Input tape: head is read only and can move only right
Working tape: head is read/write.
The language accepted by LBA is defined as the set:
{w ∈ (Σ − {ψ, $}∗ )|(q0 , ψw $) ⊢∗ (q, α, i)}
for some q ∈ F , 1 ≤ i ≤ n

Department of CSE Module 4 March 6, 2025 25/33


Linear Bounded Automata

Linear Bounded Automata

There exist two tapes:


Input tape: head is read only and can move only right
Working tape: head is read/write.
The language accepted by LBA is defined as the set:
{w ∈ (Σ − {ψ, $}∗ )|(q0 , ψw $) ⊢∗ (q, α, i)}
for some q ∈ F , 1 ≤ i ≤ n
A Null String is represented as either a completely blank
tape, or by absence of Input string, LBA may accept the null
string.
Department of CSE Module 4 March 6, 2025 25/33
Context Sensitive Language

Relation between LBA and Context sensitive


Languages:

If L is a context sensitive language, then L is accepted by


LBA; and the converse is also true.
The set of string accepted by non-deterministic LBA is the set
of strings generated by Context sensitive grammar, excluding
Null strings.

Department of CSE Module 4 March 6, 2025 26/33


Context Sensitive Language

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

Department of CSE Module 4 March 6, 2025 27/33


Context Sensitive Language

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}

Department of CSE Module 4 March 6, 2025 27/33


Context Sensitive Language

CYK Algorithm
Q. Let w=aabba. Does w ∈ L(G) for given grammar?
S → AB, A → BB a, B → AB b

Department of CSE Module 4 March 6, 2025 28/33


Context Sensitive Language

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 = ϕ,

Department of CSE Module 4 March 6, 2025 28/33


Context Sensitive Language

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,

Department of CSE Module 4 March 6, 2025 28/33


Context Sensitive Language

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,

Department of CSE Module 4 March 6, 2025 28/33


Context Sensitive Language

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 = ϕ

Department of CSE Module 4 March 6, 2025 28/33


Context Sensitive Language

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

Department of CSE Module 4 March 6, 2025 28/33


Context Sensitive Language

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

Department of CSE Module 4 March 6, 2025 28/33


Context Sensitive Language

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 = ϕ

Department of CSE Module 4 March 6, 2025 28/33


Context Sensitive Language

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

Department of CSE Module 4 March 6, 2025 28/33


Context Sensitive Language

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 = ϕ

Department of CSE Module 4 March 6, 2025 28/33


Context Sensitive Language

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 = ϕ

Department of CSE Module 4 March 6, 2025 28/33


Context Sensitive Language

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

Q. For w=baaa. Does w∈ L(G) for given grammar?


S → AB BC, A → BA a, B → CC b, C → AB a

Department of CSE Module 4 March 6, 2025 29/33


Context Sensitive Language

CYK Algorithm

Q. For w=baaa. Does w∈ L(G) for given grammar?


S → AB BC, A → BA a, B → CC b, C → AB a
Sol. S → AB → BAB → BACC → baaa
for w =4

Department of CSE Module 4 March 6, 2025 29/33


Context Sensitive Language

CYK Algorithm

Q. For w=baaa. Does w∈ L(G) for given grammar?


S → AB BC, A → BA a, B → CC b, C → AB a
Sol. S → AB → BAB → BACC → baaa
for w =4
S,A,C
ϕ S,C,A
A,S B B
B A,C A,C A,C
b a a a

Department of CSE Module 4 March 6, 2025 29/33


Context Sensitive Language

CYK Algorithm

Q. For w=baaa. Does w∈ L(G) for given grammar?


S → AB BC, A → BA a, B → CC b, C → AB a
Sol. S → AB → BAB → BACC → baaa
for w =4
S,A,C
ϕ S,C,A
A,S B B
B A,C A,C A,C
b a a a

Department of CSE Module 4 March 6, 2025 29/33


Unrestricted Grammars

Turing Machine and Type 0 Grammars.


Construction of Grammar for a Turing Machine

Department of CSE Module 4 March 6, 2025 30/33


Unrestricted Grammars

Turing Machine and Type 0 Grammars.


Construction of Grammar for a Turing Machine
Ex. Consider a Turing Machine described by Transition table.
Obtain inverse production rules (q1 is final state).

Present state ψ b 1
→ q1 ψRq1 - bRq2
q2 - - bRq1

Department of CSE Module 4 March 6, 2025 30/33


Unrestricted Grammars

Turing Machine and Type 0 Grammars.


Construction of Grammar for a Turing Machine
Ex. Consider a Turing Machine described by Transition table.
Obtain inverse production rules (q1 is final state).

Present state ψ b 1
→ q1 ψRq1 - bRq2
q2 - - bRq1

Sol. q1 is both initial & final state.

Department of CSE Module 4 March 6, 2025 30/33


Unrestricted Grammars

Turing Machine and Type 0 Grammars.


Construction of Grammar for a Turing Machine
Ex. Consider a Turing Machine described by Transition table.
Obtain inverse production rules (q1 is final state).

Present state ψ b 1
→ q1 ψRq1 - bRq2
q2 - - bRq1

Sol. q1 is both initial & final state.


1. Productions corresponding to right moves

Department of CSE Module 4 March 6, 2025 30/33


Unrestricted Grammars

Turing Machine and Type 0 Grammars.


Construction of Grammar for a Turing Machine
Ex. Consider a Turing Machine described by Transition table.
Obtain inverse production rules (q1 is final state).

Present state ψ b 1
→ q1 ψRq1 - bRq2
q2 - - bRq1

Sol. q1 is both initial & final state.


1. Productions corresponding to right moves
2. a. Productions corresponding to left end: [b → [

Department of CSE Module 4 March 6, 2025 30/33


Unrestricted Grammars

Turing Machine and Type 0 Grammars.


Construction of Grammar for a Turing Machine
Ex. Consider a Turing Machine described by Transition table.
Obtain inverse production rules (q1 is final state).

Present state ψ b 1
→ q1 ψRq1 - bRq2
q2 - - bRq1

Sol. q1 is both initial & final state.


1. Productions corresponding to right moves
2. a. Productions corresponding to left end: [b → [
b. Productions corresponding to right end: bb] → b], 1b] → 1],
q1 ] → q1 b], q2 ] → q2 b]

Department of CSE Module 4 March 6, 2025 30/33


Unrestricted Grammars

Turing Machine and Type 0 Grammars.


Construction of Grammar for a Turing Machine
Ex. Consider a Turing Machine described by Transition table.
Obtain inverse production rules (q1 is final state).

Present state ψ b 1
→ q1 ψRq1 - bRq2
q2 - - bRq1

Sol. q1 is both initial & final state.


1. Productions corresponding to right moves
2. a. Productions corresponding to left end: [b → [
b. Productions corresponding to right end: bb] → b], 1b] → 1],
q1 ] → q1 b], q2 ] → q2 b]
3. 1 → [q1 ψ1 // ai → [q1 ψai ∀ai ∈ τ, ai ̸= b
1 → 1$] // ai → ai $] ∀ai ∈ τ, ai ̸= b
[q1 b] → S // for removing brackets from [qf b]

Department of CSE Module 4 March 6, 2025 30/33


Unrestricted Grammars

Turing Machine and Type 0 Grammars.


Construction of Grammar for a Turing Machine
Ex. Consider a Turing Machine described by Transition table.
Obtain inverse production rules (q1 is final state).

Present state ψ b 1
→ q1 ψRq1 - bRq2
q2 - - bRq1

Sol. q1 is both initial & final state.


1. Productions corresponding to right moves
2. a. Productions corresponding to left end: [b → [
b. Productions corresponding to right end: bb] → b], 1b] → 1],
q1 ] → q1 b], q2 ] → q2 b]
3. 1 → [q1 ψ1 // ai → [q1 ψai ∀ai ∈ τ, ai ̸= b
1 → 1$] // ai → ai $] ∀ai ∈ τ, ai ̸= b
[q1 b] → S // for removing brackets from [qf b]

Department of CSE Module 4 March 6, 2025 30/33


Unrestricted Grammars

Inverse productions are obtained by reversing the arrows of the


production:
ψq1 → q1 c, bq2 → q1 1, bq1 → q2 1
[→ [b, b] → bb], 1] → 1b]
q1 b → q1 ], q2 b → q2 ], [q1 c1 → 1
1$] → 1, S → [q1 b]

Department of CSE Module 4 March 6, 2025 31/33


Questions?
[email protected]
Thank you.

You might also like