Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Unit V Undecidability

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 23

125

UNIT V
UNDECIDABILITY
A language that is not Recursively Enumerable (RE) – An undecidable
problem that is RE – Undecidable problems about Turing Machine – Post’s
Correspondence Problem - The classes P and NP.

5.1. BASIC DEFINITIONS


5.1.1 Decidable Problem:
If and only if there exists an algorithm to solve the problem in finite time
and determine whether the answer is ‘yes’ or ‘no’.

5.1.2. Undecidable Problem:


If and only if there exists no algorithm to solve the problem in infinite
time and determine whether the answer is ‘yes’ or ‘no’.

5.1.3. Recursive Language:


A language is recursive if there exists a TM that accepts every string of
the language and rejects every string that is not in the language.

5.1.4. Recursively Enumerable Language:


A language is recursively enumerable if there exists a TM that accepts
every string of the language, and does not accept strings that are not in the
language. The strings that are not in the language may be rejected and it may
cause the TM to go to an infinite loop.

5.2. A LANGUAGE THAT IS NO T RECURSIVELY


ENUMERABLE
A language L is recursively enumerable if L = L(M) for some TM M.
Recursive or decidable languages that are not only recursively enumerable, but
are accepted by a TM.
To prove undecidable, the language consisting of pairs(M, w) such that;
126

(1) M is a Turing Machine (suitably coded, in binary) with input alphabet


{0, 1}.
(2) ‘w’ is a string of 0’s and 1’s.
(3) M accepts input ‘w’.
If this problem with inputs restricted to the binary alphabet is
undecidable, then surely the more general problem, where TM’s may have any
alphabet, is undecidable.

5.2.1. Enumerating the Binary Strings:


To assign integers to all the binary strings so that each string corresponds
to one integer, and each integer corresponds to one string.

5.2.2. Codes for Turing Machines:


A binary code for Turing Machines so that each TM with input alphabet
{0, 1} may be thought of as a binary string.
To represent a TM M = (Q, {0, 1}, Γ, , q1, B, F) as a binary string, we
must first assign integers to the states, tape symbols and directions L and R.
• We shall assume the states are q1, q2, ……., qk for some ‘k’. The start
state will always be ‘q1’ and ‘q2’ will be the only accepting state. Note
that, since we may assume the TM halts whenever it enters an accepting
state, there is never any need for more than one accepting state.
• We shall assume the tape symbols are X1,X2,…..,Xm for some ‘m’. X1
always be the symbol ‘0’, X2 will be ‘1’ and X3 will be B. However,
other tape symbols can be assigned to the remaining integers arbitrarily.
• We shall refer to direction L as D1 and direction R as D2.
Once we have established an integer to represent each state, symbol and
direction, we can encode the transition function ‘δ’. Suppose one transition rule
is δ(qi, Xj) = (qk, Xl, Dm), for some integers i, j, k, l and m. We shall code this
i j k l m
rule by the string 0 1o 1o 1o 1o .

5.2.3. The Diagonalization Language (Ld):


The undecidable problem can be proved by the method of
diagonalization. Construct a list of words over (0, 1)* in canonical order, where
th
‘wi’ is the i word and Mj is TM. This can be represented as a table.
127

Construct a language Ld using the diagonal entries. The value’0’ means,


wi is not in L(Mj) and ‘1’ means wi is in L(Mj).
To construct Ld, we complement the diagonal. For instance, the
complemented diagonal would begin 1,0,0,0,…… The trick of complementing
the diagonal to construct the characteristic vector of a language that cannot be the
language that appears in any row, is called diagonalization.

Proof that Ld is not Recursively Enumerable:


Theorem:
Ld is not a recursively enumerable language. That is, there is no Turning
Machine that accepts Ld.
Proof:
Suppose Ld were L(M) for some TM M. Since Ld is a language over
alphabet {0,1}, M would be in the list of TM’s we have constructed, since it
includes all TM’s with input alphabet {0,1}. Thus, there is atleast one code for
M, say ‘i’, that is, M=Mi.
• If wi is in Ld, then Mi accepts wi. But then, by definition of Ld, wi is not
in Ld, because Ld contains only those wi such that Mj does not accept wj.
• Similarly, if wi is not in Ld, then Mi does not accept wi. Thus, by
definition of Ld, wi is in Ld.
Since wi can neither be in Ld nor fail to be in Ld, we conclude that there is a
contradiction of our assumption that M exists. That is, Ld is not a recursively
enumerable language.

PROBLEM:
Ex:
Obtain the code for (M, 1011) where M = ({q1, q2, q3}, {0, 1}, {0,1,B},
δ, q1, B, {q2}), δ is,
128

δ(q1, 1) = (q3, 0, R) δ(q3, 1) = (q2, 0, R)


δ(q3, 0) = (q1, 1, R) δ(q3, B) = (q3, 1, L)
Soln:
1 – represented as two zero’s
0 – represented as one zero
L – represented as one zero
R – represented as two zero’s
B – represented as threee zero’s
(M, 1011) = 0 | 00 | 000 | 0 | 00 || 000 | 0 | 0 | 00 | 00 || 000 | 00 | 00 | 0 | 00 || 000 |
000 | 000 | 00 | 0

5.3. AN UNDECIDABLE PROBLEM THAT IS RE


5.3.1. Recursive Language:
A language L recursive if L=L(M) for some TM M such that;
1. If ‘w’ is in L, then accepts.
2. If ‘w’ is not in L, then M eventually halts, although it never enters an
accepting state.
If we think of the language L as a “problem” as will be the case
frequently, then problem L is called decidable if it is a recursive language, and it
is called undecidable if it is not a recursive language.

5.3.2. Complements of Recursive and RE languages:


Theorem:
If L is a recursive language, so is L .
Proof:
Let L = L(M) for some TM M that always halts. We construct a TM M
such that L = L( M ) by the construction.

That is, M behaves just like M. However, M is modified as follows to create


M;
(1) The accepting states of M are made non accepting states of M with no
transitions, ie., in these states M will halt without accepting.
(2) M has a new accepting state ‘r’; there are no transitions from ‘r’.
(3) For each combination of a non accepting state of M and a tape symbol of
M such that M has no transition (ie., M halts without accepting), add a
transition to the accepting state ‘r’.

Theroem:
If L and L are recursively enumerable then L is recursive.
Proof:
Let M1 be the L and M2 be the L . Construct M to simulate M1 and M2
simultaneously, since ‘w’ is either in L or L .
M accepts ‘w’ if M1 accepts it and M rejects ‘w’ if M2 accepts it. Thus
M will always say either “Accept” or “reject”. Since M is accepts L. Thus L is
recursive.

The important consequences of the properties that we have seen are,


If L and L are complementary then only one of the following should be
true.
(1) Both L and L are recursive.
(2) Neither L nor L is recursively enumerable.
(3) One of the L is recursively enumerable and other is not recursively
enumerable.

5.3.3. The Universal Language:


We define Lu, the universal language, to be the set of binary strings that
encode in the pair (M,w), where M is a TM with the binary input alphabet, and
‘w’ is a string in (0, 1)*, such that ‘w’ is in L(M). That is, Lu is the set of strings
130

representing a TM and an input accepted by that TM. We shall show that there is
a TM U, often called the universal Turing Machine such that Lu = L(U).
• It is easiest to describe U as a multitape TM.
• In the case of U, the transitions of M are stored initially on the first tape,
doing with the string ‘w’.
• A second tape will be used to hold the simulated tape of M, using the
same format as for the code of M.
• That is, tape symbol Xi of M will be represented by 0i, and tape symbols
will be separated by single 1’s.
• The third tape of U holds the state of M, with state qi represented by ‘i’,
0’s.

The operation of U can be summarized as follows;


(1) Examine the input to make sure that the code for M is a legitimate code
for some TM. If not, U halts without accepting. Since invalid codes are
assumed to represent the TM with no moves, and such a TM accepts to
inputs.
(2) Initialize the second tape to contain the input ‘w’, in its encoded form.
That is, for each ‘0’ of ‘w’, place 10 on the second tape, and for each ‘1’
of ‘w’, place 100 there. Note that the blanks on the simulated tape of M,
which are represented by 1000.
(3) Place ‘0’, the start state of M, on the third tape, and move the head of U’s
second tape to the first simulated cell.
(4) To simulate a move of M.
131

(5) If M has no transition that matches the simulated state and tape symbol,
then no transition will be found. Thus, M halts in the simulated
configuration.
(6) If M enters its accepting state, then U is accepts.

5.3.4. Undecidability of the Universal Language:


Theorem:
Universal Language Lu is not recursive.

Proof:
We know that Ld is not recursive, by reducing Ld to Lu.

• Assume that Lu is recursive. Then Ld must be recursive too.

• Since we know that L is not recursive we can conclude that L is not


d u
recursive.
• Construct an algorithm for Lu which accepts (Mi, wi) if wi is in L(Mi).
Thus we have an Ld . This is contradiction. Hence Lu is not recursive.

5.4. UNDECIDABLE PROBLEMS ABOUT TURING MACHINES


5.4.1. Turing Machines that accept the Empty language:
In this, we are using two languages, called Le and Lne. Each consists of
binary strings. If ‘w’ is a binary string, then it represents some TM, Mi.
If L(Mi) = , that is, Mi does not accept any input, then ‘w’ is in Le.
Thus, Le is the language consisting of all those encoded TM’s whose language is
empty. On the other hand, if L(Mi) is not the empty language, then ‘w’ is in Lne.
Thus, Lne is the language of all codes for Turing Machines that accept atleast one
input string. Define the two languages are,
• Le = {M | L(M) = }
• Lne = {M | L(M) ≠ }
Theorem:
Lne is recursively enumerable.
Proof:
In this, a TM that accepts Lne. It is easiest to describe a non deterministic
TM M.

The operation of M is as follows;


(1) M takes as input a TM code Mi.
(2) Using its nondeterministic capability, M guesses an input ‘w’, that Mi
might accept.
(3) M test whether Mi accepts ‘w’. For this part, M can simulate the
Universal TM U that accepts Lu.
(4) If Mi accepts ‘w’, then M accepts its own input, which is Mi.
If Mi accepts even one string M will guess that string and accept Mi.
However, if L(Mi) = , then no guess ‘w’ leads to acceptance by Mi, so M does
not accept Mi. Thus, L(M) = Lne.

Theorem:
Lne is not recursive.
Proof:
In this, we must design an algorithm that converts an input that is a
binary coded pair(M, w) into a TM M’ such that L(M’) ≠ if and only if M
accepts input ‘w’. The construction of M’ is shown in following fig.

If M does not accept ‘w’, then M’ accepts none of its input’s, ie., L(M’)
= . However, if M accepts w, then M’ accepts every input, and thus L(M’)
surely is not . M’ is designed to do the following;
(1) M’ ignores its own input ‘x’. Rather it replaces its input by the string
that represents TM M and input string ‘w’. Since M’ is designed for a
specific pair (M, w) which has some length n, we may construct M’ to
have a sequence of states q0,q1,……,qn, where q0 is the start state.
a. In state qi, for i=0, 1, ……, n-1, M’ writes the (i+1), bit of the
code for (M, w) goes to state qi+1, and moves right.
b. In state qn, M’ moves right, if necessary replacing any nonblanks
by blanks.
(2) When M’ reaches a blank in state qn, it uses a similar collection of states
to reposition its head at the left end of the tape.
(3) Now, using additional states, M’ simulates a universal TM U on its
present tape.
(4) If U accepts, then M’ accepts. If U never accepts, then M’ never accepts
either.

5.4.2. Rice’s Theorem and Properties of the RE Languages:


All nontrivial properties of the RE languages are undecidable, that is, it is
impossible to recognize by a TM. The property of the RE languages is simply a
set of RE languages. The property of being empty is the set { ) consisting of
only the empty language.
A property is trivial if it is either empty, or is all RE languages.
Otherwise, it is nontrivial.

Theorem: (Rice’s Theorem)


Every nontrivial property of the RE languages is undecidable.
Proof:
Let P be a nontrivial property of the RE languages. Assume to begin that
, the empty language, is not in P. Since, P is nontrivial, there must be some
nonempty language L that is in P. Let ML be a TM accepting L.
We shall reduce Lu to Lp, thus proving that Lp is undecidable , since Lu
is undecidable. The algorithm to perform the reduction takes as input a pair (M,
w) and produces a TM M’. The design of M’ is given by the following fig.
L(M’) is if M does not accept ‘w’, and L(M’) = L if M accepts ‘w’. L(M’) = L
if M accepts w. The TM M’ is constructed to do the following;
(1) Simulate M on input ‘w’. Note that ‘w’ is not the input to M’; rather M’
writes M and ‘w’ onto one of its tapes and simulates the universal TM U
on that pair.
(2) If M does not accept ‘w’, then M’ does nothing else. M’ never accepts
its own input, x, so L(M’)= . Since we assume is not in property P,
that means the code for M’ is not in LP.
(3) If M accepts w, then M’ begins simulating ML on its own input ‘x’.
Thus M’ will accept exactly the language L. Since L is in P, the code for
M’ is in LP.
We observe that constructing M’ from M and ‘w’ can be carried out by an
algorithm. Since this algorithm turns (M, w) into an M’ that is in LP if and only
if (M, w) is in Lu, this algorithm is a reduction of Lu to Lp and proves that the
property P is undecidable.

5.5. POST’s CORRESPONDENCE PROBLEM


In this section, we will discuss the undecidability of strings and not of
Turing Machines. The undecidability of strings is determined with the help of
Post’s Correspondence Problem(PCP).
Our goal is to prove this problem about strings to be undecidable, and
then use its undecidability to prove other problems undecidable by reducing PCP
to those.

5.5.1. Definition of Post’s Correspondence Problem:


An instance of Post’s Correspondence Problem(PCP) consists of two
lists of strings over some alphabet Σ; the two lists must be of equal length. We
generally refer to the A and B lists, and write A = w1, w2, …… wk and B =
x1, x2, ……. xk, for some integer ‘k’. For each ‘i’, the pair (wi, xi) is said to be a
corresponding pair.
We say this instance of PCP has a solution, if there is a sequence of one
or more integers i1,i2…..im that, when interpreted as indexes for strings in the A
and B lists, yield the same string. That is, wi1, wi2,……..wim = xi1, xi2,………xim.
We say the sequence i1,i2, ….., im is a solution to this instance of PCP.

Ex.1:
Consider the correspondence system as given bellows,

Does this PCP have a


solution?
Soln:
In this case, PCP has a solution. We find, wi1, wi2,……..wim = xi1,
xi2,………xim
Let m = 4, ie) i1 = 2, i2 = 1, i3 = 1, i4 = 3
(2) (1) (1) (3)
List A: 10111 1 1 10
List B: 10 111 111 0
ie) wi1, wi2,……..wim = xi1, xi2,………xim
101111110 = 101111110
∴ The solution list is {2, 1, 1, 3}

Ex.2:
Consider the correspondence system as given bellows,
Does this PCP have a
solution?
Soln:
In this case, PCP has a solution. We find, wi1, wi2,……..wim = xi1,
xi2,………xim
Let m = 6, ie) i1 = 1, i2 = 2, i3 = 1, i4 = 3, i5 = 3, i6 = 4
(1) (2) (1) (3) (3) (4)
List A: 1 0 1 010 010 11
List B: 10 10 10 01 01 1
ie) wi1, wi2,……..wim = xi1, xi2,………xim
10101001011 = 10101001011
∴ The solution list is {1, 2, 1, 3, 3, 4}

Ex.3:
Consider the correspondence system as given bellows,

Does this PCP have a solution?

Soln:
In this case, PCP has no solution. Suppose that the PCP instance has a
solution, then we say, wi1, wi2,……..wim = xi1, xi2,………xim. But in this case,
it would not have the equal string [∴ wi ≠ xi]. So we find the partial solution.
ie) If i1 = 1, i2 = 3, then the two corresponding strings from lists A and B would
have to begin.
List A: 10101 …...
List B: 101011…..
ie) wi1, wi2,……..wim = xi1, xi2,………xim
10101 ≠ 101011
∴ The two strings can never become equal.

5.5.2. The Modified PCP (MPCP):


• It is easier to reduce Lu to PCP, if we first introduce an intermediate
version of PCP, which we call the Modified Post’s Correspondence
Problem or MPCP.
• In the Modified PCP, there is the additional requirement on a solution
that the first pair on the A and B lists must be the first pair in the
solution.
• An instance of MPCP is two lists A = w1, w2, …… wk and B = x1, x2,
……. xk, and a solution is a list of ‘0’ or more integers i1,i2…..im such
that, w1wi1wi2,……..wim = x1xi1xi2,………xim.
• Notice that the pair (w1, x1) is forced to be at the beginning of the two
strings, even though the index ‘1’ is not mentioned at the front of the list
that is the solution.
• Unlike PCP, where the solution has to have atleast one integer on the
solution list, in MPCP the empty list could be a solution, if w1 = x1.

Ex:
Consider the correspondence system as given bellows,

Does this MPCP have a


solution?
Soln:
In this case, MPCP has no solution. In proof, observe that any partial
solution has to begin with index 1, so the two strings of a solution would begin;
List A: 1 …...
List B: 111…..
Thus, the next index would have to be ‘1’ yielding;
List A: 11 …...
List B: 111111 …..
ie) wi1, wi2,……..wim = xi1, xi2,………xim
11 ≠ 111111
∴ The solution list is {1, 1}
∴ The B string remains three times as long as the A string, and the two
strings can never become equal.

5.5.3. Reducing MPCP to PCP:


An instance of MPCP with alphabet Σ, we construct an instance of PCP
C=y0,y1,……yk+1, and D=z0,z1,……..zk+1 as follows;
(1) First, we introduce a new symbol ‘*’ that, in the PCP instance, goes
between every symbol in the strings of the MPCP instance. For
i=1,2,…..k, let yi be wi with a ‘*’ after each symbol of wi, and let zi be xi
with a ‘*’ before each symbol of xi.
th
(2) y0 = *y1, and z0 = z1. That is, the o pair looks like pair1, expect that
there is an extra ‘*’ at the beginning of the string from the first list.
(3) A final pair ($, *$) is added to the PCP instance, yk+1 = $ and zk+1 = *$

Ex:
An instance of MPCP is defined as,

Construct an instance of PCP?


Soln:
Theorem:
MPCP reduces to PCP.
Proof:
First, suppose that i1,i2…..im is a solution to the given MPCP instance
with lists A and B. Then we know w1wi1wi2,……..wim = x1xi1xi2,………xim. If
we were to replace the w’s by y’s and the x’s by z’s, we would have two strings
that were almost the same, y1,yi1, yi2,……yim, and z1,zi1, zi2,……..zim.
The difference is that the first string would be missing a ‘*’ at the
beginning, and the second would be missing a ‘*’ at the end. That is,
*y1,yi1, yi2,……yim = z1,zi1, zi2,……..zim*
However, y0 = *y1 and z0 = z1, so we can fix the initial ‘*’ by replacing
the first index by ‘0’.
*y0,yi1, yi2,……yim = z0,zi1, zi2,……..zim*
We can take care of the final ‘*’ by appending the index k+1. Since yk+1
= $, and zk+1 = *$, we have:
y0,yi1, yi2,…… yim, yk+1 = z0,zi1, zi2,…….. zim, zk+1
We show that 0,i1,i2, ….. im,k+1 is a solution to the instance of PCP. We
claim that i1,i2…..im is a solution to the MPCP instance. The reason is that if we
remove the *’s and the final $ from the strings,
y0yi1 yi2,…… yimyk+1 = z0zi1 zi2,…….. zim zk+1
we get w1wi1wi2,……..wim = x1xi1xi2,………xim.

5.5.4. Completion of the Proof of PCP Undecidability:


To complete the chain of reductions by reducing Lu to MPCP. That is,
given a pair (M, w), we construct an instance (A, B) of MPCP such that TM M
accepts input ‘w’ if and only if (A, B) has a solution.
140

The essential idea is that MPCP instance (A, B) simulates, in its partial
solutions, the computation of M on input ‘w’. Let M = (Q, Σ, Γ, δ, q0, B, F) be a
TM and let w in Σ* be an input string. We construct an instance of MPCP as
follows;
(1) The first pair is:
List A List B
# #q0w#
This pair, which must start any solution according to the rules of MPCP,
begins the simulation of M on input ‘w’.
(2) Tape symbols and the separator # can be appended to both lists. The pairs,
List A List B
X X
# # for each X in Γ.
(3) To simulate a move of M, we have certain pairs that reflect those moves.
For all ‘q’ in Q-F, p in Q, and X, Y and Z in Γ we have;
List A List B
qX Yp if δ(q, X) = (p, Y, R)
zqX pZY if δ(q, X) = (p, Y, L); ‘Z’ is an tape
symbol
q# yp# if δ(q, B) = (p, Y, R)
zq# pZY# if δ(q, B) = (p, Y, L); ‘Z’ is an tape
symbol
(4) If the ID at the end of the B string has an accepting state, then we need to
allow the partial solution to become a complete solution. Thus, if ‘q’ is an
accepting state, then for all tape symbols ‘X’ and ‘Y’ there are pairs;
List A List B
XqX q
XqY q
YqX q
YqY q
Xq q
Yq q
qX q
qY q
(5) Finally, once the accepting state has consumed all tape symbols, it stands
alone as the last ID on the string. That is the remainder of the two strings
is q#. We use the final pair;
141

List A List B
q## #

Ex:
Consider the TM M and w=01, where M=({q1, q2, q3}, {0,1}, {0,1,B}, δ,
q1, B, {q3}) and δ is given by,
qi δ(qi, 0) δ(qi, 1) δ(qi, B)
→q1 (q2, 1, R) (q2, 0, L) (q2, 1, L)
q2 (q3, 0, L) (q1, 0, R) (q2, 0, R)
*q3 - - -

Reduce the above problem to PCP and find whether that PCP has a solution or
not?
Soln:
Rule List A List B Source
(1) # #q101#
0 0
(2) 1 1
# #
q10 1q2 From δ(q1, 0) = (q2, 1, R)
0q11 q200 From δ(q1, 1) = (q2, 0, L)
1q11 q210 From δ(q1, 1) = (q2, 0, L)
0q1# q201# From δ(q1, B) = (q2, 1, L)
(3) 1q1# q211# From δ(q1, B) = (q2, 1, L)
0q20 q300 From δ(q2, 0) = (q3, 0, L)
1q20 q310 From δ(q2, 0) = (q3, 0, L)
q21 0q1 From δ(q2, 1) = (q1, 0, R)
q2# 0q2# From δ(q2, B) = (q2, 0, R)
0q30 q3
0q31 q3
1q30 q3
(4) 1q31 q3
0q3 q3
1q3 q3
q30 q3
q31 q3
(5) q3## #

Now find the sequence of partial solutions, that mimics this computation
of M and eventually leads to a solution.
(1) A: #
B: #q101#
(2) A: #q101#
B: #q101#1q21#
(3) A: #q101#1q21#
B: #q101#1q21#10q1#
(4) A: #q101#1q21#10q1#
B: #q101#1q21#10q1#1q201#
(5) A: #q101#1q21#10q1#1q201#
B: #q101#1q21#10q1#1q201#q3101#
(6) A: #q101#1q21#10q1#1q201#q3101#
B: #q101#1q21#10q1#1q201#q3101#q301#
(7) A: #q101#1q21#10q1#1q201#q3101#q301#
B: #q101#1q21#10q1#1q201#q3101#q301#q31#
(8) A: #q101#1q21#10q1#1q201#q3101#q301#q31#
B: #q101#1q21#10q1#1q201#q3101#q301#q31#q3#

With only q3 left in the ID, we can use the pair (q3##, #) from rule(5) to finish the
solution.
A: #q101#1q21#10q1#1q201#q3101#q301#q31#q3##
B: #q101#1q21#10q1#1q201#q3101#q301#q31#q3##
∴ The PCP has a solution. Because it produces same string on
list A and list B.

Theorem:
Post’s Correspondence Problem is undecidable.
Proof:
The construction of this section shows how to reduce Lu to MPCP. Thus,
we complete the proof of undecidability of PCP by proving that the construction
is correct, that is;
M accepts ‘w’ if and only if the constructed MPCP instance has a
solution. If ‘w’ is in L(M), then we can start with the pair(M, w) from rule1 to
rule5, allow the A string to catch up to the B string and form a solution.
In particular, as long as M does not enter an accepting state, the partial
solution is not a solution the B string is longer than the A string. Thus, if there is
a solution, M must at some point enter an accepting state. That is M accepts w.

5.6. THE CLASSES P AND NP


The classes P and NP of problems solvable in polynomial time by
deterministic and nondeterministic TM’s and the technique of polynomial
time reduction. Also define the notion of “NP-Completeness”.

5.6.1. Problems Solvable in Polynomial Time:


A TM M is said to be of time complexity T(n). If whenever M is given
an input ‘w’ of length ‘n’, M halts after making atmost T(n) moves, regardless of
whether or not M accepts. Then the language L is in class P if there is some
polynomial T(n) such that L = L(M) for some deterministic TM M of time
complexity T(n).

5.6.1.1. An Example: Kruskal’s Algorithm:


Kruskal’s algorithm focus on finding a Minimum-Weight Spanning
Tree(MWST) for a graph.
Spanning Tree:
A spanning tree is a subset of the edges such that all nodes are connected
through these edges, yet there are no cycles.

MWST:
A Minimum-Weight Spanning Tree has the least possible total edge
weight of all spanning trees. There is a well-known “Greedy Algorithm”, called
Kruskal’s algorithm, for finding a MWST.
Procedure:
(1) Identify the minimal edge connected component.
(2) Find the minimal edge if both the vertices belong to different connected
component then add the edge.
(3) Identify minimal edge, if that edge connects both the vertices in the same
component then leave the edge. (Otherwise it will form a cycle).
(4) Repeat the process until all the vertices are found.
Ex:
Find the MWST using Kruskal’s algorithm.

Soln:
(1) First consider the edge (1, 3) because it has the lowest weight 10.

(2) The next minimal edge is (2, 3), with weight 12. Since 2 and 3 are in
different components, we accept this edge and add the node 2 into first
connected component. ie;

(3) The third edge is (1, 2) with weight 15. However, 1 and 2 are now in the
same component, so we reject this edge and proceed to the fourth edge
(3. 4). ie;
(4) Now, we have three edges for the spanning tree of a 4-node graph and so
may stop.

When we translate the above ideas to TM’s, we face several issues:


• When we deal with TM’s, we may only think of problems as languages,
and the only output is Yes or No(ie., Accept or Reject). For instance, the
MWST problem could be couched as: “Given this graph G and limit
weight ‘W’ or less?
• While we might think informally of the “size” of a graph as the number
of its nodes or edges, the input to a TM is a string over a finite alphabet.
Thus, problem elements such as nodes and edges must be encoded
suitably.

5.6.2. Nondeterministic Polynomial Time:


A fundamental class of problems can be solved by a nondeterministic
TM that runs in polynomial time. A language L is in the class NP
(Nondeterministic Polynomial) if there is a nondeterministic TM M and a
polynomial time complexity T(n) such that L = L(M), and when M is given an
input of length ‘n’, there are no sequences of more than T(n) moves of M.

5.6.2.1. An NP Example: The Traveling Salesman Problem:


The input to Traveling Salesman Problem TSP) is the same as to MWST,
a graph with integer weights on the edges and a weight limit W.
A Hamilton Circuit is a set of edges that connect the nodes into a single
cycle, with each node appearing exactly once. Note that the number of edges on
a Hamilton Circuit must equal the number of nodes in the graph.
Ex:
Find Travelling Salesman Problem for the graph,
Soln:
Hamilton Circuit: The cycle (1, 2, 4, 3, 1). The total weight of this cycle
is 15+20+18+10 = 63. Thus if ‘w’ is 63 or more, the answer is “yes”, and if
w<63 the answer is “no”.

5.6.3. Polynomial Time Reductions:

In this, to prove the statement “if P2 is in P, then so is P1”.


• For the proof, suppose that we can decide membership in P2 of a string of
k
length ‘n’ in time O(n ). Then we can decide membership in P1 of a
j j k j
string of length ‘m’ in time O(m + (cm ) ) time; the term m accounts for
j k
the time to do the translation, and the term (cm ) accounts for the time to
decide the resulting instance of P2.
j
• Simplifying the expression, we see that P1 can be solved in time O(m +
j k
(cm ) ). Since c, j and k are all constants, this time is polynomial in ‘m’,
and we conclude P1 is in P.
• A reduction from P1 to P2 is polynomial time if it takes time that is some
polynomial in the length of the P1 instance. Note that as a consequence,
the P2 instance will be of a length that is polynomial in the length of the
P1 instance.

5.6.4. NP – Complete Problems:


Let L be a language(problem) in NP, we say L is NP-Complete if the
following statements are true about L;
(1) L is in NP.
(2) For every language L’ in NP there is a polynomial – time reduction of L’
to L.
An example of NP- Complete problem is the Travelling Salesman
Problem. Since it appears that P≠NP, all the NP-Complete problems are in NP –
P, we generally view a proof of NP – Completeness for a problem as a proof that
the problem is not in P.

Theorem:
If P1 is NP-Complete, and there is a Polynomial – time reduction of P1 to
P2, then P2 is NP – Complete.
Proof:
To show that every language L in NP Polynomial – time reduces to P2.
We know that there is a polynomial time reduction of L to P1, this reduction
takes some polynomial time P(n). Thus, a string ‘w’ in L of length ‘n’ is
converted to a string ‘x’ in P1 of length atmost P(n).
Also know that there is a polynomial time reduction of P1 to P2; Let this
reduction take polynomial time q(m). Then this reduction transforms ‘x’ to some
string ‘y’ in P2, taking time atmost q(p(n)).
Thus, the transformation of ‘w’ to ‘y’ takes time atmost p(n)+q(p(n)),
which is a polynomial. We conclude that L is polynomial time reducible to P2.
Since L could be any language in NP, we have shown that all of NP polynomial –
time reduces to P2; that is, P2 is NP-Complete.

You might also like