UNIT - V
Types of Turing machine: Turing machines and halting
Undecidability: Undecidability, A Language that is Not Recursively Enumerable, An
Undecidable
Problem That is RE, Undecidable Problems about Turing Machines, Recursive
languages, Properties of recursive languages, Post's Correspondence Problem,
Modified Post Correspondence problem,
Other Undecidable Problems, Counter machines.
Variation of Turing Machine
1. Two-way infinite Tape Turing Machine:
Infinite tape of two-way infinite tape Turing machine is unbounded in both
directions left and right.
Two-way infinite tape Turing machine can be simulated by one-way infinite
Turing machine (standard Turing machine).
2. Multiple track Turing Machine:
A k-track Turing machine (for some k>0) has k-tracks and one R/W head that
reads and writes all of them one by one.
A k-track Turing Machine can be simulated by a single track Turing machine
3. Non-deterministic Turing Machine:
A non-deterministic Turing machine has a single, one way infinite tape.
For a given state and input symbol has atleast 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.
4. Multi-dimensional Tape Turing Machine:
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
5. Multi-tape Multi-head Turing Machine:
The multi-tape Turing machine has multiple tapes and multiple heads
Each tape controlled by separate head
Multi-Tape Multi-head Turing machine can be simulated by standard Turing
machine.
6. Multi-tape Turing Machine:
It has multiple tapes and controlled by a single head.
The Multi-tape Turing machine is different from k-track Turing machine but
expressive power is same.
Multi-tape Turing machine can be simulated by single-tape Turing machine.
7. Multi-head Turing Machine:
A multi-head Turing machine contain 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.
Multi-head Turing machine can be simulated by single head Turing machine.
Introduction to Undecidability
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.
Recursive and Recursive Enumerable Languages in TOC
Recursive Enumerable (RE) or Type -0 Language
RE languages or type-0 languages are generated by type-0 grammars. An RE language can
be accepted or recognized by Turing machine which means it will enter into final state for the
strings of language and may or may not enter into rejecting state for the strings which are not
part of the language. It means TM can loop forever for the strings which are not a part of the
language. RE languages are also called as Turing recognizable languages.
Recursive Language (REC)
A recursive language (subset of RE) can be decided by Turing machine which means it will
enter into final state for the strings of language and rejecting state for the strings which are
not part of the language. e.g.; L= {a nbncn|n>=1} is recursive because we can construct a turing
machine which will move to final state if the string is of the form a nbncn else move to non-final
state. So the TM will always halt in this case. REC languages are also called as Turing
decidable languages. The relationship between RE and REC languages can be shown in
Figure 1.
Closure Properties of Recursive Languages
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.
Concatenation: If L1 and If L2 are two recursive languages, their concatenation L1.L2 will
also be recursive.
For Example:
L1= {anbncn|n>=0}
L2= {dmemfm|m>=0}
L3= L1.L2 = {a nbncndmemfm|m>=0 and n>=0} is also recursive.
L1 says n no. of a’s followed by n no. of b’s followed by n no. of c’s. L2 says m no. of d’s
followed by m no. of e’s followed by m no. of f’s. Their concatenation first matches no. of
a’s, b’s and c’s and then matches no. of d’s, e’s and f’s. So it can be decided by TM.
Kleene Closure: If L1is recursive, its kleene closure L1* will also be recursive. For
Example:
L1= {a nbncn|n>=0}
L1*= { a nbncn||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. For Example:
L1= {anbncndm|n>=0 and m>=0}
L2= {anbncndn|n>=0 and m>=0}
L3=L1 ∩ L2
= { anbncndn |n>=0} will be recursive.
L1 says n no. of a’s followed by n no. of b’s followed by n no. of c’s and then any no. of d’s.
L2 says any no. of a’s followed by n no. of b’s followed by n no. of c’s followed by n no. of d’s.
Their intersection says n no. of a’s followed by n no. of b’s followed by n no. of c’s followed by
n no. of d’s. So it can be decided by turing machine, hence recursive.
Similarly, complement of recursive language L1 which is ∑*-L1, will also be recursive.
Note: As opposed to REC languages, RE languages are not closed under complementation
which means complement of RE language need not be RE.
Post Correspondence Problem
In this section, we will discuss the undecidability of string and not of Turing machines. The
undecidability of the string is determined with the help of Post's Correspondence Problem
(PCP). Let us define the PCP.
"The Post's correspondence problem consists of two lists of string 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 such that, w1, w2, w3, .... wn = x1, x2,
x3, .... xn"
To solve the post correspondence problem we try all the combinations of i 1, i2, i3, .... , in to
find the w1 = x1 then we say that PCP has a solution.
Example 1:
Consider the correspondence system as given below
A = (b, bab3, ba) and B = (b3, ba, a). The input set is ∑ = {0, 1}. Find the solution.
Solution:
A solution is 2, 1, 1, 3. That means w2w1w1w3 = x2x1x1x3
The constructed string from both lists is bab 3b3a.
Example 2:
Does PCP with two lists x = (b, a, aba, bb) and y = (ba, ba, ab, b) have a solution?
Solution: Now we have to find out such a sequence that strings formed by x and y are
identical. Such a sequence is 1, 2, 1, 3, 3, 4. Hence from x and y list
Example 3:
Obtain the solution for the following system of posts correspondence problem. A = {100,
0, 1},
B = {1, 100, 00}
Solution: Consider the sequence 1, 3, 2 the string obtained from A = babababb. The
string obtained from B = bababbbb. These two strings are not equal. Thus if we try various
combination from both the sets to find the unique sequence, we could not get such a
sequence. Hence there is no solution for this system.
Example 4:
Obtain the solution for the following system of posts correspondence problem, X = {100,
0, 1}, Y = {1, 100, 00}.
Solution: The solution is 1, 3, 1, 1, 3, 2, 2. The string is
X1X3X1X1X3X2X2 = 100 + 1 + 100 + 100 + 1 + 0 + 0 = 1001100100100
Y1Y3Y1Y1Y3Y2Y2 = 1 + 00 + 1 + 1 + 00 + 100 + 100 = 1001100100100
Example 5:
Let A = {001,0011,11,101} and B= {01,111,111,010}.
Similarly.
let C = {00,001,1000} and D = {0,11,011}.
Which of the following pairs have a post-correspondence solution?
1. Only pair (A, B)
2. Only pair (C, D)
3. Both (A, B) and (C, D)
4. Neither (A, B) nor (C, D)
Answer : 1. Only pair (A, B)
Question 102 Explanation
Before solving this question, let understand what is PCP problem.
The Post Correspondence Problem is to determine whether a collection of dominos has a match.
Given the following two lists, M and N of non-empty strings over ∑
M = (x1, x2, x3,………, xn)
N = (y1, y2, y3,………, yn)
We can say that there is a Post Correspondence Solution, if for some i 1,i2,..... ik, where 1 ≤ ij ≤ n, the condition
xi1 …….xik = yi1 …….yik satisfies.
Given data is :
A
A1 A2 A3 A4
001 0011 11 101
B
B1 B2 B3 B4
11
01 111 010
1
C
C1 C2 C3
00 001 1000
D
D1 D2 D3
0 11 011
Now, A convenient way to view an instance of a Post correspondence problem is as a collection of blocks of
the form
Ai
Bi
there being an unlimited supply of each type of block. Thus the given example is viewed as
A1 A2 A3 A4
00
0011 11 101
1
B1 B2 B3 B4
01 111 111 010
A, B have a PCP solution because
A3A4A1 = 11 . 101 . 001 = 11101001 = 111. 010 . 01 = B 3B4B1
Furthermore, since (3, 4, 1) is a solution, so are all of its "repetitions", such as (3, 4, 1, 3, 4, 1), etc.; that is,
when a solution exists, there are infinitely many solutions of this repetitive kind.
So, option 1 is correct answer
Chomsky Hierarchy
Chomsky Hierarchy represents the class of languages that are accepted by the different
machine. The category of language in Chomsky's Hierarchy is as given below:
1. Type 0 known as Unrestricted Grammar.
2. Type 1 known as Context Sensitive Grammar.
3. Type 2 known as Context Free Grammar.
4. Type 3 Regular Grammar.
This is a hierarchy. Therefore every language of type 3 is also of type 2, 1 and 0. Similarly,
every language of type 2 is also of type 1 and type 0, etc.
Type 0 Grammar:
Type 0 grammar is known as Unrestricted grammar. There is no restriction on the
grammar rules of these types of languages. These languages can be efficiently modeled
by Turing machines.
For example:
bAa → aa
S→s
Type 1 Grammar:
Type 1 grammar is known as Context Sensitive Grammar. The context sensitive grammar
is used to represent context sensitive language. The context sensitive grammar follows
the following rules:
o The context sensitive grammar may have more than one symbol on the left hand side of
their production rules.
o The number of symbols on the left-hand side must not exceed the number of symbols on
the right-hand side.
o The rule of the form A → ε is not allowed unless A is a start symbol. It does not occur on the
right-hand side of any rule.
o The Type 1 grammar should be Type 0. In type 1, Production is in the form of V → T
Where the count of symbol in V is less than or equal to T.
For example:
S → AT
T → xy
A→a
Type 2 Grammar:
Type 2 Grammar is known as Context Free Grammar. Context free languages are the
languages which can be represented by the context free grammar (CFG). Type 2 should
be type 1. The production rule is of the form
A→α
Where A is any single non-terminal and is any combination of terminals and non-terminals.
For example:
A → aBb
A→b
B→a
Type 3 Grammar:
Type 3 Grammar is known as Regular Grammar. Regular languages are those languages
which can be described using regular expressions. These languages can be modeled by
NFA or DFA.
Type 3 is most restricted form of grammar. The Type 3 grammar should be Type 2 and
Type 1. Type 3 should be in the form of
V → T*V / T*
For example:
A → xy
What are NP, P, NP-complete and NP-Hard problems?
P is a set of problems that can be solved by a deterministic Turing machine in Polynomial
time.
NP is set of decision problems that can be solved by a Non-deterministic Turing Machine
in Polynomial time. P is subset of NP (any problem that can be solved by a deterministic
machine in polynomial time can also be solved by a non-deterministic machine in polynomial
time).
Informally, NP is a set of decision problems that can be solved by a polynomial-time via a
“Lucky Algorithm”, a magical algorithm that always makes a right guess among the given set
of choices
NP-complete problems are the hardest problems in the NP set. A decision problem L is NP-
complete if:
1) L is in NP (Any given solution for NP-complete problems can be verified quickly, but there
is no efficient known solution).
2) Every problem in NP is reducible to L in polynomial time (Reduction is defined below).
A problem is NP-Hard if it follows property 2 mentioned above, doesn’t need to follow
property 1. Therefore, the NP-Complete set is also a subset of the NP-Hard set.
Travelling Sales Person Problem
The traveling salesman problems abide by a salesman and a set of cities. The salesman
has to visit every one of the cities starting from a certain one (e.g., the hometown) and to
return to the same city. The challenge of the problem is that the traveling salesman needs
to minimize the total length of the trip.
Suppose the cities are x1 x2..... xn where cost cij denotes the cost of travelling from city
xi to xj. The travelling salesperson problem is to find a route starting and ending at x 1 that
will take in all cities with the minimum cost.
Example: A newspaper agent daily drops the newspaper to the area assigned in such a
manner that he has to cover all the houses in the respective area with minimum travel
cost. Compute the minimum travel cost.
The area assigned to the agent where he has to drop the newspaper is shown in fig:
18.9M
359
Prime Ministers of India | List of Prime Minister of India (1947-2020)
Next
Stay
Solution: The cost- adjacency matrix of graph G is as follows:
costij =
The tour starts from area H1 and then select the minimum cost area reachable from H 1.
Mark area H6 because it is the minimum cost area reachable from H 1 and then select
minimum cost area reachable from H6.
Mark area H7 because it is the minimum cost area reachable from H 6 and then select
minimum cost area reachable from H7.
Mark area H8 because it is the minimum cost area reachable from H 8.
Mark area H5 because it is the minimum cost area reachable from H 5.
Mark area H2 because it is the minimum cost area reachable from H 2.
Mark area H3 because it is the minimum cost area reachable from H 3.
Mark area H4 and then select the minimum cost area reachable from H 4 it is H1.So, using
the greedy strategy, we get the following.
4 3 2 4 3 2 1 6
H1 → H6 → H7 → H8 → H5 → H2 → H3 → H4 → .
H1
Thus the minimum travel cost = 4 + 3 + 2 + 4 + 3 + 2 + 1 + 6 = 25
Canonical Collection of LR(0) items
An LR (0) item is a production G with dot at some position on the right side of the
production.
LR(0) items is useful to indicate that how much of the input has been scanned up to a
given point in the process of parsing.
In the LR (0), we place the reduce node in the entire row.
Example
Given grammar:
S → AA
A → aA | b
Add Augment Production and insert '•' symbol at the first position for every production in
G
S` → •S
S → •AA
A → •aA
A → •b
I0 State:
Add Augment production to the I0 State and Compute the Closure
I0 = Closure (S` → •S)
Add all productions starting with S in to I0 State because "•" is followed by the non-
terminal. So, the I0 State becomes
I0 = S` → •S
S → •AA
Add all productions starting with "A" in modified I 0 State because "•" is followed by the
non-terminal. So, the I0 State becomes.
I0= S` → •S
S → •AA
A → •aA
A → •b
I1= Go to (I0, S) = closure (S` → S•) = S` → S•
Here, the Production is reduced so close the State.
I1= S` → S•
I2= Go to (I0, A) = closure (S → A•A)
Add all productions starting with A in to I2 State because "•" is followed by the non-
terminal. So, the I2 State becomes
I2 =S→A•A
A → •aA
A → •b
Go to (I2,a) = Closure (A → a•A) = (same as I3)
Go to (I2, b) = Closure (A → b•) = (same as I4)
I3= Go to (I0,a) = Closure (A → a•A)
Add productions starting with A in I3.
A → a•A
A → •aA
A → •b
Go to (I3, a) = Closure (A → a•A) = (same as I3)
Go to (I3, b) = Closure (A → b•) = (same as I4)
I4= Go to (I0, b) = closure (A → b•) = A → b•
I5= Go to (I2, A) = Closure (S → AA•) = SA → A•
I6= Go to (I3, A) = Closure (A → aA•) = A → aA•
Drawing DFA:
The DFA contains the 7 states I0 to I6.