NP-Completeness CS 583 Fall 2006 Analysis of Algorithms 7/1/2016

advertisement
NP-Completeness
CS 583 Fall 2006
Analysis of Algorithms
7/1/2016
CS583 Fall'06: NP-Completeness
1
Outline
• HW2/3 Status
• Overview
– Showing a problem to be NPC
• Polynomial time
– Abstract problems
– Encodings
• Verification in Polynomial Time
• NP-completeness
• Self-test
– 34.1-2, 34.2-3
• Final exam details
7/1/2016
CS583 Fall'06: NP-Completeness
2
HW 2/3 Status
• It is very likely that HW2 grades have been lost.
– HW2 solutions are posted on the web.
• Therefore, HW3 becomes “mandatory” to avoid
losing 10 points.
– The deadline is extended to Saturday, December 9
(midnight).
– The online submission needs to be e-mailed to the
instructor.
– The answers will posted on 12/10.
• If HW2 grades are recovered before 12/16, they will
be taken into account.
7/1/2016
CS583 Fall'06: NP-Completeness
3
Overview
• Three classes of problems:
– Class P consists of those problems that are solvable in
polynomial time.
• An algorithm runs in O(nk) for some constant k, where n is the
size of the input.
– Class NP consists of problems that are “verifiable” in
polynomial time.
• It can be verified in polynomial time that a given solution is
feasible.
– A problem is in the class NPC if it is in NP, and is as
“hard” as any other problem in NP.
• If any NP-complete problem can be solved in polynomial time,
then every problem in NP has a polynomial time algorithm.
• Most computer scientists believe NPC problems are intractable,
i.e. P  NP.
7/1/2016
CS583 Fall'06: NP-Completeness
4
Showing a Problem to be NPC
• Decision problems versus optimization problems.
– Many problems of interest are optimization problems:
• Each feasible solution has an associated value, and we wish to
find the one with the best value.
• For example, the graph coloring problem: use the least number of
colors, so that no two adjacent vertices are colored the same.
– NP-completeness applies to decision problems:
• The answer to a problem is “yes” or “no”.
• For example, the graph coloring decision problem: can a graph be
colored with k colors?
– An optimization problem can be cast to a decision
problem.
• The decision problem is “easier” as once an optimization problem
is solved, its related decision problem is solved as well.
7/1/2016
CS583 Fall'06: NP-Completeness
5
Reductions
• We show that one decision problem is no easier or
harder than another one.
– Suppose we have a decision problem A that we wish to
solve in polynomial time.
– Assume we have a decision problem B that we can solve
in polynomial time.
– Develop a procedure that converts an instance (input)  of
A into instance  of B as follows.
• The transformation takes polynomial time.
• The answers are the same: the answer for  is “yes” if and only if
the answer for  is also “yes”.
7/1/2016
CS583 Fall'06: NP-Completeness
6
Reductions (cont.)
• Such procedure is called a reduction algorithm as it
allows solving A in polynomial time:
– Given an instance  of A, use a polynomial-time
reduction algorithm to transform it to an instance  of B.
– Run B in polynomial time on input .
– Use the answer for  as the answer for .
• It can be shown that if it is proven that A is
intractable, then B cannot be solved in polynomial
time as well.
– Proof: by contradiction.
7/1/2016
CS583 Fall'06: NP-Completeness
7
A First NPC Problem
• The technique of reduction relies on having a
problem known to be NP-complete.
• Hence we need to start with some NPC problem.
• The “first” such problem we use is the circuitsatisfiability problem:
– Given a boolean combinational circuit composed of AND,
OR, and NOT gates,
– We wish to know if there’s any set of boolean inputs to
this circuit that causes its output to be 1.
7/1/2016
CS583 Fall'06: NP-Completeness
8
Polynomial time
• The polynomial time problems are considered
tractable for the following reasons:
– A problem that runs in (n100) is practically intractable.
However,
• In practice there are very few such problems.
• When a problem running in (n100) is solved, it is likely that
much better algorithms are discovered.
– A problem that can be solved in polynomial time in one
model, can be solved in P time in another.
• Parallel algorithms.
– Class P has closure properties.
• An algorithm composed of P-time algorithms is also polynomial.
7/1/2016
CS583 Fall'06: NP-Completeness
9
Abstract Problems
• An abstract problem Q is a binary relation on a set I
of problem instances, and a set S of solutions:
– Q: I  S, e.g., (i1, s1)  Q, where i1  I, s1  S.
• Decision problems have a yes/no solution:
– S = {0, 1}
– Example: graph coloring decision problem COLOR:
• If i = (G, k) is an instance of the problem COLOR, then
• COLOR(i) = 1 (yes) if graph G can be colored with k colors
• COLOR(i) = 0 (no) otherwise
• Recall that more practical optimization problems
can be recast as decision problems.
7/1/2016
CS583 Fall'06: NP-Completeness
10
Concrete Problems
• An encoding of a set S of abstract objects is a mapping e
from S to the set of binary strings.
– Example: natural numbers (set N={0,1,2,...}) can be represented as
binary numbers:
• e(3) = 11, e(4) = 100, ... , e(17) = 10001
• An algorithm that “solves” some abstract decision problem
takes an encoding of a problem instance as input.
– A problem whose instance set is a set of binary strings is called a
concrete problem.
– An algorithm solves a concrete problem in O(T(n)) time, where n =
|i|
– A problem is polynomial-time solvable if T(n) = nk for some constant
k.
• The complexity class P is a set of concrete decision problems
that are polynomial-time solvable.
7/1/2016
CS583 Fall'06: NP-Completeness
11
Formal-Language Framework
• The machinery of formal-language theory is very
convenient for decision problems.
– An alphabet  is a finite set of symbols.
– A language L over  is any set of strings made up of
symbols from .
• For example,  ={0,1}, L = {10,11,101, ...} – prime numbers
– An empty string is denoted by ,
– An empty language is denoted by .
– The language of all strings over  is denoted *.
• For example,  ={0,1}, * = {, 0 , 1, 00, 10, 11, 101, ...} – the
set of all binary strings.
7/1/2016
CS583 Fall'06: NP-Completeness
12
Formal-Language Framework (cont.)
• Operations on languages:
– Union and intersection follow directly from set
operations.
– The complement of L is  L = * - L.
– The concatenation of two languages L1 and L2 is the
language
• L = {x1x2: x1  L1 and x2  L2}
– The closure, or Kleene star of language L is
• L* = {}  L  L2  L3  ...
• Hence, the set of instances for any decision problem
Q is simply the set *, where  = {0,1}.
7/1/2016
CS583 Fall'06: NP-Completeness
13
Formal-Language Framework (cont.)
• Q is a language L over  = {0,1}, where
– L = {x  * : Q(x) = 1}
• Expressing the relation between decision problems
and algorithms.
– An algorithm A accepts a string x  {0,1}* if
• given input x, the algorithm outputs A(x) = 1.
– An algorithm rejects x if A(x) = 0.
– The language accepted by A is
• L = {x  {0,1}* : A(x) = 1}
– A language L is decided by A if
• every binary string in L is accepted by A, and
• every binary string not in L is rejected by A.
7/1/2016
CS583 Fall'06: NP-Completeness
14
Formal-Language Framework (cont.)
• A language L is accepted in polynomial time by algorithm A
if:
– it is accepted by A, and
– there is a constant k such that for any x  L, |x| = n it accepts x in
O(nk).
• A language L is decided in polynomial time if:
– there is a constant k such that for any x  {0,1}*, |x| = n, A correctly
decides whether x  L in O(nk).
• Thus, to accept a language, an algorithm only needs to
consider strings in L, but to decide it, it needs to consider
every string in {0,1}*.
• The complexity class P:
– P = {L  {0,1}* : there exists an algorithm A that decides L in
polynomial time}
7/1/2016
CS583 Fall'06: NP-Completeness
15
Hamiltonian Cycle Problem
• Hamiltonian cycle:
– A hamiltonian cycle of a graph G=(V,E) is a simple cycle that
contains all vertices in V.
– A graph that contains a hamiltonian cycle is called hamiltonian.
• The Hamiltonian cycle problem defined in a formal
language:
– HAM-CYCLE = {<G> : G is a hamiltonian graph}
• Brute-force algorithm:
– Take each permutation of vertices and check if it’s a hamiltonian
graph.
– Running time:
•
•
•
•
7/1/2016
Assume the encoding is its adjacency matrix of size n.
The number of vertices m = (n1/2).
There are m! possible permutations of vertices.
The running time of such algorithm is (m!) = (n1/2!) = (2n1/2) – not
polynomial!
CS583 Fall'06: NP-Completeness
16
Verification Algorithm
• When a certain permutation of vertices is given, it can be
verified if it’s a hamiltonian cycle in O(n2) time.
• A verification algorithm is a two-argument algorithm A:
– One argument is an input string x.
– The other argument is a binary string y called a certificate.
– A verifies an input x if there exists a certificate y such that
• A(x,y) = 1
– The language verified by A is
• L = {x  {0,1}* : there exists y  {0,1}* such that A(x,y) = 1}
– A verifies L if for any string x  L, there is a certificate y that A can
use to prove that x  L.
• In the HAM-CYCLE problem, the certificate is the list of vertices in
some hamiltonian cycle.
– If the graph is hamiltonian, the cycle is sufficient to verify the fact.
– If it is not hamiltonian, no such certificate exists.
7/1/2016
CS583 Fall'06: NP-Completeness
17
The Complexity Class NP
• NP is the class of languages that can be verified by a
polynomial-time algorithm A(x,y):
– L = {x  {0,1}* : there exists a certificate y with |y| = O(|x|c) such that
c is constant and A(x,y) = 1}
– We say that algorithm A verifies language L in polynomial time.
• If L P, then L NP
– If there is a polynomial time algorithm to decide L, it can be
converted to a verification algorithm to ignore the certificate.
– Hence P  NP.
• It is unknown if P = NP
– The class of NP-complete algorithms makes this question even more
intriguing:
• If one NPC algorithm can be solved in polynomial time, then every
problem in NP has a polynomial time solution!
7/1/2016
CS583 Fall'06: NP-Completeness
18
Final Exam
• Taking the exam:
– The exam will be available to take in a classroom.
– The exam will be available online on case-by-case basis only.
• The exceptions will be granted based on good cause.
• The online version will be distributed by e-mail.
• The NEW session will be open during the exam for student questions.
– The student evaluations will be taken before the exam.
• Exam details:
– It is an “open everything” exam.
– The duration is 2.5 hours, -- from 7:45 to 10:15.
– It consists of 4 main problems (10 points each), and 2 bonus questions (2
points each).
– The exam covers the contents of all classes, although it will contain more
questions from the second half of the course (after the midterm exam).
• Overall grading:
– A: 90+ points
– B+: 85+; B: 80+; B-: 75+
– C: 65+; D: 60+
7/1/2016
CS583 Fall'06: NP-Completeness
19
Download