Halting Problem and Rice Theorem
Halting Problem and Rice Theorem
,
have an algorithm) if the language L of all yes instances to P is decidable.
Example- (I) (Acceptance problem for DFA) Given a DFA does it accept a
given word? (II) (Emptiness problem for DFA) Given a DFA does it accept
any word? (III) (Equivalence problem for DFA) Given two DFAs, do they
accept the same language?
Example 1
Find out whether the following problem is decidable or not −
Is a number ‘m’ prime?
Solution
Prime numbers = {2, 3, 5, 7, 11, 13, …………..}
Divide the number ‘m’ by all the numbers between ‘2’ and ‘√m’ starting
from ‘2’.
If any of these numbers produce a remainder zero, then it goes to the
“Rejected state”, otherwise it goes to the “Accepted state”. So, here the
answer could be made by ‘Yes’ or ‘No’.
Hence, it is a decidable problem.
Example 2
Given a regular language L and string w, how can we check if w ∈ L?
Solution
Take the DFA that accepts L and check if w is accepted
Some more decidable problems are −
Undecidable Languages
For an undecidable language, there is no Turing Machine which accepts
the language and makes a decision for every input string w (TM can make
decision for some input string though). A decision problem P is called
“undecidable” if the language L of all yes instances to P is not decidable.
Undecidable languages are not recursive languages, but sometimes, they
may be recursively enumerable languages.
Example
The halting problem of Turing machine
Solution: Let us assume that we can design that kind of machine called as
HM(P, I) where HM is the machine/program, P is the program and I is the
input. On taking input the both arguments the machine HM will tell that the
program P either halts or not.
If we can design such a program this allows us to write another program we
call this program CM(X) where X is any program(taken as argument) and
according to the definition of the program CM(X) shown in the figure.
In the program CM(X) we call the function HM(X), which we have already
defined and to HM() we pass the arguments (X, X), according to the
definition of HM() it can take two arguments i.e one is program and another
is the input.Now in the second program we pass X as a program and X as
input to the function HM().We know that the program HM() gives two output
either “Halt” or “Not Halt”.But in case second program, when HM(X, X) will
halt loop body tells to go in loop and when it doesn’t halt that means loop, it
is asked to return.
Now we take one more situation where the program CM is passed to CM()
function as an argument. Then there would be some impossibility, i.e., a
condition arises which is not possible.
It is impossible for outer function to halt if its code (inner body) is in loop and
also it is impossible for outer non halting function to halt even after its inner
code is halting. So the both condition is non halting for CM machine/program
even we had assumed in the beginning that it would halt.So this is the
contradiction and we can say that our assumption was wrong and this
problem, i.e., halting problem is undecidable.
This is how we proved that halting problem is undecidable.
Rice Theorem
Rice theorem states that any non-trivial semantic property of a language
which is recognized by a Turing machine is undecidable. A property, P, is
the language of all Turing machines that satisfy that property.
Formal Definition
undecidable.
property P.
A property is called to be trivial if either it is not satisfied by
any recursively enumerable languages, or if it is satisfied by all
recursively enumerable languages.
A non-trivial property is satisfied by some recursively
Proof
Suppose, a property P is non-trivial and φ ∈ P.
Since, P is non-trivial, at least one language satisfies P, i.e., L(M 0) ∈ P , ∋
Turing Machine M0.
Let, w be an input in a particular instant and N is a Turing Machine which
follows −
On input x
Run M on w
If M does not accept (or doesn't halt), then do not accept x (or do
not halt)
If M accepts w then run M0 on x. If M0 accepts x, then accept x.
A function that maps an instance ATM = {<M,w>| M accepts input w} to a
N such that
L(M0) ∈ p
If M accepts w and N accepts the same language as M 0, Then L(M) =
NP-completeness
The Non-deterministic Polynomial (NP) problems were a little harder
to understand. In terms of solving a NP problem, the run-time is not
polynomial. It would be something like O(n!) or something larger.
However, this class of problems are given a specific solution, and
checking the solution would have a polynomial run-time.
For example, the Sudoku game.
NP-Hard Problems
A problem is said to be NP-Hard when an algorithm for solving NP Hard
can be translated to solve any NP problem. Then we can say, this problem
is at least as hard as any NP problem, but it could be much harder or
more complex.
NP-Complete Problems
NP-Complete (NPC) problems are problems that are present in both the
NP and NP-Hard classes. That is NP-Complete problems can be verified in
polynomial time and any NP problem can be reduced to this problem in
polynomial time.
A problem is in class NPC if it is in NP and is as hard as any problem in NP.
A problem is said to be NP-hard if all problems in NP are polynomial time
reducible to it, even though it may not be in NP itself.
If a polynomial time algorithm exists for any of these types of problems,
all problems in NP can be polynomial time solvable. These problems are
called NP-complete. NPcompleteness is important for both theoretical and
practical reasons.
Definition of NP-Completeness
A language M is NP-complete, if it satisfies the two conditions which are
given below
M is in NP.
Every A in NP is polynomial time reducible to M.
NP-Complete Problems
Examples of NP-Complete problems where no polynomial time algorithm
is known are as follows −
Determining whether a graph has a Hamiltonian cycle
Determining whether a Boolean formula is satisfactory, etc.
NP-Hard Problems
The following problems are NP-Hard
The circuit-satisfiability problem
Set Cover
Vertex Cover
Travelling Salesman Problem
Example
Given below is an example of the Hamilton cycle path −
TSP is NP-Complete
The travelling salesman problem (TSP) is having a salesman and a set of
cities. The salesman needs to visit each one of the cities starting from a
certain one and returning to the same city i.e. back to starting position.
The challenge of this problem is that the travelling salesman wants to
minimise the total length of the trip.
Proof
To prove TSP is NP-Complete, first try to prove TSP belongs to Non-
deterministic Polynomial (NP).
In TSP, we have to find a tour and check that the tour contains each
vertex once.
Then, we calculate the total cost of the edges of the tour. Finally, we
check if the cost is minimum or not. This can be done in polynomial time.
Therefore, TSP belongs to NP.
Next, we have to prove that TSP is NP-hard.
To prove this, one way is to show that the Hamiltonian cycle ≤p TSP (as
we know that the Hamiltonian cycle problem is NP Complete).
Assume G = (V, E) to be an instance of the Hamiltonian cycle.
Hence, an instance of TSP is constructed. We can create the complete
graph G' = (V, E'), where
E′={(i,j):i,j∈Vandi≠j
Thus, the cost function is defined as follows:
t(i,j)= 0 if (i,j) ∈ E
=1 otherwise
Now, assume that a Hamiltonian cycle H exists in G. The cost of each
edge in H is 0 in G' as each edge belongs to E. Therefore, H is having a
cost of 0 in G'. Thus, if graph G has a Hamiltonian cycle, then graph G'
has a tour of 0 cost.
Now let us assume that G' has a tour H’ of cost at most 0. The cost of
edges in E' are 0 and 1 by definition. Hence, each edge must have a cost
of 0 as the cost of H’ is 0. We finally conclude that H' contains only edges
in E.
Finally proved that G has a Hamiltonian cycle, if and only if G' has a tour
of cost at most 0. TSP is NP-complete.