CSC 505, Fall 000: Week 0 Objectives: understand problem complexity and classes defined by it understand relationships among decision, witness, evaluation, and optimization problems understand what it means to reduce one problem to another understand the meaning of membership in the class NP, and NP-completeness Page of
A complexity class (a class of problems that are related based on the efficiency -- time or space -- of the best possible algorithms for them) Class P is the class of all decision problems that can be solved in time polynomial in the input size. Questions:. Why polynomial? (i.e. why is P an important class?). Why decision problems? 3. How do we count time and input size? Page of
MST as a decision problem/language MST decision problem: Given a weighted,undirected graph G = (V,E,w) and an integer k, does G have a spanning tree whose total weight is k? L MST = { strings z z encodes a graph G = (V,E,w) and an integer k and G has a spanning tree T with w(t) k } 4 5 G = 8 3 z = #0#00####0##0##000### Do the details of the encoding matter? Page 3 of
Rules for this particular encoding alphabet = {0,,#} fixed, finite instance ::= graph ### int G and k graph ::= edge {## edge } list of edges edge ::= vertex #vertex # int ends and weight vertex ::= int vertex names are ints int ::= bit { bit } ints are in binary bit ::= 0 8 6 9 5 Another example: G = 3 7 4 k =8 #0#000####0###0#00###00###0#00#0###000 Page 4 of
Types of combinatorial problems Optimization a combinatorial object (set, sequence,... ) of optimum (min/max) weight Example: Output a minimum spanning tree T of G = (V,E,w). Evaluation the weight of an optimum object Example: Output w(t ), the weight of a minimum spanning tree T of G = (V,E,w). Decision yes/no (does an object of a certain weight or better exist) Example: Given G = (V,E,w) and an integer k, does there exist a spanning tree T such that w(t) k? Witness a certificate for the decision problem, i.e. proof of a yes answer if such proof exists Example: Given G = (V,E,w) and an integer k, output a spanning tree T with w(t) k or report that none exists. Page 5 of
Are the problem types related? If you can solve the optimization problem (in polynomial time), you can solve the evaluation, decision, and witness problems (in polynomial time). (Obvious. Why?) If you can solve the decision problem, you can solve the evaluation problem. (Binary search on the interval of possible solution values) If you can solve both the evaluation and the witness problem, you can solve the optimization problem. (Easy. How?) The missing link is how to solve the witness problem using the decision problem. Page 6 of
Self-reducibility u w v Graph G has a spanning tree with weight k. Can you determine if edge (u,v) is in such a spanning tree? Your only resource is a black box that allows you to input a graph and a weight and will output yes if there is a spanning tree with that weight or less, no otherwise. You can perform modifications on G but you can t look at it (i.e. you can put a modified form of G into the box). Page 7 of
Using the decision problem to solve the witness problem function MST-Witness(G, k) is returns a spanning tree of G with weight k, if one exists. Pick an arbitrary u V [G] for each v Adj[u] do if MST-Decision(G/uv, k w(uv)) then return MST-Witness(G/uv, k w(uv)) G/uv is G with u and v joined into one vertex. ERROR: no such tree end MST-Witness Time bound, i.e. number of times MST-Decision is called? Page 8 of
Non-deterministic algorithm for MST-Decision function MST-Decision(G, k) is returns true iff a spanning tree of G with weight k exists Choose n edges to form a subset T E[G] Use DFS (for example) to check that T is a spanning tree (quit when a cycle is found or there s more than one tree). Add up edge costs and check that the total is k. if T passes both tests then return true else return false end MST-Witness Guess a certificate and then check the validity of the certificate. Page 9 of
What is nondeterminism and what is NP? How nondeterminism works. If there exists a choice that leads to a yes answer, the algorithm answers yes (true) for that instance. magic no computational device works this way. Why nondeterminisim is useful. Algorithms are simple. Algorithms can be simulated by deterministic ones. It is a useful way to classify problems. N P is the class of all decision problems that can be solved by a nondeterministic algorithm (guess a certificate and check) in polynomial time (certificate has polynomial size; checking takes polynomial time). Compare with text! Page 0 of
P and NP: what s all the fuss about? NP?? Traveling salesperson problem Polynomial algorithm? Non-polynomial lower bound? At least as hard as... P Minimum spanning-tree problem TSP: Given an n x n distance matrix D (where D[i,j] = distance from city i to city j) and an integer K, does there exist a permutation p of {,...,n} so that D[p(n),p()] + sum i from to n of D[p(i),p(i+)] is at most K? Page of
Reduction: a confusing concept A reduces to B means A can be solved in terms of B, or A is at least as easy as B. In divide-and-conquer, greedy, dynamic and programming: reduce (an instance of) a problem to (a smaller instance of) itself. Witness problem can be solved in terms of decision problem. An instance of transitive closure is reduced to several instances of matrix multiplication and 3 smaller instances of transitive closure. So an O(n α )-time algorithm for matrix multiplication with α implies an O(n α )-time algorithm for transitive closure. But A reduces to B can also mean B is at least as hard as A. If transitive closure can t be solved in O(n α ) time for some α, neither can matrix multiplication! If A is known to be hard (NP-complete) and A reduces (in polynomial time) to B, then B is also hard (NP-complete). Page of
Reduction: technical details (Decision) problem P reduces in polynomial time to problem P, notation P P P, if there exists a polynomialtime reduction algorithm F that transforms an arbitrary instance of P to an instance of P so that F (x) has a yes answer in P if and only if x has a yes answer in P. Simple example: PATH P SR. An instance of PATH is a directed, unweighted graph G = (V,E) and two vertices s and t answer yes if there is a path from s to t in G. An instance of SR (shortest route) is an n n distance matrix D = {D[i, j]}, two cities s and t, and an integer B answer yes if there is a sequence s = x 0, x,...,x k = t so that k i=0 D[x i,x i+ ] B. How does the reduction algorithm work? Page 3 of
Proof of correctness for the reduction Let F (G, s, t) be defined by the following:. Number V [G] from to n, where n = V [G].. For each pair i, j, if ij E[G], let D[i, j] = 0, otherwise let D[i, j] =. Let B = 0 and output D,s,t,B. Claim: There is a path from s to t in G iff there is a path with sum of all edges = 0 from s to t using the distance matrix D. Page 4 of
Another reduction: TSP to Longest simple path TSP P LSP. An instance of LSP (longest simple path) is a weighted, directed graph G = (V,E,w), two vertices s and t, and an integer bound B answer yes if G has a path P from s to t with w(p ) B. Let F(D,K) be defined by the following:. Let V = {,...,n } {s, t} and E = {uv u, v n } {su u n } {ut u n }.. Let ˆd be the largest distance in D and let w(u, v) = ˆd D[u, v] if u, v n. Let w(s, u) = ˆd D[n, u] and let w[u, t] = ˆd D[u, n]. 3. Let B = n ˆd K and output G, s, t, and B. Page 5 of
Example of the TSP to LSP reduction TSP: 3 Corresponding LSP: 0 s 3 as 3 source 3 0 4 0 5 6 3 0 Transform: cycle to path, to 5 4 4 5 t 3 as target Counterclockwise tour: 3 > > >3 6 Cost = 3 3 High-Low path: s > > >t Cost = Low-High path: s > > >t Cost = Clockwise tour: 3 > > >3 Cost = Page 6 of
Correctness of the reduction? Need to prove:. Certificate for TSP instance D,K implies certificate for LSP instance F (D,K). Let π be a permutation that certifies D,K and assume wlog that π() = n (since only the cyclic order matters). This means that D[π(n), n] + n i= D[π(i), π(i+ )] K. From the construction of the LSP instance, we can see that the path s π()π(3)...π(n) t has total weight ( ˆd D[π(n), n])+ n i= ( ˆd D[π(i), π(i+ )]) n ˆd K = B. The converse: Certificate for LSP instance F(D,K) implies certificate for TSP instance D,K. Suppose s = v...v k = t is a simplepath from s to t with weight B, that is, k i= w(v i, v i+ ) B. There s a problem here: we d like to transform his path into a permutation. What might prevent that? Page 7 of
A possible problem with the proof 3 3 0 0 0 3 Let K = 5 s 3 as source 0 0 0 0 0 t 3 as target Then B = 3 x 5 = and s t is a path with weight B. Page 8 of
Adjusting the transformation The largest reasonable value for K is n ˆd (Otherwise we can transform to a trivial yes-instance). Suppose in F (D,K) we let w(u, v) = n ˆd + D[u, v] and B = n ˆd + n K. weight of a certificate path B = n ˆd + n K n ˆd + n n ˆd > (n )(n ˆd + ) weight of a path with < n edges Thus, a certificate path for F (D,K) must have at least n edges, and, being a simple path, must visit every vertex. Page 9 of
The bad example revisited s 3 as source 3 6 5 3 0 0 0 5 5 5 5 t 3 as target w(u,v) = 3 x + D[u,v] 3 Let K = 5 Then B = 9 x + 3 5 = 6 A certificate has weight at least K and the edges have weight 7 a, 7 b, and 7 c. Thus, a + b + c K. Page 0 of
Summary of polynomial reduction Proving that A P B: Specify in detail how any instance x of A is to be transformed into an instance f(x) of B. This should be like a recipe, so that there s no ambiguity and no doubt that it can be done in polynomial time. Show how a certificate y for x can be converted to a certificate for f(x). Show how a certificate z for f (x) can be converted to a certificate for x. This is important. Page of