Title: NP Completeness
1NP Completeness
Instructor Yao-Ting Huang
Bioinformatics Laboratory, Department of Computer
Science Information Engineering, National Chung
Cheng University.
2Quiz
- Find all-pair shortest path.
- Please give the shortest paths of (1, 4), (3, 2),
(2, 1).
3Final Exam
- Final exam will be started at 1/11 1/15.
- Place to be determined.
4The Halting Problem
Input
a program Q
Question
Decide if this program will halt
5Construct a New Program D
D
P
Loop forever
YES
Q
NO
6Construct a New Program D
- Suppose P solves variant of halting problem
- On input Q, assume
- P(Q) yes if Q will halt.
- Build program D
- D(Q) run forever if P(Q) yes
- What will D(D) do?
- If D(D) halts, P(D) Yes and D(D) runs forever.
- If D(D) runs forever, P(D) No and D(D) halts.
- CONTRADICTION program P must not exist.
7Polynomial-Time Algorithms
- Are some problems solvable in polynomial time?
- Of course every algorithm weve studied provides
polynomial-time solution to some problem - We define P to be the class of problems solvable
in polynomial time - Are all problems solvable in polynomial time?
- No Turings Halting Problem is not solvable by
any computer, no matter how much time is given - Such problems are clearly intractable, not in P.
- But how about the others?
8Shortest and Longest Paths
- So far we have known that shortest path problems
can be solved in polynomial time. - How about finding the longest simple path?
- A hamiltonian path of an undirected graph is a
simple path that visits every vertex once. - The hamiltonian-path problem
- Given a graph G, does it have a hamiltonian path?
- The hamiltonian-cycle problem
- Given a graph G, does it have a hamiltonian cycle?
9Hamiltonian-cycle problem
10P and NP
- As mentioned, P is set of problems that can be
solved in polynomial time - NP (nondeterministic polynomial time) is the set
of problems that can be solved in polynomial time
by a nondeterministic computer - What the hell is that?
11Nondeterminism
- Think of a non-deterministic computer as a
computer that magically guesses a solution,
then has to verify that it is correct - If a solution exists, computer can find it.
- One way to imagine it a parallel computer that
can freely process an infinite number of
processes - Have one processor work on each possible solution
- All processors attempt to verify that their
solution works - If a processor finds it has a working solution
- NP solutions verifiable in polynomial time
12Nondeterminism
- Hamiltonian-cycle problem is in NP
- Cannot solve in polynomial time so far.
- But easy to verify solution in polynomial time.
13P and NP
- Summary so far
- P problems that can be solved in polynomial
time - NP problems for which a solution can be
verified in polynomial time. - Unknown whether P NP (most suspect not)
14P NP??
- We call this the P NP question
- The biggest open problem in CS.
- If you can prove this equation (either yes or
no), you will be awarded Turing Award for sure
plus at least US1,000,000.
15Problems in NP
- In practice, many important problems are known to
be in NP but not in P yet. - Traveling sales problem.
- VLSI layout.
- Biology
16Distinguishing a Sample
Haplotype patterns
An unknown sample
P1
P2
P3
P4
S1
- We can extract all nucleotides to distinguish an
unknown haplotype sample. - But there are billion of nucleotides in the human
genome.
S2
S3
S4
S5
S6
SNP loci
S7
S8
S9
major allele
S10
S11
minor allele
S12
17Examples of Tag SNPs
Haplotype pattern
P1
P2
P3
P4
S1
- In fact, it is not necessary to genotype all
SNPs. - SNPs S3, S4, and S5 can form a set of tag SNPs.
S2
S3
S4
S5
S6
SNP loci
P1
P2
P3
P4
S7
S8
S3
S9
S4
S10
S5
S11
S12
18Examples of Tag SNPs
Haplotype pattern
P1
P2
P3
P4
S1
- SNPs S1, S2, and S3 can not form a set of tag
SNPs because P1 and P4 will be ambiguous.
S2
S3
S4
S5
S6
SNP loci
P1
P2
P3
P4
S7
S1
S8
S2
S9
S3
S10
S11
S12
19Examples of Tag SNPs
Haplotype pattern
- SNPs S1 and S12 can form a set of tag SNPs.
- The problem of finding the minimum set of tag
SNPs is NP-hard (Bafna et al., Zhang, et. al.).
P1
P2
P3
P4
S1
S2
S3
S4
S5
S6
SNP loci
S7
S8
P1
P2
P3
P4
S9
S1
S10
S12
S11
S12
20Hardness of Finding Tag SNPs
- The naïve approach is testing each combination of
SNPs - (12, 1) (12, 2) (12, 12) 212 .
P1
P2
P3
P4
21Hardness of Finding Tag SNPs
- Is it possible to do in O(nk )?
P1
P2
P3
P4
22Should We Try?
- Many smart people have tried to solve these
problems over past decades. - Yet none of above problems are solved in
polynomial time. - A genius saved us by proving a way to evaluate
the hardness of a problem. - Problems that can be reduced to certain problems
(called NP-hard problems) are considered to be
hard.
23Reduction
- Informally, a problem P can be reduced to another
problem Q if any instance of P can be easily
rephrased as an instance of Q, the solution to
which provides a solution to the instance of P. - What do you suppose easily means?
- This rephrasing is called transformation
- Intuitively If P reduces to Q, P is no harder
to solve than Q - Q is at least as hard as P.
24An Example of Reduction
- P Single source shortest-path
- Q All pairs shortest paths
- P can be easily reduced to Q.
- Q is at least as hard as P.
25An Example of Reduction
- An example
- P Given a set of Booleans, is at least one TRUE?
- Q Given a set of integers, is their sum
positive? - Transformation (x1, x2, , xn) (y1, y2, , yn)
where yi 1 if xi TRUE, yi 0 if
xi FALSE - Q is at least as hard as P.
- If P is polynomial-time reducible to Q, we denote
this P ?p Q
26NP-Hard and NP-Complete
- Definition of NP-Hard
- If all problems R ? NP are reducible to P, then P
is NP-Hard - Definition of NP-Complete
- P is NP-Complete if P is NP-Hard and P ? NP
- Formally R ?p P ? R ? NP
- If P ?p Q and P is NP-Complete, Q is also
NP-Complete - This is the key idea you should take away today
27NP-Complete Problems
- We will see that NP-Complete problems are the
hardest problems in NP - If any NP-Complete problem can be solved in
polynomial time, then every NP-Complete problem
can be solved in polynomial time. - That is, every problem in NP can be solved in
polynomial time (which would show P NP) - Thus solve Hamiltonian-cycle in O(n100) time,
youve proved that P NP. Retire rich famous.
28NP-Complete Problems
- The NP-Complete problems are an interesting class
of problems whose status is unknown - No polynomial-time algorithm has been discovered
for an NP-Complete problem. - This class of problems are used to prove the
hardness of a problem.
29A First NP-complete problem
- Because reduction relies on having a problem
already known to be NP-complete, a first
NP-complete problem was proven by Turing. - Circuit-satisfiability problem
30(No Transcript)
31Why Prove NP-Completeness?
- Though nobody has proven that P ! NP, if you
prove a problem is NP-Complete, most people
accept that it is probably very hard. - Dont try hard to come up with an efficient
algorithm.
32Proving NP-Completeness
- What steps do we have to take to prove a problem
P is NP-Complete? - Pick a known NP-Complete problem Q
- Reduce Q to P
- Describe a transformation that maps instances of
Q to instances of P, s.t. yes for P yes for
Q - Prove the transformation works
- Prove it runs in polynomial time
33An Example
- Suppose we have known directed Himitonian-cycle
is NP-complete. - Does undirected Hamitonian-cycle is NP-complete?
34Undirected Hamitonian-cycle in NP
- Given a sequence of V vertices that makes up the
hamiltonian cycle. - The verification algorithm checks if this
sequence contains each vertex exactly once. - The first vertex is repeated at the end.
- It checks if there is an edge between all pairs
of vertices (cycle).
35ReductionDirected ? Undirected Ham. Cycle
- 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,v2) and (v2,v3)
in E - Every directed edge (v, w) in E transforms into
the undirected edge (v3, w1) in E (draw it) - Can this be implemented in polynomial time?
G
G
36Directed ? Undirected Ham. Cycle
- Prove the reduction is correct
- If G has directed hamiltonian cycle, G will have
undirected cycle (straightforward)
G
G
37Directed ? Undirected Ham. Cycle
- Is it possible G has a hamiltonian cycle but G
does not have?
G
G
38Directed ? Undirected Ham. Cycle
- If G has an undirected hamiltonian cycle, G will
have a directed hamiltonian cycle as well. - The three vertices that correspond to a vertex v
in G must be traversed in order v1, v2, v3 v3,
v2, v1, since v2 cannot be reached from any other
vertex in G - Every directed edge (v, w) in E transforms into
the undirected edge (v3, w1) in E - Then G has a corresponding directed hamiltonian
cycle
39Summary of the Proof
- We have to show a problem P is NP.
- We have to find an NP-complete problem Q.
- Design a method for reducing all instances of Q
to instances of P. - Show solutions of instances of Q are also
solutions of instances of P. - Show solutions of reduced instances of P are also
solutions of instances of Q.
40Hamiltonian Cycle ? TSP
- The well-known traveling salesman problem
- Optimization variant a salesman must travel to n
cities, visiting each city exactly once and
finishing where he begins. How to minimize
travel cost? - Model as complete graph with cost c(i,j) to go
from city i to city j - TSPs (and variants) have enormous practical
importance - E.g., for shipping and freighting companies
- How would we turn this into a decision problem?
- A ask if ? a TSP with cost lt k
41Hamiltonian Cycle ? TSP
- The steps to prove TSP is NP-Complete
- Show TSP ? NP
- Reduce the undirected hamiltonian cycle problem
to the TSP - So if we had a TSP-solver, we could use it to
solve the hamilitonian cycle problem. - How can we reduce all instances of the
hamiltonian cycle problem to instances of the
TSP? - Can we do this in polynomial time?
42Hamiltonian Cycle ? TSP
- To reduce hamiltonian 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 0
- All other edges in E have weight 1
- TSP is there a TSP on G with weight 0 (Klt1)?
- If G has a hamiltonian cycle, G has a cycle with
weight 0 - If G has cycle with weight 0, every edge of that
cycle has weight 0 and is thus in G. Thus G has
a ham. cycle
43Next Example
- Suppose we know a k-clique problem is
NP-complete. - Show another problem vertex-cover is also
NP-complete.
44Clique
- Clique is a subset of vertices fully connected to
each other. - A complete subgraph of G
- The clique problem Does a clique of size k exist
in G (for any k)? - Naïve algorithm
45Vertex Cover
- A vertex cover for a graph G is a set of vertices
incident to every edge in G - The vertex cover problem does a vertex cover of
size k exist in G.
46Clique ? Vertex Cover
- First, show vertex cover in NP.
- Next, reduce k-clique to vertex cover
- The complement GC of a graph G contains exactly
those edges not in G - Compute GC in polynomial time
- G has a clique of size k iff GC has a vertex
cover of size V - k
47Clique ? Vertex Cover
GC
G
48Clique ? 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-clique
- Then V - V is a vertex cover in GC
- Let (u,v) be any edge in GC
- Then u and v cannot both be in V
- Thus at least one of u or v is in V-V, so edge
(u, v) is covered by V-V - Since true for any edge in GC, V-V is a vertex
cover
49Clique ? Vertex Cover
- Claim If GC has a vertex cover V with V
V - k, then G has a clique V of size k. - For all u,v ? V, if (u,v) ? GC then u ? V or v
? V or both. - If u ? V and v ? V, then (u,v) ? G
- 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 k
50Clique ? Vertex Cover
GC
G
Vz, w
Vu, v, y, x
51Concluding Remarks
- Hundreds of problems have been shown to be
NP-Complete. - Hamiltonian path/cycle
- Vertex cover.
- Set cover.
-
- Some reductions are profound, some are
comparatively easy, many are easy once the key
insight is given. - You can expect at least one NP-Completeness proof
in the final exam.