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

Unit 5 NP

Uploaded by

Aesthete Tushhuu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Unit 5 NP

Uploaded by

Aesthete Tushhuu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Unit-V

NP-Completeness
5.1 Introduction:

Almost all the algorithms so far we have studied are polynomial type algorithms: on input of size n
k
their worst case time is O(n ) for some constant k. Now the question is that can all the problems are
solvable in polynomial time, the answer is No, it means that there are some problems that cannot be solved
in polynomial time such as turning machine “halting Problem”.
Generally we assume the problems that can be solved in polynomial time are “tractable “or easy problems
and those can not be solvable are “Intractable” or hard problems. So there exist some problems that cannot
be solved in polynomial time, these problems are called NP problems. We believe in theoretical computer
science that P ≠ NP; it means NP complete problems exist.

Examples:
 Shortest Vs Longest simple path: we can find shortest path from single source in O(VE) time.
Finding the longest simple path between two vertices is NP problem.
 Euler’s tour Vs Hamilton cycle: Euler’s tour of a directed graph is a cycle that traverses each edge
of G exactly once, although it may visit the vertex in more than once. It takes O (E) time. Hamilton
cycle of a directed graph is a cycle that contains all vertices (visited exactly once). It is NP complete
problem.
 3-CNF satisfiability: A Boolean formula contains variables whose values are 0 or 1; Boolean

connectives such as (AND), (OR), and ¬ (NOT); and parentheses. A Boolean formula is satisfiable

if there is some assignment of the values 0 and 1 to its variables that causes it to evaluate to 1. A
Boolean formula is in k-conjunctive normal form, or k-CNF, if it is the AND of clauses of ORs of
exactly k variables or their negations. 3-CNF is NP problem.

*********************************************************************

1 |@2010 M r . S h a n k a r T h a w k a r , H O D I T , H C S T
Q. Define NP, NP-complete and NP-hard. Give examples of each.

5.2 Problem Classes P, NP, NP-complete and NP-Hard and co-NP


 Class P: The class P consists of those problems which are solvable in polynomial time. More
k
specifically, they are problems that can be solved in time O(n ) for some constant k, where n is the size of the
input to the problem. Most of the problems such as searching, sorting etc are P class problems.
 Class NP: It stands for non-deterministic polynomial time. So NP is the set of problems that can be
solved by nondeterministic algorithm in polynomial time.
The classes NP consist of those problems that are “verifiable” in polynomial time. This we
can say by assuming a certificate of a solution. Then we can verify that the certificate is correct in
polynomial time, because the size of certificate is equal to the size of problem.
Example: for 3-CNF satisfiability, a certificate would be an assignment of values to variables. We
can easily check in polynomial time that this assignment satisfies the Boolean formula. Any problem
in P is also in NP, since if a problem is in P then we can solve it in polynomial time without even
being given a certificate.

The class of problem NP is divided into two types: NP-Complete and NP-Hard
 NP-Complete: Any problem is NP complete if it is NP and NP-Hard. These problems have the property
that if any NP-complete problem can be solved in polynomial time the every NP-complete problem is
solved in polynomial time.
Example: Hamilton-cycle and vertex-cover problem.
 NP-Hard: A problem L is NP-hard if and only if it is reducible. All NP-hard problems are NP-complete
but not all NP-complete problems are NP-hard.
Example: Set covering problem is NP-hard.

 Class co-NP: class co-NP as the set of languages L such that the question of whether
NP is closed under complement can be rephrased as whether NP = co-NP. Since P is closed under
complement it follows that P  NP ∩ co-NP. Once again, however, it is not known whether P = NP
∩ co-NP or whether there is some language in NP∩ co-NP

2 |@2010 M r . S h a n k a r T h a w k a r , H O D I T , H C S T
Figure: Four possibilities for relationships among complexity classes. In each diagram, one region
enclosing another indicates a proper-subset relation. (a) P = NP = co-NP. Most researchers regard this
possibility as the most unlikely. (b) If NP is closed under complement, then NP = co-NP, but it need not
be the case that P = NP. (c) P = NP∩co-NP, but NP is not closed under complement. (d) NP = co-NP
and P= NP∩co-NP.

*********************************************************************

5.3 showing Problem to be NP-Complete

One of the key concepts in showing a problem to be NP-complete is:


Reductions: Let us consider a NP problem (or say decision Problem) A, which we would like to solve
in polynomial time. We consider the I/P to the problem is an instance of the problem. Now suppose
there is one more NP problem B, that we already know how to solve in polynomial time. Finally we
suppose that we have an algorithm that transform any instance α of A into some instance β of B with the
following characteristics-
1. The transformation takes polynomial time.
2. The answers are same. i.e. the answer for α is “yes” if and only if the answer for β is also “yes”.

3 |@2010 M r . S h a n k a r T h a w k a r , H O D I T , H C S T
As in above figure, the algorithm solve problem A in polynomial time.
1. Given an instance α of problem A, the reduction algorithm transforms it into an instance β of
problem B.
2. Run polynomial time decision algo for B on instance β.
3. Use the ans of β as ans for α.
*********************************************************************

Q. Write a short note on NP-completeness and reducibility.

5.4 NP-completeness and Reducibility

In theoretical computer science we believe that P ≠ NP, it means NP complete problems exist ,these
problems have the interesting property that if any NP-complete problem can be solved in polynomial
time the every NP-complete problem is solved in polynomial time, i.e. P=NP. Despite years of study,
though no polynomial time algorithm has ever been discovered for any NP-complete problem.
The language (Problem) Hamilton cycle is NP-complete problem, if we solve Hamilton cycle in
polynomial time, then we could solve every problem in polynomial time.
Reducibility: Any problem Q can be reduce to problem Q’ such that solution of Q’ provide solution to
Q. for example a problem of solving the linear equation can be reduce to the problem of solving
quadratic equations Given ax+b=0 this can be transformed into 0x2+ax+b=0, so solution of this problem
provide the solution to ax+b=0
A language L1 is polynomial-time reducible to another language L2, denoted L1 ≤ p L2 if there exists a
Polynomial-time computable function f:{0, 1}* → {0, 1}* such that for all x belongs to {0, 1}*, x
belongs to L1 if and only if f(x) belongs to L2.
We call the function f the reduction function, and a polynomial-time algorithm F that computes a
reduction function f is called reduction algorithm. Following fig. shows the reduction of L1 into L2 in
polynomial time.

4 |@2010 M r . S h a n k a r T h a w k a r , H O D I T , H C S T
NP-Complete: Polynomial-time reductions provide a formal means for showing that one problem is at least
as hard as another, to within a polynomial-time factor. That is, if L1 ≤P L2, then L1 is not more than a polynomial
factor harder than L2, which is why the “less than or equal to” notation for reduction is mnemonic. We can now
define the set of NP-complete languages, which are the hardest problems in NP.

If a language L satisfies property 2, but not necessarily property 1, we say that L is NP-hard. We also define NPC
to be the class of NP-complete languages.

*********************************************************************

5.5 SAT
A Boolean formula is a formula where the variables and operations are Boolean (0/1):
(a+b+¬d+e)(¬a+¬c)(¬b+c+d+e)(a+¬c+¬e)
OR: +, AND: (), NOT: ¬

SAT: Given a Boolean formula S, is S satisfiable, that is, can we assign 0’s and 1’s to the variables so
that S is 1 (“true”)? Easy to see that CNF-SAT is in NP: Non-deterministically choose an assignment
of 0’s and 1’s to the variables and then evaluate each clause. If they are all 1 (“true”), then the
formula is satisfiable.

************************************************************************

Q. Prove that CIRCUIT-SAT belongs to NP. Or prove that CIRCUIT-SAT is NPC.

5.6 Circuit satisfiability


A Boolean circuit is a set of AND, OR and NOT gates. The circuit-SAT problem is to determine if
there is an assignment of 0’s and 1’s to a circuit I/P so that the circuit output is 1. [If the output of the
of circuit is 1 then circuit is satisfiable]

CIRCUIT-SAT = {<C> | C is a satisfiability Boolean combinational circuit}

5 |@2010 M r . S h a n k a r T h a w k a r , H O D I T , H C S T
For example, the circuit in the following Figure has the satisfying assignment x1 = 1, x2 = 1, x3 = 0,
and so it is satisfiable.

Given a circuit C, we might attempt to determine whether it is satisfiable by simply checking


all possible assignments to the inputs. Unfortunately, if there are k inputs, there are 2k possible
assignments. When the size of C is polynomial in k, checking each one takes (2k) time, which is
super-polynomial in the size of the circuit. In fact, as has been claimed, there is strong evidence that
no polynomial time algorithm exists that solves the circuit-satisfiability problem because circuit
satisfiability is NP-complete.

Theorem: Prove that CIRCUIT-SAT belongs to NP.

Proof: We assume that two inputs to polynomial time algorithm A that can verify CIRCUIT-SAT
problem. One of the inputs is Boolean circuit C and another is a certificate corresponding to the
assignment of Boolean values to the circuit.
The Algorithm A is constructed as: for each logic gate in circuit, it checks that the values
provided by the certificate on I/P wires is correctly computed as a function of values on the output
wires. Then if the output of entire circuit is 1, the algorithm o/p is 1. The certificate has a length
equals to the size of circuit i.e. polynomial in size. So CIRCUIT-SAT problem is verified in
polynomial time. It means that CIRCUIT-SAT is NP problem.

*********************************************************************

6 |@2010 M r . S h a n k a r T h a w k a r , H O D I T , H C S T
Q. Prove that SAT (formula SAT) is NPC.

5.7 Formula Satisfiability Problem or SAT

A Boolean formula composed of -


1. n Boolean variables: x1, x2, …, xn
2. m Boolean connectives: any Boolean function with one or two inputs and one output, such as
if)
3. Parenthesis
A Boolean formula φ is said to be satisfiable if the truth assignment of Boolean values (0, 1) to
variables xi of the Boolean formula that causes the formula φ to evaluate to 1.
In formal language it is defined as-
SAT = {φ: φ is a satisfiable Boolean formula}

and thus this formula φ belongs to SAT. The naive algorithm to determine whether an arbitrary
boolean formula is satisfiable does not run in polynomial time. There are 2n possible assignments in a
formula φ with n variables. If the length of φ is polynomial in n, then checking every assignment
requires (2n) time, which is super-polynomial in the length of φ. so SAT is NP problem.

Theorem: Prove that SAT is NPC (NP-complete)


Proof: Since SAT is NP-complete if –
1. SAT is NP and
2. SAT is NP-Hard i.e. SAT is reducible.
1. SAT is NP: To show that SAT belongs to NP, we assume a certificate that consist of a
satisfying assignment for an input formula φ. The verifying algorithm simply replaces
each variable in the formula with its corresponding value and then evaluates the
expression (just like above example). This task is easily done in polynomial time. If the
expression evaluates to 1, the formula is satisfiable.
7 |@2010 M r . S h a n k a r T h a w k a r , H O D I T , H C S T
2. SAT is NP-Hard: Now we can show that SAT is reducible (i.e. NP-hard). It means that
we have to prove Circuit-SAT≤p SAT. Consider the following circuit for the reduction of
the problem from CIRCUIT-SAT to SAT.

For each wire xi in the circuit C, the formula φ has a variable xi . The proper operation of a
gate can now be expressed as a formula involving the variables of its incident wires. The
formula φ produced by the reduction algorithm is the AND of the circuit output variable with
the conjunction of clauses describing the operation of each gate.
For the circuit in the figure, the formula is

Thus the formula is satisfiable.


So, given a circuit it is easily converted into formula in polynomial time, and this can also be
verified in polynomial time. So if we assign the values to the circuit exactly as in formula,
circuit is satisfiable, so Circuit-SAT ≤p SAT. Hence is NP-Complete.

8 |@2010 M r . S h a n k a r T h a w k a r , H O D I T , H C S T
Q. Prove that 3-CNF is NP Complete (NPC)?

5.8 CNF satisfiability


A literal in a Boolean formula is an occurrence of a variable or its negation. A Boolean formula is in
conjunctive normal form, or CNF, if it is expressed as an AND of clauses, each of which is the OR of one or
more literals. A Boolean formula is in 3-conjunctive normal form, or 3-CNF, if each clause has exactly three
distinct literals.
For example, the Boolean formula

is in 3-CNF. The first of its three clauses is , which contains the three literals x1, ¬x1, and

¬x2.

In 3-CNF-SAT, The problem is whether a given boolean formula φ in 3-CNF is satisfiable or not.

Theorem: Prove that 3-conjunctive normal form is NP-complete.

Proof: Since 3-CNF is NP complete if it is –


1. NP
2. NP-Hard (i.e. reducible)

1. 3-CNF is NP: To show that 3-CNF belongs to NP, we assume a certificate that consist of a
satisfying assignment for an input formula φ of 3-CNF. The verifying algorithm simply
replaces each variable in the formula with its corresponding value and then evaluates the
expression. This task is easily done in polynomial time. If the expression evaluates to 1, the
formula is satisfiable.
2. 3-CNP is NP-hard: We can prove that 3-CNP is NP-hard by reducing SAT (Boolean
formula) into 3-CNP i.e. SAT ≤P 3-CNF-SAT.The reduction algorithm can be broken into
three basic steps.
Step 1: Construct a binary “parse” tree for the input formula φ, with literals as leaves and
connectives as internal nodes. Following Figure shows such a parse tree for the formula

9 |@2010 M r . S h a n k a r T h a w k a r , H O D I T , H C S T
-Introduce a variable yi for the output of each internal node. Then, we rewrite the original formula φ
as the AND of the root variable and a conjunction of clauses describing the operation of each node.
For the formula φ , the resulting expression is

Step 2: Convert into CNF (conjunctive normal form)


- First construct a truth table for each clause in . We consider the first clause in the

formula and it is denoted by . The truth table corresponding


the clause is give below-

[Note: the symbol is called if and only if and its value is 1 if values of l-side=r-side, otherwise 0.]
10 |@2010 M r . S h a n k a r T h a w k a r , H O D I T , H C S T
-Using the truth-table entries that evaluate to 0, we build a formula in disjunctive normal form (or
DNF)—an OR of AND’s—

-convert this formula into a CNF formula φ

Step 3: transforms the formula so that each clause has exactly 3 distinct literals. The final 3-CNF
formula is constructed from the clauses of the CNF formula . For each clause Ci of , we
include the following clauses in :
-If Ci has 3 distinct literals, then simply include Ci as a clause of
-If Ci has 2 distinct literals, that is, if , where l1 and l2 are literals, then Include
; requirement that there be exactly 3 distinct literals fulfill.

- If Ci has just 1 distinct literal l, then include


clauses of

We can see that the 3-CNF formula is in 3-CNF and the reduction is computed in polynomial
time.

11 |@2010 M r . S h a n k a r T h a w k a r , H O D I T , H C S T
Q. Prove that Clique is NP-Complete.

5.9 The clique problem


A clique in an undirected graph G = (V, E) is a subset of vertices, each pair of which is
connected by an edge in E.
o A clique is a complete sub-graph of G. The size of a clique is the number of vertices it
contains.
o The Clique problem is the optimization problem of finding a clique of maximum size in a
graph.
o The formal definition is-
CLIQUE = {<G, k>: G is a graph with a clique of size k} .

Theorem: The clique problem is NP-complete.


Proof : To show that CLIQUE is NP complete we have to show
1. CLIQUE is NP
2. CLIQUE is NP –Hard i.e. CLIQUE i.e. reducible.

1. CLIQUE is NP: Assume an algorithm A that takes two Inputs. One is the Certificate that contain
vertices of V’ for G and another is the Graph G. An algorithm A verify in polynomial that
whether V’ is a clique or not by checking whether, for each pair u, v V’, the edge (u, v)
belongs to E.

2. CLIQUE is NP-Hard : We prove this by reduction i.e. we have to prove 3-CNF-SAT ≤P


CLIQUE.
o The reduction algorithm begins with an instance of 3-CNF-SAT.
Let φ = be a boolean formula in 3-CNF with k clauses. Where each

clause Cr has exactly three distinct literals


o We now construct a graph G such that φ is satisfiable if and only if G has a clique of
size k.

o We put an edge between two vertices if both of the following hold:

o This graph can easily be computed from φ in polynomial time. Let us consider

12 |@2010 M r . S h a n k a r T h a w k a r , H O D I T , H C S T
then G is the graph shown in following Figure..

o We now show that this transformation of φ into G is a reduction.


 First, suppose that φ has a satisfying assignment. Then each clause Cr contains at
least one Literal lr1 that is assigned 1.
o Picking one such “true” literal from each clause yields a set V’ of k vertices. We
claim that
V’ is a clique.
both corresponding

o In the example of above Figure, a satisfying assignment of φ has x2 = 0 and x3 = 1.

A corresponding clique of size k = 3 consists of the vertices corresponding to ¬x2

from the first clause, x3 from the second clause, and x3 from the third clause.

Because the clique contains no vertices corresponding to either x1 or ¬x1, we can

set x1 to either 0 or 1 in this satisfying assignment.

 So we reduced an arbitrary instance of 3-CNF-SAT to an instance of CLIQUE with


a particular structure. Hence prove.

**************************************************************************************

13 |@2010 M r . S h a n k a r T h a w k a r , H O D I T , H C S T

You might also like