You are on page 1of 22

COMP3251


Lecture 24: Polynomial-Time


Reduction and Intractability
Polynomial-Time Reduction

Holy Grail: Classify problems according to those that can be


solved in polynomial-time and those that cannot.

Polynomial-time solvable: sorting, connected components,


shortest path, scheduling, network ow, etc.
Provably requires super-polynomial time:

- Given a C++ program, does it ever stop?

- Given a board position in a (generalized) chess game, can


black guarantee a win?

Frustrating news: Lots of fundamental problems have de ed


classi cations for decades.

Great discovery: Many of these fundamental problems are


“computationally equivalent” to one really hard problem.

COMP3251 2 Zhiyi Huang


fi
fl
fi
Polynomial-Time Reduction
De nition. Problem X poly-time reduces to another problem Y
if an arbitrary instance of problem X can be solved by:

1) construct an instance of Y (in poly time);

2) solve the instance of Y;

3) convert solution of Y gives us a solution of X (in poly time).

Note: It is important that steps 1 and 3 must run in poly time.

Notation: X ≤P Y.

COMP3251 3 Zhiyi Huang


fi
Applications of Polynomial Time Reduction
Design algorithms (last lecture): If X ≤P Y, Y can be solved in
polynomial time, then X can also be solved in polynomial time.


Establish intractability (today): If X ≤P Y, and X cannot be


solved in poly-time, then Y cannot be solved in poly-time either.


Establish equivalence (today): If X ≤P Y and Y ≤P X, then X and


Y are equally hard and we use notation X ≡P Y.

COMP3251 4 Zhiyi Huang


Some Examples
Network Flow: Given a ow network, i.e., a graph G = (V, E), a
source vertex s, a sink vertex t, and a capacity function c, nd a
ow in G with the maximum value.

Bipartite Matching: Given a bipartite graph G, nd a matching


with the maximum number of edges.

Theorem (last lecture): Bipartite Matching ≤P Network Flow

COMP3251 5 Zhiyi Huang


fl
fl
fi
fi
Some Examples
Independent Set: Given a graph G = (V, E) and an integer k, is
there a subset of vertices S ⊆ V such that |S| ≥ k, and no two
vertices in S are joined by an edge?

Example:

b a c



 e f d



 g h

- Is there an independent set of size 3? Yes, the green ones.

- Is there an independent set of size ≥ 4? No.

COMP3251 6 Zhiyi Huang


Some Examples
Vertex Cover: Given a graph G = (V, E) and an integer m, is
there a subset of vertices C ⊆ V such that |C| ≤ m, and for each
edge, at least one of its endpoints is in C?

Example:

b a c



 e f d



 g h

- Is there a vertex cover of size 5? Yes, the green ones.

- Is there a vertex cover of size ≤ 4? No.

COMP3251 7 Zhiyi Huang


Independent Set ≡P Vertex Cover
Key Lemma: Consider any graph G = (V, E). For any subset S
of V, S is an independent set if and only if V - S is a vertex cover.

Proof (⟹): Let S be any independent set.


- Consider an arbitrary edge (u, v).

- S independent ⟹ u ∉ S or v ∉ S ⟹ u ∈ V - S or v ∈ V - S.

- Thus, V - S covers (u, v).

Proof (⟸): Let V - S be any vertex cover.


- Consider two vertices u ∈ S and v ∈ S.

- Observe that (u, v) ∉ E since V - S is a vertex cover.

- So no two vertices in S are joined by an edge 



⟹ S is an independent set.

COMP3251 8 Zhiyi Huang


Independent Set ≡P Vertex Cover
Theorem: Independent Set ≤P Vertex Cover.

Proof: Given any problem instance IS(G, k) of the independent


set problem, we will do the followings.

1) Construct an instance VC(G’,k’) of the Vertex Cover problem,


and prove that IS(G,k) is YES if and only if VC(G’,k’) is YES.

2) Then, we can focus on solving VC(G’,k’):

- If VC(G’,k’) is YES, then we know IS(G,k) is YES.

- If VC(G’,k’) is NO, then we know IS(G,k) is NO.

Question: What is G’ and k’?

Answer: G’ = G = (V, E), and k’ = |V| - k.

COMP3251 9 Zhiyi Huang


Independent Set ≡P Vertex Cover
Theorem: Vertex Cover ≤P Independent Set.

Proof: Leave as an exercise.

COMP3251 10 Zhiyi Huang


A More Subtle Reduction
Some notations:
- Boolean variables (literals): X1, X2, … , Xn which takes
value either true or false (alternatively, either 1 or 0).

- Clause: A disjunction of literals, e.g., X2 _ X̄4 _ X7 .

- Conjunctive normal form (CNF): A propositional formula


that is the conjunction of clauses, e.g., 

(X1
_ X̄2 _ X3 ) ^ (X̄1 _ X̄3 _ X4 ) ^ (X2 _ X̄3 _ X̄4 )
CNF-SAT: Given a CNF formula, can it be satis ed?

- E.g., given the above CNF, the answer is YES (say by


setting X1 to false, and X2, X3, X4 to true).

3-SAT: SAT where each clause contains exactly 3 literals.

Claim: These problems “cannot” be solved in polynomial time.

COMP3251 11 Zhiyi Huang


fi
3-SAT ≤P Independent Set
Given an instance ɸ of 3-SAT, we will construct an instance 

(G, k) of Independent Set that has an independent set of size k 

if and only if ɸ is satis able.

The reduction:
- G contains 3 vertices for each clause, one for each literal.

- Connect 3 literals in a clause in a triangle.

- Connect literal to each of its negations.


(X1 _ X̄2 _ X3 ) ^ (X̄1 _ X̄3 _ X4 ) ^ (X2 _ X̄3 _ X̄4 )

X̄2 X̄3 X̄3

X1 X3 X̄1 X4 X2 X̄4
COMP3251 12 Zhiyi Huang
fi
3-SAT ≤P Independent Set
(⟹): Let S be an independent set of size k.
- S must contain exactly one vertex in each triangle.

- Set these literals to true.

- Truth assignment is consistent due to the cross-triangle


edges and all clauses are satis ed.

(X1 _ X̄2 _ X3 ) ^ (X̄1 _ X̄3 _ X4 ) ^ (X2 _ X̄3 _ X̄4 )

X̄2 X̄3 X̄3

X1 X3 X̄1 X4 X2 X̄4

COMP3251 13 Zhiyi Huang


fi
3-SAT ≤P Independent Set
(⟸): Given any satisfying assignment of the 3-SAT instance.
- Select one true literal from each triangle.

- This is an independent set of size k.

(X1 _ X̄2 _ X3 ) ^ (X̄1 _ X̄3 _ X4 ) ^ (X2 _ X̄3 _ X̄4 )

X̄2 X̄3 X̄3

X1 X3 X̄1 X4 X2 X̄4

COMP3251 14 Zhiyi Huang


Transitivity of Polynomial-Time Reduction
Simple Lemma (Transitivity). If X ≤P Y and Y ≤P Z, then X ≤P Z.

Example:

Recall that

- 3-SAT ≤P Independent Set

- Vertex Cover ≡P Independent Set 



⟹ Independent Set ≤P Vertex Cover

We have

- 3-SAT ≤P Independent Set ≤P Vertex Cover.

Therefore, 3-SAT ≤P Vertex Cover.

Implications: Independent Set and Vertex Cover “cannot” be


solved in polynomial time.

COMP3251 15 Zhiyi Huang


P versus NP
We are interested in problems with the following form:

Given an instance I of the problem, either nding a 



solution for I, or else report that none exists.
Note: Not all problems we studied are exactly this form, but
they can be “changed” to this form easily.

Example: We can de ne a problem very similar to the Shortest


Path problem as follows:

Given a number b, a graph G, and two of its vertices 



s and t, nd a path from s to t with length ≤ b.
Why do we need to rephrase the problem like this?
We are comparing the di culty of di erent problems, including
YES/NO problems such as 3-SAT, Vertex Cover, etc. So we
rephrase Shortest Path as a YES/NO problem as well.
COMP3251 16 Zhiyi Huang
fi
fi
ffi
ff
fi
P versus NP
We are interested in problems with the following form:

Given an instance I of the problem, either nding a 



solution for I, or else report that none exists.
A radically new concept:
Given an instance I of the problem, and a proposed 

solution S for I, verify if S is a correct solution to I.

COMP3251 17 Zhiyi Huang


fi
P versus NP
P (polynomial time):
A problem X is in P if given any instance I of the problem, we
can use polynomial time to nd a correct solution to I, or else
report none exists.

NP (nondeterministic polynomial time):


A problem X is in NP if given an instance I of the problem and
a proposed solution S for I, we can always verify whether S is
a correct solution to I in polynomial time.

Examples:

- Shortest Path is in P (Why?).

- For the problems like CNF-SAT, Vertex Cover, etc., we do


not know whether they are in P, but it is easy to show that
they are in NP.
COMP3251 18 Zhiyi Huang
fi
P versus NP
One of the biggest challenges in Computer Science and
Mathematics:

P = NP?

Layman’s version: If we can verify a solution easily, does it


imply we can also nd a solution easily?

- Obviously NOT, right?

- The conventional wisdom also believes that it’s not, but we


still cannot prove it.

An idea for proving P ≠ NP: Identify the most di cult problem


in NP, and then prove that there is no polynomial time algorithm
for this problem.

How to nd this the most di cult problem?

COMP3251 19 Zhiyi Huang


fi
fi
ffi
ffi
NP-completeness
De nition: A problem X is an NP-complete problem if

1) X is in NP, and

2) for every problem Y in NP, Y ≤P X.


Implications:
- If X can be solved in polynomial time, then all NP problem
can be solved in polynomial time (i.e., NP = P).

- If we can prove any one NP problem cannot be solved in


polynomial time, then X cannot be solved in polynomial
time (i.e., NP ≠ P).

COMP3251 20 Zhiyi Huang


fi
NP-completeness
Question: Does such NP-complete problem exist?

Answer: Yes.

Theorem [Cook, Levin, Karp]. 3-SAT is NP-complete.

Recall 3-SAT ≤P Independent Set ≤P Vertex Cover.

Theorem. Independent-Set (IS) and Vertex Cover (VC) are NP-


complete.

Proof (for IS). First, IS is in NP (why?).

• Then, recall that 3-SAT ≤P IS.

• So for any NP problem, we have

- X ≤P 3-SAT (as 3-SAT is NP-complete);

- and therefore X ≤P 3-SAT ≤P IS.

COMP3251 21 Zhiyi Huang


Proof Format of NP-completeness
Goal: Show that a given problem X is NP-complete.

Step 1: Verify that the problem is in NP.

- To do this, we need to show that verifying a given solution


can be done in polynomial time.

Step 2: Show that X is “the hardest problem” in NP.

- To do this, we need to identify another problem Y which is


known to be NP-complete.

- Then, we show that Y ≤P X.

COMP3251 22 Zhiyi Huang

You might also like