Sei sulla pagina 1di 75

NP-Completeness

1
NP-Completeness
o Complexity
o Easy and Hard Problems (Intractability)
o P, NP, NP-Complete
o NP-Completeness Proofs
• Informal Illustration
• Key Concepts
• Formal definitions: P,NP,NP-Complete
• First NP-Complete Problem
• NP-Completeness proofs
• Examples

2
• How do computer scientists differentiate
between good (efficient) and bad (not
efficient) algorithms?

3
Polynomial vs Exponential growth
Ordered functions by their growth rates Order
c constant 1
lg n logarithmic 2

lgc n polylogarithmic 3
nr ,0<r<1 sublinear 4
n linear 5
nr ,1<r<2 subquadratic 6

n2 quadratic 7

n3 cubic 8

nc,c≥1 polynomial 9

rn, r>1 exponential 10

Efficient algorithms
Not efficient algorithms
4
Polynomial vs Exponential growth

5
Polynomial vs Exponential growth

6
Easy vs Hard Problems

• Easy Problems
 A problem X to be “easy” or efficiently solvable, if there is a
polynomial time algorithm A for solving X
 Class P of problems are solvable in polynomial time

• Hard problems
 Any problem for which there is no polynomial time algorithm
is an intractable problem

7
Problem 1: Problem 2:
Input: A road map of cities Input: A road map of cities
with distances attached to the with distances attached to the
road map, and two designated road map, and two designated
cities A and B cities A and B
Output: A description of the Output: A description of the
shortest path between A and B longest path between A and B

We know that it is easy – it can be solved efficiently!

Can we come up with an efficient algorithm for the longest path?


8
Polynomial-time Algorithm
(Tractable)

o On inputs of size n, the worst-case running time is O(nk) for some


constant k.
o There are some problems that cannot be solved in polynomial-time.
eg. Turing’s famous Halting Problem cannot be solved by any computer,
no matter how much time is given:

Halting Problem: The problem of determining in advance whether a


particular program or algorithm will terminate (will not run forever).

9
Polynomial-time Algorithm
(Tractable)
o Polynomial-time algorithms are “Tractable”, “Easy”,
eg. O(n), O(1), O(n3), O(n lg n)
o Superpolynomial time: “Intractable”, “Hard”,
eg. O(2n),O(nn),O(n!)

10
11
P, NP, NPC
Traditional definition of NP
• Turing machine model of computation
– Simple model where data is on an infinite capacity tape
– Only operations are reading char stored in current tape cell, writing a
char to current tape cell, moving tape head left or right one square

• Deterministic versus nondeterministic computation


– Deterministic: At any point in time, next move is determined
– Nondeterministic: At any point in time, several next moves are possible

• NP: Class of problems that can be solved by a nondeterminstic


turing machine in polynomial time

12
P, NP, NPC
Nondeterministic Running Time

Deterministic Computation Nondeterministic Computation

• We measure running time by looking at height of


computation tree, NOT number of nodes explored
• Both computation have same height 4 and thus same
running time
13
P, NP, NPC
Nondeterministic computation returning YES

Yes Result No Result

• If any leaf node returns yes, we consider the input to be a


‘yes input’.
• If all leaf nodes return no, then we consider the input to
be a ‘no input’.
14
Nondeterministic algorithms
• A nondeterminstic algorithm consists of
phase 1: guessing
phase 2: checking
• If the checking stage of a nondeterministic algorithm
is of polynomial time-complexity, then this
algorithm is called an NP (nondeterministic
polynomial) algorithm.
• NP problems : (must be decision problems)
– e.g. searching, MST
sorting
satisfiability problem (SAT)
traveling salesperson problem (TSP)

3- 15
Nondeterministic operations and functions

• Choice(S) : arbitrarily chooses one of the elements in


set S
• Failure : an unsuccessful completion
• Success : a successful completion
• Nonderministic searching algorithm:
j ← choice(1 : n) /* guessing */
if A(j) = x then success /* checking */
else failure
3- 16
3- 16
P, NP, NPC
Showing a problem is in NP (illustration)
• Hamiltonian Path (HP)
– Input: Undirected graph G = (V,E)
– Y/N Question: Does G contain a HP?
• Nondeterministic polynomial-time solution
– Guess a hamiltonian path P (ordering of vertices)
• V! possible orderings
• For binary tree, V log V height to generate all guesses
– Verify guessed ordering that is correct
– Return yes/no if ordering is actually a HP

17
P, NP, NPC
Showing a problem is in NP (illustration)
2
Guess Phase
1 3 (Nondeterministic)
Yes input graph ---------------
123 132 213 231 312 321 Verify Phase
(Deterministic)

2
Guess Phase
1 3 (Nondeterministic)
No input graph ---------------
123132213 231 312321 Verify Phase
(Deterministic)
18
P, NP, NPC
Alternate definition of NP
• Preliminary Definitions
– Let P be a decision problem
– Let I be an input instance of P
– Let Y(P) be the set of yes input instances of P
– Let N(P) be the set of no input instances of P

• P belongs to NP iff
• For any I ε Y(P), there exists a “certificate” [solution] C(I)
such that a deterministic algorithm can verify I ε Y(P) in
polynomial time with the help of C(I)
• For any I ε N(P), no “certificate” [solution] C(I) will convince
the algorithm that I ε Y(P).
19
P, NP, NPC
Showing a problem is in NP (illustration)
• Certificate [Solution]
Guess Phase • A Hamiltonian Path
(Nondeterministic)
--------------- • C(I1): 123 or 321

123 132 213 231 312 321 Verify Phase • C(I2): none
(Deterministic)
• Verification Alg:
• Verify certificate is a
possible HP
• Check for edge
2 between all adjacent
nodes in path
1 3
Yes input graph

20
P, NP, NPC
Proving problem in NP

• You need to describe what the certificate C(I) will be


for any input instance I
• You need to describe the verification algorithm
– usually trivial
• You need to argue that all yes input instances and
only yes input instances have an appropriate
certificate C(I)
– also usually trivial (typically do not require)

21
P, NP, NPC
Proving problem in NP: Clique problem

• Clique Problem
– Input: Undirected graph G = (V,E), integer k
– Y/N Question: Does G contain a clique of size ≥ k?
• Certificate
– A clique C of size at least k
• Verification algorithm
– Verify this is a potential clique of size k
– Verify that all nodes in C are connected in E

22
P, NP, NPC
Proving problem in NP: Vertex Cover problem
• Vertex Cover
– Input: Undirected graph G = (V,E), integer k
– Y/N Question: Does G contain a vertex cover of size ≤ k?
• Vertex cover: A set of vertices C such that for every edge (u,v) in E,
either u is in C or v is in C (or both are in C)
• Certificate
– A vertex cover C of size at most k
• Verification algorithm
– Verify C is a potential vertex cover of size at most k
– Verify that all edges in E contain a node in C

23
P, NP, NPC
Proving problem in NP: Satisfiability problem
• Satisfiability
– Input: Set of variables X and set of clauses C over X
– Y/N Question: Is there a satisfying truth assignment T for
the variables in X such that all clauses in C are true?
• Certificate?
• Verification algorithm?

24
Certifiers and Certificates: 3-Satisfiability

SAT. Given a CNF formula , is there a satisfying assignment?

Certificate. An assignment of truth values to the n boolean variables.

Certifier. Check that each clause in  has at least one true literal.

Ex.
 x1  x2  x3    x1  x2  x3    x1  x2  x4   x1  x3  x4 

instance s

 x1 1, x2 1, x3  0, x4 1
certificate t

Conclusion. SAT is inNP.

25
Certifiers and Certificates: Hamiltonian Cycle

HAM-CYCLE. Given an undirected graph G = (V, E), does there exist a


simple cycle C that visits every node?

Certificate. A permutation of the n nodes.

Certifier. Check that the permutation contains each node in V exactly


once, and that there is an edge between each pair of adjacent nodes in
the permutation.

Conclusion. HAM-CYCLE is in NP.

instance s certificate t

26
27
P, NP, NPC

Class P: Solvable in Polynomial-time ( O(nk) ) for some constant k.


Class NP: “Verifiable” in polynomial-time
Given a “certificate” of a solution, we can verify that the certificate
is correct in O(nk) time.
Hamiltonian-cycle problem: Find a simple cycle that contains each
vertex of a given directed graph.
A certificate would be a path of n vertices.
It is easy to check that this certificate is correct, in O(nk) time.
A problem solvable in polynomial-time must be verifiable in
polynomial time. ie. P  NP.

Class NPC (NP-complete):


These problems are in NP and are as “hard” as any problem in NP,
eg. Hamiltonian-cycle
28
P, NP, NPC

Class P Solvable in We are interested in whether


Polynomial-time P = NP ?

Class NP Verifiable in If we can find a polynomial-


polynomial-time verifiable problem that is proved
not polynomial-time solvable,
then we can disprove.

P We know P  NP But so far we cannot find any.


NP

29
P, NP, NPC

• A problem P is said to be NP-Hard if all members of


NP polynomially reduce to this problem.
• A problem P is said to be NP-Complete if (a) P ∈ NP,
and (b) P is NP-Hard.

NP NP-
Hard
P
NP Complete

30
P, NP, NPC
Class NP
A decision problem is solvable in Non-deterministic Polynomial time:
– The solution can be verified in polynomial time, eg. verifying that a
path has length greater than K
– If we have an exponential number of processors, we can check all
possible solutions simultaneously and therefore answer in
polynomial time

Class NPC
The word complete means that every problem in the class NPC can be
reduced (in polynomial time) into another problem of the class NPC.
The class of NPC problems is the class of the hardest computational
problems in the class NP: every NP problem can be transformed
into an NPC problem (the reverse is not true!!!)
31
P, NP, NPC

• P not equal to NP?


– Is that true that not all problems is NP can be solved in
polynomial time?

• Class of NP-Complete Problems


– They all admit exponential time solutions;
– Nobody has ever been able to find a polynomial time solution for
any single problem in the class;
– Nobody has ever been able to prove an exponential lower bound
for any single problem in the class;

32
P, NP, NPC

• Completeness
– if someone were to find a polynomial time solution for a single
problem in the class NP-complete  all the problems could be
solved in polynomial time!!!
– if someone were to prove an exponential lower bound for a
single problem in the class NP-complete  all the problems in
the class would be intractable !!!

33
P, NP, NPC
Class NPC (The class of NP-complete problems):

These problems are hardest ones in NP (no other NP problem is


harder then these problems)

There are many problems in NPC. So it is important to know


whether these problems are tractable.
Moreover, if a polynomial time solution can be found for any one of
them, then all NP problems are polynomial-time solvable (hence
can be proved).
However, so far no such solution is discovered.
So, many believe that P  NP (NP-complete problems are intractable.)

34
P, NP, NPC
Why study P algorithms?

• From experience, once a polynomial-time algorithm for a


problem is discovered (eg. (n100)), more efficient algorithm
often follow.
• A problem that can be solved in polynomial time in one model
(one computer architecture) can be solved in polynomial time in
another.
• If an algorithm only include polynomial-time execution of basic
instructions and a constant number of calls to polynomial-time
subroutines, the running time of the composite algorithm is
polynomial.

35
P, NP, NPC
Why study NP-completeness?

• When we can establish a problem as NP-complete, we provide


good evidence for its intractability.
• Then we better spend the time to develop an approximation
algorithm, or solve a tractable special case.
• Interestingly, several NP-complete problems are similar to some
tractable ones.

36
Examples
1. Shortest vs longest simple paths
Single-source shortest paths can be found in O(ve) time.
But finding longest simple path between 2 vertices is NP-complete

2. Euler tour vs hamiltonian cycle


Euler tour: traverses each edge of a connected, directed graph exactly once (O(e))
Hamiltonian cycle: a simple cycle that contains each vertex of a given graph:
NP-complete

37
Examples
3. 2-CNF satisfiability vs 3-CNF satisfiability (k-conjunctive normal form)
A boolean formula is satisfiable if there is some assignment of the 0/1 variable
values that makes the formula results in “1”.
Example:

2-CNF : P AND 3-CNF : NPC AND


OR OR OR OR OR OR
x1 x2 x1 x3 x2 x3 x1 x2 x4 x1 x3 x4 x2 x3 x1

2 elements 3 elements

38
How to prove NP-Completeness

How do we know a problem is NP-complete?

Informal illustration:
• The concept of “Polynomial-time reducibility”
- For comparing the hardness of problems.
• How to prove a problem to be NP-complete
(the first NP-complete problem).
• Based on some already known NP-complete problems, how to
prove some other problems are NP-complete.

39
How to prove NP-Completeness
Informal Illustration
Given 2 problems: P1 and P2, Instance of P1
• We map an input problem instance of
P1 to P2 , Solve
• Then solve for P2, for P1 Map instance of P1 to
Polynomial-time
Instance of P2
Reduction
• And then obtain the answer for P1
directly from the answer from P2. Instance of P2
If the mapping (reduction) is in
polynomial time, then we say: Solve for P2
Answer of
P1 is polynomial-time reducible to P2. instance of P2
We can use P2 as a subroutine of P1, with Answer of
only a polynomial amount of overhead. instance of P1

Note that, if we can solve a problem P1 by mainly solving P2, this does not imply P1
is harder than P2. Indeed, we can say the P2 algorithm is a powerful engine that
can solve for P1, although maybe P1 is only a piece of cake.
40
How to prove NP-Completeness
Informal Illustration

NP-complete problems are the hardest ones of all NP problems.


One method to prove that a particular problem is NP-complete:
Given a particular problem that can Instance of a
essentially be used as a subroutine for all problem in NP
problems in NP, with only a polynomial Solve for the
problem in NP
amount of overhead.
(Polynomial-time Reduction) Polynomial-time
Reduction
Instance of a
subroutine problem
=> This problem is harder than or at least
equally hard as all NP problems. An problem
used as subroutine
“This problem is ”
Answer of the
subroutine problem
=> If this problem is also in NP, then, this
problem is NP-complete. Answer of the
problem in NP

41
How to prove NP-Completeness
Informal Illustration

NP-complete problems are the hardest ones of all NP problems.


After we prove that a particular problem is NP-complete,
Instance of P1
Given this NP-complete problem, eg. P1, we can prove (NP-complete)
some others are NP-complete: Solve for P1
(NP-complete)
To prove the NP-completeness for P2: Polynomial-time
If we can show that P2 can essentially be used as a Reduction
subroutine for P1, with only a polynomial amount of Instance of P2
(in NP)
overhead. (Polynomial-time Reduction)
=> P2 is harder than or at least equally hard as P1. P2
=> P2 is harder than or at least equally hard as all NP Answer of P2
(in NP)
problems. “P2 is NP-hard”
Answer of P1
=> If P2 is also in NP, then, P2 is NP-complete. (NP-complete)

42
How to prove NP-Completeness
Informal Illustration

Hamiltonian Cycle Problem: Traveling Salesman Problem:


whether there is a simple cycle containing whether there is a simple cycle containing
each vertex of a given undirected graph each vertex of a given complete graph with
(simple cycle => each vertex visited once) edge costs and has total cost  K?
H Problem: T Problem:
1 1
2 1
2 2
1 1 2

1
We can reduce the H problem to the T problem as shown.
Then we solve the T problem with k=number of edges in the H problem.
Then we use the result of the T problem to answer the H problem.

Since we already know that the H problem is NP-Complete.


43
We can conclude that the T problem is .
How to prove NP-Completeness

Formal study of NP-Completeness proofs.

To prove a problem is NP-complete, we need to


show “how hard it is”.

Three key concepts for the proofs:


1. Decision problems vs Optimization problems
2. Reductions
3. A first NP-complete problem

44
How to prove NP-Completeness
3 Key concepts for the proofs

A. Decision problems vs optimization problems

NP-Completeness applies directly to decision problems, not optimization


ones. But optimization problems usually have a related decision problem.

Optimization problems PATH(G,u,v,k)


each feasible solution has 1.run SHORTEST-PATH(G,u)
a value to be optimized 2.compare result of SHORTEST-PATH with k
eg. SHORTEST-PATH if is easy,
then is easy as well.
Decision problems
answer is simple, yes or no. Likewise, “a decision problem is hard” implies
eg. PATH(G,u,v,k) : “the related optimization problem is hard”.

whether a path exists Hence the theory of NP-completeness often has


between 2 given vertices implications for optimization problems as well.
having at most k edges.
45
How to prove NP-Completeness
3 Key concepts for the proofs

B. Reductions

• We have 2 decision problems: A and B. An algorithm
to decide A
• We have a a polynomial-time reduction
Polynomial-time
algorithm that transforms any instance  of A
reduction algorithm
into some instance  of B such that the
answers (yes/no) to  and  are the same. 
An algorithm
• “Problem A is hard” => “ ” to decide B
• “A is NP-Complete” => “ ” yes no
if B is also in NP.
yes no

The reduction method for NP-Completeness proofs:


Given an NP-Complete problem A, we can prove problem B as NP-Complete by
1. Prove that B is in NP.
2. Then, find a polynomial-time reduction algorithm from A to B.
46
How to prove NP-Completeness
3 Key concepts for the proofs

C. A first NP-Complete Problem



An algorithm
The reduction method for NP-Completeness proofs:
to decide A
Polynomial-time Given an NP-Complete problem A, we can prove
reduction algorithm problem B as NP-Complete by
 1. Prove that B is in NP.
An algorithm
2. Then, find a polynomial-time reduction algorithm
to decide B
from A to B.
yes no
yes no • We need a first NP-Complete problem
in order to prove a different problem
NP-Complete.
The notation of
polynomial-time reducibility: • Our first NP-Complete problem:
p Circuit-Satisfiability Problem
Eg. A p B
47
How to prove NP-Completeness

(1) Formalize the definitions of P, NP, and NPC


(2) Illustrate NPC proofs
(3) Introduce some NPC problems

48
Accepted vs Decided (Class P)
• Decision problems : map the problem instances to {0,1}  (True/False).
• Given an algorithm A and an input instance x  A(x) will returns 1 if A accepts
x and 0 if A rejects x.
• Consider all inputs x1,x2,..., xn that results “1”.
Suppose L is a set such that L = {x1,x2,..., xn}.
Then L is accepted by A if every element xi in L is accepted by A.
(But A may loop forever for an element x  L without rejecting it)
L is decided by A if every element xi in L is accepted by A and
every element not in L is rejected by A.
For Turing’s Halting Problem, there exists an accepting algorithm, but no
decision algorithm exists.
• The complexity class P: A problem belongs to P if and only if it has
a polynomial time decision algorithm.
49
Verification Algorithm (CLASS NP)
• Consider the decision problem PATH, for a given problem instance
x = <G,u,v,k>, we need to determine whether it is true or false.
If we are also given a path from u to v (a certificate) that helps to prove for k,
then the verification of x is easy.

• A A is a 2-input algorithm that outputs whether a given


certificate verifies a given problem instance x:
A(x,certificate) = 1 or A(x,certificate) = 0

Eg. bool Verify_Path(<G,u,v,k>,a_path)

• The complexity class NP: A problem belongs to NP if and only if


it has a polynomial-time verification algorithm, A(x, certificate),
such that |certificate| = O(|xc|).

50
NP-Completeness and the Proofs
• A problem, A, is NP-Complete: CIRCUIT-SAT
(1) A  NP, and
(2) L p A, for every L  NP. [NP-hard] SAT
• We also say that A belongs to NPC
3-CNF-SAT
• Some famous NP-Complete problems:
CIRCUIT-SAT, SAT, 3-CNF-SAT, CLIQUE, ..
CLIQUE SUBSET-SUM
• Alternatively, we can conclude that a
problem, A, is NP-Complete if: VERTEX-COVER
(1) , and
(2’) , for some L NPC [=> ] HAM-COVER

CIRCUIT-SAT is proved using (1) and (2).


TSP
SAT, 3-CNF-SAT, CLIQUE.. are proved using (1) and (2’).
51
CIRCUIT-SAT
First NP-complete Problem
Elements:
Circuit-Satisfiability Given a boolean combinational x z
Problem circuit composed of AND, OR,
and NOT gates, is it satisfiable? x x
(CIRCUIT-SAT) 0 1
x1 1 0
x2 x
A y z
x y xy
Output 0 0 0
0 1 0
x3 1 0 0
1 1 1

If we assign 1, 1, and 0 to x1, x2, and x3, the output will be 1. x z


y
=> The circuit is satisfied by some => It is satisfiable. x y xy
However, if A is replaced by an AND gate, we can’t find any 0 0 0
“assignment” of (x1, x2, x3) to make it satisfied. => It is not satisfiable. 0 1 1
1 0 1
1 1 1 52
CIRCUIT-SAT
First NP-complete Problem

x1
x2

Output
x3

• The of a boolean combinational circuit


= no. of boolean combinational elements + no. of wires
• To such a circuit into a binary string:
we can devise a graph like encoding
• If there are k inputs, then there are 2k possible assignments. By simply checking all these
assignments => O( ).

• By proving that it is NP-Complete, we can claim that “there is strong


evidence that no polynomial-time algorithm exists” for CIRCUIT-SAT.
53
CIRCUIT-SAT First NP-complete Problem
Part A of the proof: CIRCUIT-SATNP
x1
CIRCUIT-SAT is NP-Complete x2
Two parts of the proof:
A. CIRCUIT-SAT NP Output
B. CIRCUIT-SAT is NP-hard x3

Part A of the proof: CIRCUIT-SATNP


Consider an algorithm:
bool Verify_Circuit_Sat( Input_Circuit,
Certificate/*an assignment to the wires, eg. x1, x2, x3*/)
This algorithm computes values of the logic gates based on the
assignment. If circuit output is 1 (0), then the algorithm returns 1 (0).
This is a algorithm for CIRCUIT-SAT
Since we can find such an algorithm for CIRCUIT-SAT, we say that
CIRCUIT-SAT can be verified in polynomial time, and .
54
CIRCUIT-SAT First NP-complete Problem
Part B of the proof: Every NP problem is polynomial-time reducible to CIRCUIT-SAT

Part B of the proof: CIRCUIT-SAT is NP-hard


For each NP problem, we design F in this way:
Bool_Combinational_Circuit polynomial_time_F(encoded_input_of_an_NP_instance)
1 n = size of encoded_input_of_an_NP_problem_instance
2 Compute T(n) of alg. A using n, where A is the verification program of the NP_problem
3 Based on a computer capable of running A, create T(n) copies of the corresponding
boolean combinational circuits, such that circuiti will map configi to configi+1.
4 Create the whole_circuit by wiring the outputs of circuit1 to circuit2, and outputs of
circuit2 to circuit3, etc.
5 Wire the “Program Code” pins of circuit1 according to A’s code.
6 Wire the “Encoded_input” pins of circuit1 according to
encoded_input_of_an_NP_problem_instance.
7 Ignore (ground) all outputs of whole_circuit, except the 0/1 output of circuitT(n).
8 Return whole_circuit.
Polynomial time55of n
NP-Completeness and the Proofs
After some problems have been proved NP-Complete,
we can prove for other problems more easily. CIRCUIT-SAT

A common approach to prove that a problem,


SAT
A, is NP-complete:
1. Prove A  NP 3-CNF-SAT
2. Select a known NP-complete problem K
3. Describe an algorithm that maps every instance CLIQUE SUBSET-SUM
of A to an instance of K
4. Prove that the results for both instances (yes or
VERTEX-COVER
no) in (3) are the same
5. Prove that the algorithm in (3) runs in
polynomial time [ Polynomial-time Reducibility ] HAM-COVER

TSP
56
SAT Problem
Formula-Satisfiability Given a boolean formula of n boolean
Problem variables, m boolean connectives, and required
(SAT) parenthesis, is it satisfiable?

Boolean functions: P Q PQ PQ P PQ P Q


T T T T F T T
T F F T F F F
F T F T T T F
F F F F T T T
Example: ((x1  x2)  (( x1  x3)  x4))   x2
It is satisfiable by the assignment: <x1=0, x2=0, x3=1, x4=1>:
((0  0)   (( 0  1)  1))   0
= (1  (1  1))  1
=

57
SAT Problem
Part A of the proof: SATNP

SAT is NP-Complete Example:


Two parts of the proof: ((x1  x2)  (( x1  x3)  x4))   x2
A. SAT NP
B. SAT is NP-hard

Part A of the proof: SATNP


Consider an algorithm:
bool Verify_Sat( Input_Boolean_Formula,
Certificate/*an assignment to the variables, eg. x1, x2, x3*/)
This algorithm replaces each variable in the formula with its corresponding
values and evaluate the expression.
This is a 2-input, polynomial-time verification algorithm for SAT.
Since we can find such an algorithm for SAT, we say that SAT can be
verified in polynomial time, and .
58
SAT Problem
Part B of the proof: SATNP-Hard

Part B of the proof: SAT is NP-hard


Show that CIRCUIT-SAT p SAT
ie. Any instance of circuit satisfiability can be reduced in polynomial time to
an instance of formula satisfiability.
Reduction by simple translation,
Sometimes it is easy: But not always:
s t
t x z
x z
y
y
z = (t  (xy))  ((xy))
z = (s t)  ((x y))
Original circuit: 4 gates + 8 wires Original circuit: 4 gates + 8 wires
Resultant formula: 4 variables + 4 operators Resultant formula: variables + operators
Reason of complexity: Fan-out > 1
Indeed, such a reduction is not in polynomial time.
59
SAT Problem
Part B of the proof: CIRCUIT-SAT p SAT

Part B of the proof: SAT is NP-hard x1 x5


x2 x8
Since we need to show that “Any x6
instance of circuit satisfiability can be x9 x10
reduced in to an
instance of formula satisfiability.”
x3 x4 x7
We design a more clever method:
The formula:
x10  (x4   x3)
Step 1. For each gate, formulate it with  (x5  (x1  x2))
the operation on its incident  (x6  x4)
wires.  (x7  (x1  x2  x4))
eg. x10  (x7  x8  x9)  (x8  (x5  x6))
 (x9  (x6  x7))
Step 2. “AND” all the formulas of the  (x10  (x7  x8  x9))
gates.

A CIRCUIT-SAT instance with m gates and n wires


Polynomial time
reduction A SAT instance (size = polynomial in the size of CIRCUIT-SAT) 60
The 3-CNF-SAT Problem
3CNF-Satisfiability Problem (3-CNF-SAT) Given a boolean formula in
3-CNF, is it satisfiable?
A literal: eg. x1 or x1 (an occurrence of a variable or its negation)
One or more literals “” together
Conjunctive normal form
(CNF) x? x? x? x? x? x?
or?x
(x or?  …)(x3-CNF
or?x
or?  …)(x
or ?x
or?  …)..
Eg. (x1x2)(x3x2x4)x1 x? x? x? x? x? x?

2-CNF x? x? x? x? x? x?
Eg. (x1x2)(x3x4)(x1x3) or?x
(x or?x
or?)(x or?x
or ?)(x or ?)..
x? x? x? x? x? x?
3-CNF
Eg. ( x1x1x2) x? x? x? x? x? x? x? x? x?
or?x
(x or?x or?or??x
or?)(x or?x
or?)(x or?x
or?)..
(x3x2x4) x? x? x? x? x? x? x? x? x?
(x1x3x4)
61
The 3-CNF-SAT Problem
Part A of the proof: 3-CNF-SATNP

3-CNF-SAT is NP-complete
2 parts of the proof: A 3-CNF Example:
A. 3-CNF-SAT NP (x1x1x2)(x3x2x4)(x1x3x4)
B. 3-CNF-SAT is NP-hard

Part A of the proof: 3-CNF-SATNP


Consider an algorithm:
bool Verify_3_CNF_SAT( Input_Boolean_Formula,
Certificate /*an assignment to the variables*/ )
This algorithm replaces each variable in the formula with its corresponding
values and evaluate the expression.
This is a 2-input, polynomial-time verification algorithm for 3-CNF-SAT.
Since we can find such an algorithm for 3-CNF-SAT, we say that 3-CNF-
SAT can be verified in polynomial time, and 3-CNF-SATNP.
62
The 3-CNF-SAT Problem
Part B of the proof: 3-CNF-SAT is NP-hard
Part B of the proof: 3-CNF-SAT is NP-hard
Show that SAT p 3-CNF-SAT
A formula Example:
ie. Any instance of formula ((x1  x2)   ((x1  x3 )  x4 ))  x2
satisfiability can be reduced in
polynomial time to an instance A 3-CNF Example:
of 3-CNF formula satisfiability. (x1x1x2)(x3x2x4)(x1x3x4)

The Reduction :
y1
Step 1: Create a binary “parse” tree for the formula.
y2

Step 2: Rewrite it in the form:
y3  y4 x2
y1  (y1  (y2  x2))
 (y2  (y3  y4))  
 (y3  (x1  x2 )) x1 x2 y5
 (y4   y5) 
 (y5  (y6  x4))  y6 x4
 (y6  ( x1  x3))
x1 x3 63
Part B of the proof: 3-CNF-SAT is NP-hard
Show that SAT p 3-CNF-SAT
A formula: eg. ((x1  x2)   ((x1  x3 )  x4 ))  x2
ie. Any instance of formula satisfiability
can be reduced in polynomial time to an 3-CNF eg. (x1x1x2)(x3x2x4)(x1x3x4)…
instance of 3-CNF formula satisfiability.

The Reduction :
Step 3: Change each sub-clause of the following to an OR of literals:
y1  (y1  (y2  x2)) Eg. y1 y2 x2 (y1 (y2  x2)) (y y x )
 (y2  (y3  y4)) 1 1 1 0 1 2 2
 (y3  (x1  x2 )) 1 1 0
1 0 1
1
0 (y1y2x2)
 (y4   y5) 1 0 0 0
 (y5  (y6  x4))
0 1 1
0 1 0
1
0
(y1y2x2)
 (y6  ( x1  x3)) 0 0 1
0 0 0
1
1 (y1y2 x2)

We can rewrite (y1 (y2  x2)) as:


 [ (y1y2x2) (y1y2x2)  (y1y2x2)  (y1y2 x2) ]
By DeMorgan’s laws:
=> (y1y2x2)  (y1y2x2)  (y1y2x2)  (y1y2 x2)
=> (y1  y2  x2) (y1  y2  x2)  (y1  y2  x2)  (y1  y2  x2)
64
Part B of the proof: 3-CNF-SAT is NP-hard
Show that SAT p 3-CNF-SAT
A formula: eg. ((x1  x2)   ((x1  x3 )  x4 ))  x2
ie. Any instance of formula satisfiability
can be reduced in polynomial time to an 3-CNF eg. (x1x1x2)(x3x2x4)(x1x3x4)…
instance of 3-CNF formula satisfiability.

The Reduction : y1  (y1  (y2  x2))


Step 3: Change each sub-clause to an OR of literals:  (y2  (y3  y4))
 (y3  (x1  x2 ))
(Con’td)  (y4   y5)
 (y5  (y6  x4))
 (y6  ( x1  x3))
We can rewrite (y1 (y2  x2)) as:
(y1  y2  x2) (y1  y2  x2)  (y1  y2  x2)  (y1  y2  x2)
Apply the same y1  (y1y2x2)(y1y2x2)(y1y2x2)(y1y2 x2)
method to other  (y2  (y3  y4))
sub-clauses:  (y3  (x1  x2 ))
 (y4   y5)
 (y5  (y6  x4))
 (y6  ( x1  x3))

Polynomial time A SAT instance


reduction A 3-CNF-SAT instance
65
such that result of SAT instance = result of 3-CNF-SAT instance
NP-Completeness and the Proofs
CIRCUIT-SAT

SAT

3-CNF-SAT

CLIQUE SUBSET-SUM

VERTEX-COVER

HAM-CYCLE

TSP
66
The Clique Problem
A complete graph A Clique in an undirected graph
G=(V,E) is a complete subgraph of
u v G.
u v

y x z w

y x

Clique Problem
Optimization problem: Find a clique of maximum size in a graph.
Decision problem: Whether a clique of a given size k exists in the graph.

67
The CLIQUE Problem
Part A of the proof: CLIQUENP
CLIQUE is NP-complete u v
2 parts of the proof:
A. CLIQUE NP
z w
B. CLIQUE is NP-hard

y x
Part A of the proof: CLIQUE NP
Consider an algorithm:
bool Verify_CLIQUE( Input_Graph,
Certificate /*a set of vertices in the input graph*/ )
This algorithm checks whether the set of vertices in the certificate are
linked up as a complete graph.
This is a 2-input, polynomial-time verification algorithm for CLIQUE.
Since we can find such an algorithm for CLIQUE, we say that CLIQUE can
be verified in polynomial time, and CLIQUENP.
68
The CLIQUE Problem
Part B of the proof: CLIQUE is NP-hard
Part B of the proof: CLIQUE is NP-hard A 3-CNF Example:
Show that 3-CNF-SAT p CLIQUE (x1x2x3)(x1x2x3)(x1x2x3)
ie.Any instance of 3-CNF formula satisfiability can x x
be reduced in polynomial time to an instance of CLIQUE. x1 2 3

The Reduction :
Describe a 3-CNF formula with k sub-clauses as: x x1
1
(l11  l12  l13)  (l21  l22  l23)  .. (lk1  lk2  lk3)
x2 x2
Reduce it to a clique problem such that it is
satisfiable if and only if a corresponding graph x3 x3
has a clique of size k.
Polynomial time reduction
Step 1: Represent each “term” lr as a vertex v ri .
i
A 3-CNF-SAT instance
Step 2: Create the edges for any two
A CLIQUE instance
vertices: vri and vsj if: s.t. result of 3-CNF-
r  s and lri is not the negation of lsj SAT instance = result
of CLIQUE instance69
The VERTEX-COVER Problem
A vertex Covers A Vertex-Cover in an undirected graph is a set of
a set of edges: vertices that cover all edges in the graph.

u v u v u v

z w z w z w

y x y x y x
Vertex-Cover = {w,z}

Vertex-Cover Problem
Optimization problem: Find a vertex-cover of minimum size in a graph.
Decision problem: Whether a graph has a vertex-cover of a given size k.

70
The VERTEX-COVER Problem
Part A of the proof: VERTEX-COVERNP
VERTEX-COVER is NP-complete
2 parts of the proof: u v
A. VERTEX-COVER NP
B. VERTEX-COVER is NP-hard z w

y x
Part A of the proof: VERTEX-COVER NP
Consider an algorithm:
bool Verify_VERTEX_COVER( Input_Graph,
Certificate /*a set of vertices*/ )
This algorithm checks whether the set of vertices in the certificate cover all
edges in the input graph.
This is a 2-input, polynomial-time verification algorithm for VERTEX-COVER.
Since we can find such an algorithm for VERTEX-COVER, we say that VERTEX-
COVER can be verified in polynomial time, and VERTEX-COVER NP.
71
The VERTEX-COVER Problem
Part B of the proof: VERTEX-COVER is NP-hard
Part B of the proof: VERTEX-COVER is NP-hard u v
Show that CLIQUE p VERTEX-COVER
z w
ie.Any instance of CLIQUE satisfiability can be reduced
in polynomial time to an instance of VERTEX-COVER. y x
The Reduction :
For any CLIQUE satisfiability problem < G=(V,E), k>, we can create a
VERTEX-COVER problem <G’,|V|-k> such that G’ is the complement of G.
Example: G G’ = complement of G
CLIQUE problem: VERTEX-COVER
In the graph u v u v problem:
G=(V,E), can we In the graph G’, can
z w z w
find a clique of we find a clique of
size k=4? y x y x size |V|-k=2?

Polynomial A CLIQUE instance


time
reduction A VERTEX-COVER instance s.t. result of CLIQUE inst. = result of VERTEX-COVER72inst.
The HAM-CYCLE Problem
A Hamiltonian Cycle in an undirected
graph is a simple cycle that contains each
vertex in V. u v

The HAM-CYCLE z w
Problem
Does a graph have a
hamiltonian cycle? y x

HAM-CYCLE is NP-complete
2 parts of the proof:
A. HAM-CYCLE NP
B. HAM-CYCLE is NP-hard

73
The HAM-CYCLE Problem
Part B of the proof: HAM-CYCLE is NP-hard
Part A of the proof: HAM-CYCLE NP
Consider an algorithm:
bool Verify_HAM-CYCLE (Input_Graph,Certificate /*a seq of vertices of a ham-cycle*/ )
It checks: 1. The certificate covers all vertices in input_graph exactly once.
2. The certificate is a valid path (each vertex links to next one).
3. An edge joins the first and the last vertex in the certificate.
This is a 2-input, polynomial-time verification algorithm for HAM-CYCLE.
Since we can find such an algorithm for HAM-CYCLE, we say that
HAM-CYCLE can be verified in polynomial time, and HAM-CYCLE NP.

Part B of the proof: HAM-CYCLE is NP-hard


Show that VERTEX-COVER p HAM-CYCLE
ie.Any VERTEX-COVER instance can be reduced in polynomial time to a HAM-CYCLE instance.
The Reduction : Please refer to the text book. Chp 34.5.3
74
Summary
o Intractability
o P,NP,NP-Complete,P<>NP
CIRCUIT-SAT
o NP-Completeness Proofs
SAT
• Informal Illustration
3-CNF-SAT
• Key Concepts
• Formal definitions: P,NP,NPC CLIQUE SUBSET-SUM

• First NP-Complete Problem VERTEX-COVER


• NP-Completeness proofs
HAM-CYCLE
• Examples
TSP

75

Potrebbero piacerti anche