0% found this document useful (0 votes)
6 views

UNIT V

Uploaded by

vishnuvv112345
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

UNIT V

Uploaded by

vishnuvv112345
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

UNIT V - NP COMPLETE AND NP HARD

NP-Completeness: Polynomial Time – Polynomial-Time Verification – NP- Completeness and


Reducibility – NP-Completeness Proofs – NP-Complete Problems.

NP-Completeness:
Show that may of the problems with no polynomial time algorithms are computational time
algorithms are computationally related.
There are two classes of non-polynomial time problems
1. NP-Hard
2. NP-Complete
NP Hard and NP-Complete
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
In this context, now we will discuss TSP is NP-Complete
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

NP Completeness

P, NP, NP-Complete and NP-Hard are sets of problems, defined as follows:

 P: problems whose solution is polynomial time in the size of their inputs.


 NP: problems whose solutions can be verified in polynomial time. (NP stands
for non-deterministic polynomial time).
 NP-Complete: A collection of problems in NP whose solutions may or may not
polynomial time. We don't know. However, if we can prove that one of them may be
solved in polynomial time, then all of them can.
 NP-Hard: A collection of problems that do not have to be in NP, whose solutions are
at least as hard as the NP-Complete problems. If a problem is in NP, and it's NP hard,
then it is also NP-Complete.
In this lecture, we are going to see what it takes to prove that problems belong to these sets.
Suppose you have a problem to solve, and you want to know its complexity class. This takes
two steps:

1. Prove that it is in NP. Typically the problem is couched as a yes or no problem


involving a data structure, such as ``does there exist a simple cycle through a given
directed graph that visits all the nodes?'' To prove it is in NP, you need to show that
a yes solution can be checked in polynomial time. In the above example, you can
check to see if a given path through the graph is indeed a simple cycle in linear time.
Therefore, the problem is in NP. You don't have to prove anything about
the no solutions, and you don't have to prove anything about how you'd calculate a
solution.
2. Transform a known NP-Complete problem to this one in polynomial time. Suppose
the problem in question is Q, and that L is a well-known NP-Complete problem like
the 3-satisfiability problem. You need to show that if you have any instance of
problem L, you can transform it into an instance of problem Q in polynomial time.
Thus, if you could solve problem Q in polynomial time, you could solve problem L in
polynomial time.

If you can do both of these things, then you have proved that a problem is NP-Complete. If
you can prove that either of these things cannot be done, then you have proved that a problem
is not NP-Complete. Sometimes you can't come up with good proofs, and you just don't
know.

The complexity classes P and NP-Hard may be put in terms of the above:

 P: If we can prove that the solution to a problem may be calculated in polynomial


time, then the problem is in P. All of the algorithms that we have studied in this class,
with the exception of enumeration, are in P.
 NP-Hard: These are problems that are at least as hard to solve as NP-Complete
problems. If they are in NP, then they are NP-complete problems. We prove that a
problem is NP-Hard by performing the transformation in step 2 of a known NP-
Complete problem the problem at hand. That is how we demonstrate that they are "at
least as hard to solve as NP-Complete problems."

3-SAT - A Canonical NP-Complete Problem

3-SAT is a very simple NP-Complete problem. You are given a boolean expression, which is
a big AND (∧) of clauses:

E = C0 ∧ C1 ∧ ... ∧ Cm-1

Each clause Ci is the OR (∨) of three literals, where a literal is either a variable xi or the
negation of a variable ¬ xi (or sometimes the negation of a is denoted a). Here is an example
with three clauses and three variables. To make it easier to read, I'm simply calling the
variables a, b and c .

E=(a∨b∨c)∧(a∨b∨c)∧(a∨b∨c)
Given this definition, 3-SAT is simple -- is there an assignment of the variables so that E is
true? In the above example, it's easy to find such an assignment. For example, set a and c to
TRUE and b to FALSE (I'm coloring the true statements red -- you can see that there is
always at least one TRUE in each clause).

E=(a∨b∨c)∧(a∨b∨c)∧(a∨b∨c)

In general, 3-SAT can be a very difficult problem to solve. Here's a harder example with
seven clauses and four variables.

E=(a∨b∨c)∧(a∨b∨d)∧(a∨c∨d)∧(b∨c∨d)∧(a∨b∨c)∧(b∨c∨d)∧(
b∨c∨d)

One correct assignment is setting a and c to FALSE, and b and d to TRUE:

E=(a∨b∨c)∧(a∨b∨d)∧(a∨c∨d)∧(b∨c∨d)∧(a∨b∨c)∧(b∨c∨d)∧
(b∨c∨d)

From our lecture notes on enumeration, we can answer whether an instance of 3-SAT is true
or false with a simple power set enumeration. That enumerates all possible true/false settings
of the literals, and for each setting, you can test to see whether the expression is true. Of
course, if there are n literals, the power set enumeration will enumerate 2n settings, so this is
definitely not polynomial time.

Is there a polynomial time solution? No one knows.

It is an easy matter to prove that 3-SAT is in NP. How many different clauses can there be?
(4/3) * n * (n-1) * (n-2) -- we'll go over that in class. That's a polynomial of n. If we have a
solution, we can test its validity by simply setting the variables and seeing if E is true. That
test is polynomial time, so 3-SAT is in NP.

As for proving that 3-SAT is NP-Complete, that is well beyond the scope of this class.
However, 3-SAT is a very popular problem for proving that other problems are NP-
Complete.

The yellow nodes are an independent set of size 5. There is no independent set of size 6.

Here's how we use 3-SAT to prove that ISDP is NP-Complete.


First, prove it's in NP: If you give me a set of k vertices, I can easily check to verify that there
are no edges between two nodes in k. That will be O(|E|) in the worst case, which is most
definitely polynomial in |V|.

Next, I need to figure out how to take an instance of 3-SAT, and convert it into an instance of
ISDP, so that if you can solve the ISDP instance in polynomial time, then you can solve the
instance of 3-SAT in polynomial time. Here's one way:

 Turn each clause into three nodes, and label the nodes with their literals (including the
not). Add an edge between each of these nodes.
 For every pair of nodes with the same, but negated, literals, add an edge between that
pair of nodes.
 Any independent set of size k=n will correspond to an assignment of the literals for
which the 3-SAT expression is true.

Here's the simple three-clause 3-SAT problem above, converted to a graph, with an example
3-node independent set colored magenta. You'll note that the set corresponds to a setting of
the variables that makes the 3-SAT equation true:

Below, I also convert the more complicated 7-node expression to a graph for the ISDP
problem. I have the clauses clumped together going clockwise around the graph, starting at
roughly 1:00. I also have colored inter-clause edges according to the literals that they
connect:
I've colored the nodes in the Independent Set gray. You should be able to verify that:

 The set is indeed independent.


 The assignment of literals makes the expression true.

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.
Fig: 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.

NP-Completeness

A decision problem L is NP-Hard if

L' ≤p L for all L' ϵ NP.

Definition: L is NP-complete if

1. L ϵ NP and
2. L' ≤ p L for some known NP-complete problem L.' Given this formal definition, the
complexity classes are:

P: is the set of decision problems that are solvable in polynomial time.

NP: is the set of decision problems that can be verified in polynomial time.

NP-Hard: L is NP-hard if for all L' ϵ NP, L' ≤p L. Thus if we can solve L in polynomial time,
we can solve all NP problems in polynomial time.

NP-Complete L is NP-complete if

1. L ϵ NP and
2. L is NP-hard

If any NP-complete problem is solvable in polynomial time, then every NP-Complete problem
is also solvable in polynomial time. Conversely, if we can prove that any NP-Complete
problem cannot be solved in polynomial time, every NP-Complete problem cannot be solvable
in polynomial time.

Reductions

Concept: - If the solution of NPC problem does not exist then the conversion from one NPC
problem to another NPC problem within the polynomial time. For this, you need the concept
of reduction. If a solution of the one NPC problem exists within the polynomial time, then the
rest of the problem can also give the solution in polynomial time (but it's hard to believe). For
this, you need the concept of reduction.
Example: - 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 solved in polynomial time.
So you can convert the problem A into problem B in polynomial time.

Example of NP-Complete problem

NP problem: - Suppose a DECISION-BASED problem is provided in which a set of


inputs/high inputs you can get high output.

Criteria to come either in NP-hard or NP-complete.

1. The point to be noted here, the output is already given, and you can verify the
output/solution within the polynomial time but can't produce an output/solution in
polynomial time.
2. Here we need the concept of reduction because when you can't produce an output of
the problem according to the given input then in case you have to use an emphasis on
the concept of reduction in which you can convert one problem into another problem.

You might also like