You are on page 1of 4

UNIT V NP COMPLETE AND NP HARD

A problem is in the class NPC if it is in NP and is as hard as any problem in NP. A


problem is 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 problems, all problems in NP would be polynomial time solvable.
These problems are called NP-complete. The phenomenon of NP-completeness is
important for both theoretical and practical reasons.

Definition of NP-Completeness
A language B is NP-complete if it satisfies two conditions
 B is in NP
 Every A in NP is polynomial time reducible to B.

If a language satisfies the second property, but not necessarily the first one, the
language B is known as NP-Hard. Informally, a search problem B is NP-Hard if there
exists some NP-Complete problem A that Turing reduces to B.
The problem in NP-Hard cannot be solved in polynomial time, until P = NP. If a
problem is proved to be NPC, there is no need to waste time on trying to find an
efficient algorithm for it. Instead, we can focus on design approximation algorithm.

NP-Complete Problems
Following are some NP-Complete problems, for which no polynomial time algorithm
is known.

 Determining whether a graph has a Hamiltonian cycle


 Determining whether a Boolean formula is satisfiable, etc.

NP-Hard Problems
The following problems are NP-Hard

 The circuit-satisfiability problem


 Set Cover
 Vertex Cover
 Travelling Salesman Problem

TSP is NP-Complete
The traveling salesman problem consists of a salesman and a set of cities. The salesman
has to visit each one of the cities starting from a certain one and returning to the same
city. The challenge of the problem is that the traveling salesman wants to minimize the
total length of the trip

Proof
To prove TSP is NP-Complete, first we have to prove that TSP belongs to NP. In TSP,
we find a tour and check that the tour contains each vertex once. Then the total cost of
the edges of the tour is calculated. Finally, we check if the cost is minimum. This can be
completed in polynomial time. Thus TSP belongs to NP.
Secondly, we have to prove that TSP is NP-hard. To prove this, one way is to show
that Hamiltonian cycle ≤p TSP (as we know that the Hamiltonian cycle problem is
NPcomplete).
Assume G = (V, E) to be an instance of Hamiltonian cycle.
Hence, an instance of TSP is constructed. We create the complete graph G' = (V, E'),
where
$$E^{'}=\lbrace(i, j)\colon i, j \in V \:\:and\:i\neq j$$
Thus, the cost function is defined as follows −
$$t(i,j)=\begin{cases}0 & if\: (i, j)\: \in E\\1 & otherwise\end{cases}$$
Now, suppose that a Hamiltonian cycle h exists in G. It is clear that the cost of each
edge in h is 0 in G' as each edge belongs to E. Therefore, h has a cost of 0 in G'. Thus, if
graph G has a Hamiltonian cycle, then graph G' has a tour of 0 cost.
Conversely, we 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 therefore conclude that h' contains only edges in E.
We have thus proven that G has a Hamiltonian cycle, if and only if G' has a tour of cost
at most 0. TSP is NP-complete.

Polynomial Time Verification


Before talking about the class of NP-complete problems, it is essential to introduce the notion of a
verification algorithm.

Many problems are hard to solve, but they have the property that it easy to authenticate the solution if
one is provided.
Hamiltonian cycle problem:-
Consider the Hamiltonian cycle problem. Given an undirected graph G, does G have a cycle that visits
each vertex exactly once? There is no known polynomial time algorithm for this dispute

Fig: Hamiltonian Cycle

Let us understand that a graph did have a Hamiltonian cycle. It would be easy for someone to convince
of this. They would similarly say: "the period is hv3, v7, v1....v13i.

We could then inspect the graph and check that this is indeed a legal cycle and that it visits all of the
vertices of the graph exactly once. Thus, even though we know of no efficient way to solve the
Hamiltonian cycle problem, there is a beneficial way to verify that a given cycle is indeed a Hamiltonian
cycle.

Definition of Certificate: - A piece of information which contains in the given path of a vertex is known
as certificate

Relation of P and NP classes


1. P contains in NP
2. P=NP

1. Observe that P contains in NP. In other words, if we can solve a problem in polynomial time, we
can indeed verify the solution in polynomial time. More formally, we do not need to see a
certificate (there is no need to specify the vertex/intermediate of the specific path) to solve the
problem; we can explain it in polynomial time anyway.
2. However, it is not known whether P = NP. It seems you can verify and produce an output of the
set of decision-based problems in NP classes in a polynomial time which is impossible because
according to the definition of NP classes you can verify the solution within the polynomial time.
So this relation can never be held.
Reductions:
The class NP-complete (NPC) problems consist of a set of decision problems (a subset of class NP) that no
one knows how to solve efficiently. But if there were a polynomial solution for even a single NP-complete
problem, then every problem in NPC will be solvable in polynomial time. For this, we need the concept of
reductions.

Suppose there are two problems, A and B. You know that it is impossible to solve problem A in
polynomial time. You want to prove that B cannot be explained in polynomial time. We want to show
that (A ∉ P) => (B ∉ P)

Consider an example to illustrate reduction: The following problem is well-known to be NPC:

3-color: Given a graph G, can each of its vertices be labeled with one of 3 different colors such that two
adjacent vertices do not have the same label (color).

Coloring arises in various partitioning issues where there is a constraint that two objects cannot be
assigned to the same set of partitions. The phrase "coloring" comes from the original application which
was in map drawing. Two countries that contribute a common border should be colored with different
colors.

It is well known that planar graphs can be colored (maps) with four colors. There exists a polynomial
time algorithm for this. But deciding whether this can be done with 3 colors is hard, and there is no
polynomial time algorithm for it.

Example of 3-colorable and non-


3- colorable graphs.

Polynomial Time Reduction:


We say that Decision Problem L1 is Polynomial time Reducible to decision Problem L2 (L1≤p L2) if there is a
polynomial time computation function f such that of all x, xϵL1 if and only if xϵL2.

You might also like