UNIT V
UNIT V
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.
NP Completeness
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:
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)
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.
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.
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:
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.
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.
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
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)
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.
NP-Completeness
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:
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.
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.