Unit - 5 Svce
Unit - 5 Svce
2|F L A T - U N I T - V
BTECH_IT-SEM 31
SVCE TIRUPATI
1. Course Objectives
Formal definitions of machine models.
1. Classify machines by their power to recognize languages.
2. Understanding of formal grammars, analysis
3. Understanding of hierarchical organization of problems depending on their
complexity
4. Understanding of the logical limits to computational capacity
5. Understanding of un-decidable problems
2. Prerequisites
Students should have knowledge on
1. Discrete Mathematics
2. Basic Mathematics
3. Syllabus
UNIT V
Turing Machines and Undecidability: Basics of Turing Machine (TM), Transitional
Representation of TMs, Instantaneous description, Non Deterministic TM, Conversion
of Regular Expression to TM, Two stack PDA and TM, Variations of the TM, TM as an
integer function, Universal TM, Linear Bounded Automata, TM Languages,
Unrestricted grammar, Properties of Recursive and Recursively enumerable
languages, Undecidability, Reducibility, Undecidable problems about TMs,
Post‘s Correspondence Problem(PCP), Modified PCP.
4. Course outcomes
1. At the end of the course, students will be able to
2. Construct finite state diagrams while solving problems of computer science
3. Find solutions to the problems using Turing machines
4. Design of new grammar and language
3|F L A T - U N I T - V
BTECH_IT-SEM 31
SVCE TIRUPATI
5. Co-PO / PSO Mapping
Machine
PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 P1 PO11 PO12 PSO1 PSO2
Tools
CO1 2 3 2 3 2 3
CO2
CO3 3 3 2
CO4 3 2 2 3 3 2 3
6. Lesson Plan
Lecture
Weeks Topics to be covered References
No.
1 Basics of Turing Machine (TM) T1, R1
2 Transitional Representation of TMs T1, R1
1
3 Instantaneous description T1, R1
4 Non-Deterministic TM T1, R1
5 Conversion of Regular Expression to TM T1, R2
6 Two stack PDA and TM T1, R1
2
7 Variations of the TM, TM as an integer function T1, R1
8 Universal TM, Linear Bounded Automata T1, R1
9 TM Languages, Unrestricted grammar T1, R1
Properties of Recursive and Recursively enumerable
10 T1, R1
3 languages
11 Undecidability, Reducibility, Undecidable problems T1, R1
12 Post‘s Correspondence Problem(PCP), Modified PCP T1, R1
4|F L A T - U N I T - V
BTECH_IT-SEM 31
SVCE TIRUPATI
Limitations of Pushdown Automata:
B B. W1. W2 Wn B B
FEATURES OF TM:
5|F L A T - U N I T - V
BTECH_IT-SEM 31
SVCE TIRUPATI
• The machine can produce certain output based on its input. In this machine there is
no distinction between input and output symbols.
• The TM can be thought of as a finite state automata connected to a read or write
head,
• It has one tape which is divided into a number of cells. Each cell can store only one
symbol.
• The read or write head can examine one cell at a time.
• In one move the machine examine the present symbol under the head on the tape
and present state of an automaton to determine:
• A new symbol should be written on the tape in the cell under the head
• The head moves one cell either left(L) or right(R), The next state of the automata.
• Whether to halt or not.
DEF: TURING MACHINE:
• ID of TM is (l,q,r) where
• l- tape contents left to the head of TM
• r- tape contents right to the head of TM including the symbol under head and
• q- current state
• Ex:
6|F L A T - U N I T - V
BTECH_IT-SEM 31
SVCE TIRUPATI
• Where l=ab l=abb
r=abb r=bb
Moves: At any given time the move of TM depends on i) Current state and ii) input
symbol i.e., (q,a). the o/p of move would be (q1, b, L) Where q1 = next state, b= symbol
to be replaced by a and L= move left one symbol.
Ex: δ( qi,a)= ( qj,b,L) i.e., in the state qi on receiving a symbol a , then change to a new
state qj , replace a by b and the move left.
B B B a b b A B B B
Current state= q0
B B B X b b A B B B
Current state= q0
B B B X b b A B B B
Current state= q0
7|F L A T - U N I T - V
BTECH_IT-SEM 31
SVCE TIRUPATI
B B B X b b A B B B
Current state= q0
B B B X b b X B B B
Current state= q0
B B B X b b X B B B
Current state= q1
B B B X b b X B B B
Current state= q1
B B B X b Y X B B B
Current state= q1
B B B X Y Y X B B B
Current state= q1
B B B X Y Y X B B B
Current state= q1
δ( q1,B)= (q2,B,H)
REPRESENTATION OF TM:
δ a b X Y B
8|F L A T - U N I T - V
BTECH_IT-SEM 31
SVCE TIRUPATI
Representation of TM using Transition Diagram: The states are represented by vertices and
transitions are represented by directed edges. The edges are labeled in the form of (α ,β,
γ) or α →β, γ where α(∈T) is the current input symbol, β(∈T) is the symbol to be replaced
with α and γ={L,R}. The TM for the above example is as
Ex: Design a TM to recognize all strings consisting of even no of a’s defined over {a}
Transition Diagram
Transition Table
δ a B
q0 (q1,a,R) (q2,B,H)
q1 (q0,a,R) --
q2 -- --
9|F L A T - U N I T - V
BTECH_IT-SEM 31
SVCE TIRUPATI
Ex: Design TM to accept strings belonging to the language (0+1)*
Transition Diagram
Transition Table
Transition Diagram
δ 0 1 B
Transition Diagram
10|F L A T - U N I T - V
BTECH_IT-SEM 31
SVCE TIRUPATI
Transition Table
δ 0 1 B
q1 (q1,0,L) (q2,1,L) --
q3 -- -- --
Ex: Construct a TM for language consisting of strings having any no of b’s and even no of
a’s defined over {a,b}.
Design a TM to accept strings formed with 0 and 1 and having substring 000
11|F L A T - U N I T - V
BTECH_IT-SEM 31
SVCE TIRUPATI
Ex: Design a TM to accept strings formed on {0,1} and ending with 000
Transition Diagram
12|F L A T - U N I T - V
BTECH_IT-SEM 31
SVCE TIRUPATI
Transition Table:
Transition Diagram
13|F L A T - U N I T - V
BTECH_IT-SEM 31
SVCE TIRUPATI
Transition Diagram
14|F L A T - U N I T - V
BTECH_IT-SEM 31
SVCE TIRUPATI
15|F L A T - U N I T - V
BTECH_IT-SEM 31
SVCE TIRUPATI
16|F L A T - U N I T - V
BTECH_IT-SEM 31
SVCE TIRUPATI
5.7 TM AS INTEGER FUNCTION:
A Turing machine M computes a function f if, when given input w in the domain of f, the
machine halts in its accept state with f(w) written (leftmost) on the tape. To use TM as a
computational machine, it is required to place the integer numbers as 0m.
Suppose it is required to add two numbers; that is, f(m, n) = m + n, then the numbers m
and n are to be placed on the tape as 0m10n where 1 is a separator for the numbers m
and n. Once processing is completed and the TM halts, the tape would have the
contents as 0(m+n), which is the required result of computation.
Sol: Let the numbers be 2 and 3. The addition of these numbers using simple logic is
explained. The numbers are placed as B02103B.
After processing, the tape content would be B05B. The simple logic that can be used is:
replace the occurrence of 0 by B and move to right and replace 1 to 0, so that it is in
required form as B05B.
17|F L A T - U N I T - V
BTECH_IT-SEM 31
SVCE TIRUPATI
18|F L A T - U N I T - V
BTECH_IT-SEM 31
SVCE TIRUPATI
• Multi-tape Turing Machines have multiple tapes where each tape is accessed with
a separate head. Each head can move independently of the other heads. Initially
the input is on tape 1 and others are blank. At first, the first tape is occupied by the
input and the other tapes are kept blank. Next, the machine reads consecutive
symbols under its heads and the TM prints a symbol on each tape and moves its
heads.
• Depending on the present state and i/p symbol scanned by each of the head, the
TM can Change its state.
• Write a new symbol on the respective cell of the respective tape from where the
i/ps were scanned, Move the head one left/right.
19|F L A T - U N I T - V
BTECH_IT-SEM 31
SVCE TIRUPATI
Def: A Multi-tape Turing machine can be formally described as a 7-tuple (Q, T, ∑, δ, q0,B,
F) where
B is a blank symbol
Ex: Design a Multi tape TM for checking whether a binary string is a palindrome or not
Sol: Consider a TM with two tapes. The i/p is written on the first tape.
Copy the i/p from the first tape to the second tape by traversing the first tape from
left to right.
20|F L A T - U N I T - V
BTECH_IT-SEM 31
SVCE TIRUPATI
Traverse from the first tape again from right to left and point the head to the first
symbol of i/p on tape 1.
Moves the two heads pointing on the two tapes in opposite directions checking
that the two symbols are identical and erasing the copy in tape2 at the same time.
A multi-head Turing machine contains two or more heads to read the symbols on the
same tape. In one step all the heads sense the scanned symbols and move or write
independently.
21|F L A T - U N I T - V
BTECH_IT-SEM 31
SVCE TIRUPATI
• In general in a TM, there is a left boundary. If the head crosses that boundary and
wants to go left, then the situation is called a crash condition. But the head may
traverse the right side up to infinity. In this sense, the i/p tape of the general TM can
be treated as a one-way infinite tape.
22|F L A T - U N I T - V
BTECH_IT-SEM 31
SVCE TIRUPATI
• A TM where there is infinite number of sequences of blank on both sides of the tape
is called a two-way infinite tape TM. A typical diagram of the i/p tape of a two-way
infinite TM is:
-- -- -- B B a a b b B B -- --
• It has multi-dimensional tape where head can move any direction that is left, right,
up or down.
• Multi-dimensional tape Turing machine can be simulated by one-dimensional Turing
machine.
• The i/p tape of 1-D TM is extended to infinite in both sides, but in one direction. If the
i/p tape can be extended infinitely in more than one dimension, then the TM is
called a multi-dimensional TM.
• In general case, consider k=2, which means that the i/p tape is extended to
infinitely in right and down directions. For this case, the read/write head can move
in the left, right, up and down directions.
• The transition function for a K-dimensional TM is δ:QX∑→QXTX{L,R,U,D,H} where
L=Left, R-Right, U-Up and D-Down.
A non-deterministic Turing machine has a single, one way infinite tape. For a given state
and input symbol has at least one choice to move (finite number of choices for the next
move), each choice several choices of path that it might follow for a given input string. A
non-deterministic Turing machine is equivalent to deterministic Turing machine
23|F L A T - U N I T - V
BTECH_IT-SEM 31
SVCE TIRUPATI
Q-finite set of states
B∈ T -blank symbol (every cell is filled with B except input alphabet initially)
Ex: Design a TM for 0n1m, where m,n>0 and n may not be equal to m
Enumerator: It is a type of TM which is attached a printer. It has a work tape and an o/p
tape. The work tape is a write only once tape. At each step, the machine chooses a
symbol to write from the output alphabet on the output tape.
After writing a symbol on the output tape, the head placed on the output moves right
by one position. The enumerator has a special state, say qp , entering which the output
tape is erased and the tape head moves to the leftmost position and finally the string is
printed. A string w is printed as o/p by the enumerator if the o/p tape contains w at the
time the machine enters in to qp.
24|F L A T - U N I T - V
BTECH_IT-SEM 31
SVCE TIRUPATI
• The binary code for the Turing machine is M which has transitions t1, t2, t3,....tn is
represented as 111t111t211t311....11tn111.
• Note: The transitions need not be in any particular order.
25|F L A T - U N I T - V
BTECH_IT-SEM 31
SVCE TIRUPATI
• If a string has to be verified then the problem is represented as a tuple <M,w>
where M is the definition of TM and w is the input string.
• Ex: Let M=({q1,q2,q3}, {0,1}, {0.1.B}, δ, q1, B,{q2}) have moves defined as δ(q1, 1)=
(q3, 0,R), δ(q3, 0)= (q1, 1,R), δ(q3, 1)= (q2, 0,R), δ(q3, B)= (q3, 1,L).
• Give the problem representation for the string w=1011
• Sol: Let binary representation for states{q1,q2,q3}be {0,00,000}, alphabet {0,1,B} be
{0,00,000} and direction {R,L} be {0,00}. The transitions are represented as follows:
• For any input M and w, Tape 1 will keep an encoded definition of M, Tape 2 will
contain the tape contents of M and Tape 3, the internal state of M. Mu looks first
at the contents of Tapes 2 and 3 to determine the configuration of M. The behavior
of the M is as follows.
• 1. Check the format of Tape 1 for the validations of the TM model.
a. No two transitions should begin with Oi1Oj1 for the same i and j.
b. Check that if Oi1Oj1Ok1Ol1Om represents a transition, then 1 < j < 3, 1 < l <
26|F L A T - U N I T - V
BTECH_IT-SEM 31
SVCE TIRUPATI
• 2. Initialize Tape 2 to contain w. Initialize Tape 3 to hold a single O representing initial
state q1. For all the tapes, the tape heads are positioned at the left end and these
symbols are marked to identify the starting position.
• 3. When Tape 3 holds OO, it is said to reach the final state, and the machine can
halt.
• 4. Let at any given time aJ be the symbol currently scanned by tape head 2 and let
Oi, the contents of Tape 3 (which indicates state). Scan Tape 1 from the left end to
the second 111 looking for a substring beginning with 11Oi1Oj1.
a. if no such string is found, then halt and reject.
b. if found, then let the suffix be Ok1Ol1Om11. Put Ok on Tape 3, print a on the tape cell
scanned by head 2 and move the head in direction Dm.
• It is clear that Mu accepts <M, w> if and only if M accepts w. It is also true that if M
runs forever on w, Mu runs forever on <M, w> and if M halts on w without
accepting, Mu also halts on w without accepting.
RECURSIVE AND RECURSIVELY ENUMERABLE LANGUAGES:
• There are three possible outcomes of executing a TM over a given input. The TM
may halt and accept the input Halt and Reject the input or Never Halt.
• Recursive Language: A language is recursive if there exists a TM that accepts every
string of the language and rejects every string (over the same alphabet) that is not
in the language.
• Note: If a language L is recursive, then its complement L1 must also be recursive.
• Recursively Enumerable Language: A language is recursively enumerable if there
exists a TM that accepts every string of the language and does not accept the
strings that are not in the language (i.e., strings may be rejected or may cause the
TM to go into an infinite loop).
• Note: Every recursive language is also recursively enumerable but the converse
need not be true.
• Union: If L1 and If L2 are two recursive languages, their union L1∪L2 will also be
recursive because if TM halts for L1 and halts for L2, it will also halt for L1∪L2.
27|F L A T - U N I T - V
BTECH_IT-SEM 31
SVCE TIRUPATI
• Concatenation: If L1 and If L2 are two recursive languages, their concatenation
L1.L2 will also be recursive.
• Ex: L1= {anbncn|n>=0}
• L2= {dmemfm|m>=0}
• L3= L1.L2= { anbncn dmemfm :m>=0 and n>=0} is also recursive.
• Kleene Closure: If L1is recursive, its kleene closure L1* will also be recursive. For
Example: L1= {anbncn|n>=0} L1*= ({anbncn|n>=0} )* is also recursive
• Intersection and complement: If L1 and If L2 are two recursive languages, their
intersection L1 ∩ L2 will also be recursive. Similarly, complement of recursive
language L1 which is ∑*-L1, will also be recursive.
• The complement of a recursive language is recursive.
• The union of two recursive languages is recursive.
• The union of two recursively Enumerable languages is recursively enumerable.
• If L is a recursive language then Σ*-L is recursive
5.8 Linear Bounded Automata (LBA)
28|F L A T - U N I T - V
BTECH_IT-SEM 31
SVCE TIRUPATI
• In the theory of computation, we often come across such problems that are
answered either 'yes' or 'no'. The class of problems which can be answered as 'yes'
are called solvable or decidable. Otherwise, the class of problems is said to be
unsolvable or undecidable.
• Decidable: A decision problem which can be solved by an algorithm is called
decidable. All the languages recognized by TM are decidable.
• Ex: Given two numbers x and y, does x evenly divides y?
• Decidable: A decision problem A is called decidable or effectively solvable if A is a
recursive set.
• Partially decidable: A problem is called partially decidable/semi decidable/
solvable/ provable if A is a recursively enumerable set.
• Undecidable: Partially decidable problems and any other problems that are not
decidable are called undecidable.
• Post Correspondence Problem (PCP): one method to test undecidability is using
TMs. The other method of testing undecidability of the string is with the help of Post's
Correspondence Problem (PCP). Let us define the PCP.
• "The Post's correspondence problem consists of two lists of strings that are of equal
length over the input. The two lists are A = w1, w2, w3, .... , wn and B = x1, x2, x3, ....
xn then there exists a non empty set of integers i1, i2, i3, .... , in n>=1 such that, w1,
w2, w3, .... wn = x1, x2, x3, .... xn"
• To solve the post correspondence problem we try all the combinations of i1, i2, i3,
.... , in to find the wi = xi then we say that PCP has a solution and is decidable
otherwise PCP is undecidable.
• Consider the following sequence and find whether it has a solution (decidable) or
not.
i List A List B
1 1 111
2 10111 10
3 10 0
Sol:
29|F L A T - U N I T - V
BTECH_IT-SEM 31
SVCE TIRUPATI
• If we take 1 then A starts with 1 and B also starts with 1, but for the next two
characters in A, there is no matching sequence.
• So we starts with 2. i.e., i=2 Therefore
i 2
Wi 10111
Xi 10
i 2 1 String
Wi 10111 1 101111
Xi 10 111 10111
i 2 1 1 String
Wi 10111 1 1 1011111
i 2 1 1 3 String
Wi 10111 1 1 10 101111110
• Length of first string = second string, Hence stop the procedure and declare the
sequence 2113 as a solution. Therefore it is decidable.
MPCP: MODIFIED VERSION OF PCP:
BTECH_IT-SEM 31
SVCE TIRUPATI
• and a solution is a list of 0 or more integers i1,i2,i3,...ip such that
w1,wi1,wi2,...wip=x1,xi1,xi2,...xip.
• The difference between the MPCP and PCP is that in the MPCP, a solution required
to start with the first string on each list.
• If we have a problem instance represented in MPCP then it can be reduced to
PCP. If there is a solution for PCP instance then there exists a solution for MPCP
instance.
• Procedure to convert MPCP to PCP or Reduction of MPCP to PCP:
• Let the list G and H be the given instance of MPCP
• Let Σ be the smallest alphabet containing all the symbols in the list G and H.
• Consider two special symbols {θ, $} not present in Σ and find two new lists X from G
and Y from H using the following rules.
• xi of list X is obtained from gi by inserting $ symbol after each character of gi.
• yi of list Y is obtained from hi by inserting $ symbol before each character of hi.
• Create new words as follows. x0=$g1, y0=h1, xk+1= θ, yk+1=$θ.
31|F L A T - U N I T - V
BTECH_IT-SEM 31
SVCE TIRUPATI
9. Practice Quiz
1. Graphical representation of a derivation is called --------------
A) production rules B) parse tree C)Derivation tree
2. CFLs are not closed under
A) concatenation B) union C) Kleen closure
3. LBA accepts _____________language.
A) CSL B) CFL C) RL
4. Grammar is said to be in CNF iff
A) NT->NT NT B) NT-> t NT C) NT-> any no. of NT
5. A Turing Machine contains_________tuples.
A) 6 B) 7 C) 5
6. If A is reducible to B and B is undecidable then_________
A) A is Decidable B) B is Decidable C) A is Un decidable
7. PDA make use of ------------
A) list B) queue C) stack
8. If PCP is decidable then MPCP is____________
A) decidable B) undecidable C) Cannot say
9. Which type of TM is attached to a printer ?
A) Enumerator B) Multi-tape TM C) Multi-head TM
10 CFG is used in ________________________
A) Translators B) assemblers C) Compilers
32|F L A T - U N I T - V
BTECH_IT-SEM 31
SVCE TIRUPATI
10. Assignments
S. No Question BL CO
Design a Turing Machine that accepts the language L = {an bn |
n ≥1}. Give the graphical representation for the Turing Machine
1 5 5
obtained and also show the moves made by the Turing machine
for the string ‘aabb’. [June-2018]
Give the formal definition of a Turing Machine. With a diagram,
2 4 5
explain the Turing Machine model. [June-2018]
Explain in brief about any five variations of the basic TM model.
3 3 5
[Nov/Dec-2019]
Design a Turing machine to accept the following language:
4 6 5
L = {0n 1n 2n |n ≥ 1} [Nov/Dec-2018]
5 Explain in detail about universal TM. [June/July-2019] 3 5
33|F L A T - U N I T - V
BTECH_IT-SEM 31
SVCE TIRUPATI
S. No Question BL CO
Design a Turing Machine that accepts the language L = {an bn |
n ≥1}. Give the graphical representation for the Turing Machine
1 5 5
obtained and also show the moves made by the Turing machine
for the string ‘aabb’. [June-2018]
Give the formal definition of a Turing Machine. With a diagram,
2 4 5
explain the Turing Machine model. [June-2018]
Explain in brief about any five variations of the basic TM model.
3 3 5
[Nov/Dec-2019]
Design a Turing machine to accept the following language:
4 6 5
L = {0n 1n 2n |n ≥ 1} [Nov/Dec-2018]
5 Explain in detail about universal TM. [June/July-2019] 3 5
34|F L A T - U N I T - V
BTECH_IT-SEM 31