Dr Yingwu Zhu Chapter 34 2 NPCompleteness Poly time algorithm input size n in some encoding worst case running time O n c for some constant c Three classes of problems ID: 244084
Download Presentation The PPT/PDF document "NP-Completeness" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.
Slide1
NP-Completeness
Dr. Yingwu Zhu
Chapter 34Slide2
2
NP-Completeness
Poly time algorithm: input size
n
(in some encoding), worst case running time –
O
(
n
c
) for some constant
c
.
Three classes of problems
P
: problems solvable in poly time.
NP
: problems verifiable in poly time.
NPC
: problems in NP and as hard as any problem in NP. Slide3
3
NP-Completeness (verifiable)
Verifiable in poly time: given a certificate of a solution, could verify the certificate is correct in poly time.
Examples (their definitions come later):
Hamiltonian-cycle, given a certificate of a sequence (
v
1
,
v
2
,…,
v
n
), easily verified in poly time.
3-CNF, given a certificate of an assignment 0s, 1s, easily verified in poly time.
(so try each instance, and verify it, but 2
n
instances)
Why not defined as “solvable in exponential time?” or “Non Poly time”?Slide4
4
NP-Completeness (why NPC?)
A problem
p
NP, and any other problem
p
NP can be translated as
p
in poly time.
So if
p
can be solved in poly time, then all problems in NP can be solved in poly time.
All current known NP hard problems have been proved to be NPC.Slide5
5
Relation among P, NP, NPC
P
NP (Sure)
NPC NP (sure)
P
= NP (or P NP, or P NP) ???
NPC
= NP (or NPC NP, or NPC NP) ???
P NP: one of the deepest, most perplexing open research problems in (theoretical) computer science since 1971.Slide6
6
Arguments about P, NP, NPC
No poly algorithm found for any NPC problem (even so many NPC problems)
No proof that a poly algorithm cannot exist for any of NPC problems, (even having tried so long so hard).
Most theoretical computer scientists believe that NPC is intractable (i.e., hard, and P
NP).Slide7
7
View of Theoretical Computer Scientists on P, NP, NPC
NPC
P
NP
P
NP, NPC NP, P NPC = Slide8
8
Why discussion on NPC
If a problem is proved to be NPC, a good evidence for its intractability (hardness).
Not waste time on trying to find efficient algorithm for it
Instead, focus on design approximate algorithm or a solution for a special case of the problem
Some problems looks very easy on the surface, but in fact, is hard (NPC).Slide9
9
Decision VS. Optimization Problems
Decision problem: solving the problem by giving an answer “YES” or “NO”
Optimization problem: solving the problem by finding the optimal solution.
Examples:
SHORTEST-PATH (optimization)
Given
G
,
u
,
v
, find a path from
u
to
v
with fewest edges.
PATH (decision)
Given G, u,v
, and k, whether exist a path from u to v consisting of at most k edges.Slide10
10
Decision VS. Optimization Problems (Cont.)
Decision is easier (i.e., no harder) than optimization
If there is an algorithm for an optimization problem, the algorithm can be used to solve the corresponding decision problem.
Example: SHORTEST-PATH for PATH
If optimization is easy, its corresponding decision is also easy. Or in another way, if provide evidence that decision problem is hard, then the corresponding optimization problem is also hard.
NPC is confined to decision problem. (also applicable to optimization problem.)
Another reason is that: easy to define reduction between decision problems.Slide11
11
(Poly) reduction between decision problems
Problem (class) and problem instance
Instance
of decision problem A and instance of decision problem B
A reduction from A to B is a transformation with the following properties:
The transformation takes poly time
The answer is the same (the answer for
is YES if and only if the answer for is YES).Slide12
12
Implication of (poly) reduction
(Poly) Reduction
Algorithm for B
Decision algorithm for A
YES
YES
NO
NO
If decision algorithm for B is poly, so does A.
A is no harder than B (or B is no easier than A)
2. If A is hard (e.g., NPC), so does B.
3. How to prove a problem B to be NPC ??
3.1 find a already proved NPC problem A
3.2 establish an (poly) reduction from A to B
Question: What is and how to prove the first NPC problem?
Circuit-satisfiability problem.
(at first, prove B is in NP, which is generally easy.)Slide13
13
Discussion on Poly time problems
(
n
100
) vs. (2
n
)
Reasonable to regard a problem of (
n
100
) as intractable, however, very few practical problem with (
n
100
).
Most poly time algorithms require much less.
Once a poly time algorithm is found, more efficient algorithm may follow soon.
Poly time keeps same in many different computation models, e.g., poly class of serial random-access machine poly class of abstract Turing machine poly class of parallel computer (#processors grows polynomially with input size)
Poly time problems have nice closure properties under addition, multiplication and composition.Slide14
14
Class P Problems
Let
n
= the length of binary encoding of a problem (i.e., input size),
T
(
n
) is the time to solve it.
A problem is
poly-time solvable
if
T
(
n
) =
O
(
n
k) for some constant k.Complexity class P=set of problems that are poly-time solvable.Slide15
15
Class NP problems
For a problem
p
, given its certificate, the certificate can be verified in poly time.
Call this kind of problem an NP one.Slide16
16
NP-completeness and Reducibility
A (class of) problem P
1
is
poly-time reducible
to P
2
, written as P
1
p
P
2
if there exists a poly-time function
f
: P1 P2 such that for any instance of p
1 P1, p1 has “YES” answer if and only if answer to f(p1) ( P2) is also “YES”.Theorem 34.3For two problems P1
, P2, if P1p P2 then P2 P implies P1 P. Slide17
17
NP-completeness and Reducibility (cont.)
A problem p
is
NP-complete
if
p NP and
p
'
p
p
for every p
'
NP.
(if p satisfies 2, then p is said
NP-hard
.)Theorem 34.4 if any NP-compete problem is poly-time solvable, then P=NP. Or say: if any problem in NP is not poly-time solvable, then no NP-complete problem is poly-time solvable. Slide18
Review: P
and
NPWhat do we mean when we say a problem is in P?What do we mean when we say a problem is in NP?What is the relation between P and NP?Slide19
Review: P
and
NPWhat do we mean when we say a problem is in P?A: A solution can be found in polynomial timeWhat do we mean when we say a problem is in NP?A: A solution can be verified in polynomial timeWhat is the relation between P and NP?A: P
NP, but no one knows whether P = NPSlide20
Review: NP-Complete
What, intuitively, does it mean if we can
reduce problem P to problem Q?How do we reduce P to Q?What does it mean if Q is NP-Hard?What does it mean if Q is NP-Complete?Slide21
Review: NP-Complete
What, intuitively, does it mean if we can
reduce problem P to problem Q?P is “no harder than” QHow do we reduce P to Q?Transform instances of P to instances of Q in polynomial time s.t. Q: “yes” iff P: “yes”What does it mean if Q is NP-Hard?Every problem PNP p QWhat does it mean if Q is NP-Complete?Q is NP-Hard and Q
NPSlide22
Review:
Proving Problems NP-Complete
How do we usually prove that a problem Ris NP-Complete?A: Show R NP, and reduce a known NP-Complete problem Q to RSlide23
Hamiltonian Cycle
A Hamiltonian cycle, also called a Hamiltonian circuit, Hamilton cycle, or Hamilton circuit, is a
graph cycle (i.e., closed loop) through a graph that visits each node exactly once (Skiena 1990, p. 196)A graph possessing a Hamiltonian cycle is said to be a Hamiltonian graph.Slide24
Directed
Undirected
Ham. Cycle Given: directed hamiltonian cycle is NP-Complete Transform graph G = (V, E) into G’ = (V’, E’):Every vertex v in V transforms into 3 vertices v1, v2, v3 in V’ with edges (
v1,
v
2
) and (
v
2
,
v
3
) in E’
Every directed edge (
v
,
w
) in E transforms into the undirected edge (
v3, w1) in E’ Slide25
Directed
Undirected
Ham. CycleProve the transformation correct:If G has directed hamiltonian cycle, G’ will have undirected cycle (straightforward)If G’ has an undirected hamiltonian cycle, G will have a directed hamiltonian cycleThe three vertices that correspond to a vertex v in G must be traversed in order v1, v2, v3 or v3, v2, v1, since v2 cannot be reached from any other vertex in G’Since 1’s are connected to 3’s, the order is the same for all triples. Assume w.l.o.g. order is v
1, v2,
v
3
.
Then G has a corresponding directed hamiltonian cycleSlide26
Traveling Salesman Problem (TSP)
Definition:
Given a list of cities and the distances between each pair of cities, what is the shortest possible route that visits each city exactly once and returns to the origin city?Slide27
Hamiltonian
Cycle
TSPThe well-known traveling salesman problem:Complete graph with cost c(i,j) from city i to city j a simple cycle over cities with cost < k ?How can we prove the TSP is NP-Complete?A: Prove TSP NP; reduce the undirected hamiltonian cycle problem to TSPTSP
NP: straightforward
Reduction: need to show that if we can solve TSP we can solve ham. cycle problemSlide28
Hamiltonian
Cycle
TSPTo transform ham. cycle problem on graph G = (V,E) to TSP, create graph G’ = (V,E’):G’ is a complete graph Edges in E’ also in E have weight 0All other edges in E’ have weight 1TSP: is there a TSP on G’ with weight 0?If G has a hamiltonian cycle, G’ has a cycle w/ weight 0If G’ has cycle w/ weight 0, every edge of that cycle has weight 0 and is thus in G. Thus G has a ham. cycleSlide29
The SAT Problem
One of the first problems to be proved NP-Complete was
satisfiability (SAT):Given a Boolean expression on n variables, can we assign values such that the expression is TRUE?Ex: ((x1 x2) ((x1 x3) x4))
x2
Cook’s Theorem:
The satisfiability problem is NP-Complete
Note: Argue from first principles, not reduction
Proof: not hereSlide30
Conjunctive Normal Form
Even if the form of the Boolean expression is simplified, the problem may be NP-Complete
Literal: an occurrence of a Boolean or its negationA Boolean formula is in conjunctive normal form, or CNF, if it is an AND of clauses, each of which is an OR of literalsEx: (x1 x2) (x1 x3 x4) (x5
)3-CNF: each clause has exactly 3 distinct literals
Ex:
(x
1
x
2
x
3
) (x
1
x
3
x
4
) (x
5 x3 x4)Notice: true if at least one literal in each clause is trueSlide31
The 3-CNF Problem
Thm
34.10: Satisfiability of Boolean formulas in 3-CNF form (the 3-CNF Problem) is NP-CompleteProof: NopeThe reason we care about the 3-CNF problem is that it is relatively easy to reduce to others Thus by proving 3-CNF NP-Complete we can prove many seemingly unrelated problems NP-CompleteSlide32
3-CNF
Clique
What is a clique of a graph G?A: a subset of vertices fully connected to each other, i.e. a complete subgraph of GThe clique problem: how large is the maximum-size clique in a graph?Can we turn this into a decision problem?A: Yes, we call this the k-clique problemCLIQUE={<G,k>: G is a graph with a clique of size k.}
Is the k-clique problem within NP?Slide33
3-CNF
Clique
What should the reduction do?A: Transform a 3-CNF formula to a graph, for which a k-clique will exist (for some k) iff the 3-CNF formula is satisfiableSlide34
3-CNF
Clique
The reduction:Let B = C1 C2 … Ck be a 3-CNF formula with k clauses, each of which has 3 distinct literalsFor each clause put a triple of vertices in the graph, one for each literalPut an edge between two vertices if they are in different triples and their literals are consistent, meaning not each other’s negationRun an example: B = (x y z) (x y z ) (x y z )Slide35
3-CNF
Clique
Prove the reduction works:If B has a satisfying assignment, then each clause has at least one literal (vertex) that evaluates to 1Picking one such “true” literal from each clause gives a set V’ of k vertices. V’ is a clique (Why?)If G has a clique V’ of size k, it must contain one vertex in each triple (clause) (Why?)We can assign 1 to each literal corresponding with a vertex in V’, without fear of contradictionSlide36
Clique
Vertex Cover
A vertex cover for a graph G is a set of vertices incident to every edge in GThe vertex cover problem: what is the minimum size vertex cover in G?Restated as a decision problem: does a vertex cover of size k exist in G?Thm 34.12: vertex cover is NP-CompleteSlide37
Clique
Vertex Cover
First, show vertex cover in NP (How?)Next, reduce k-clique to vertex coverThe complement GC of a graph G contains exactly those edges not in GCompute GC in polynomial timeG has a clique of size k iff GC has a vertex cover of size |V| - k Slide38
Clique
Vertex Cover
Claim: If G has a clique of size k, GC has a vertex cover of size |V| - k Let V’ be the k-cliqueThen V - V’ is a vertex cover in GCLet (u,v) be any edge in GCThen u and v cannot both be in V’ (Why?)Thus at least one of u or v is in V-V’ (why?), so
edge (u, v) is covered by V-V’
Since true for
any
edge in G
C
, V-V’ is a vertex coverSlide39
Clique
Vertex Cover
Claim: If GC has a vertex cover V’ V, with |V’| = |V| - k, then G has a clique of size kFor all u,v V, if (u,v) GC then u V’ or v
V’ or both (Why?)
Contrapositive: if
u
V’ and
v
V’, then
(
u
,
v
) E
In other words, all vertices in V-V’ are connected by an edge, thus V-V’ is a clique
Since |V| - |V’| =
k
, the size of the clique is
kSlide40
General Comments
Literally hundreds of problems have been shown to be NP-Complete
Some reductions are profound, some are comparatively easy, many are easy once the key insight is givenYou can expect a simple NP-Completeness proof on the finalSlide41
Other NP-Complete Problems
Subset-sum
: Given a set of integers, does there exist a subset that adds up to some target T?0-1 knapsack: when weights not just integersHamiltonian path: ObviousGraph coloring: can a given graph be colored with k colors such that no adjacent vertices are the same color?Etc…