=========================================================================== CSC 363H Lecture Summary for Week 10 Fall 2007 =========================================================================== More examples of NP-completeness INDEPENDENT-SET = { | G is an undirected graph that contains an independent set of size k -- a subset of vertices with NO edge between any two of them } - INDEPENDENT-SET (IS) is NPc: . in NP: certificate = independent set . NP-hard: VC <=p IS: Given , construct as follows: G' = G, k' = n-k. Clearly this can be done in polytime. Also, if G contains a vertex cover of size k, the vertices outside the cover form an independent set of size n-k (no edge can have both endpoint outside the cover). Finally, if G' contains an independent set of size n-k, the vertices outside the independent set form a vertex cover of size k (every edge has at least one endpoint in the cover). - CLIQUE is NPc: Already known in NP. For NP-hardness, use reduction from INDEPENDENT-SET: On input , construct as follows: G' = complement of G (same vertices, edge in G' iff edge not in G) k' = k This construction can obviously be carried out in polytime. Moreover, if G contains an I.S. of size k, then the same set in G' will be a clique of size k; conversely, if G' contains a clique of size k, the same set in G will be an I.S. of size k. Note: textbook uses different reduction from 3SAT. - SUBSET-SUM is NPc: Already known in NP. For NP-hardness, show 3SAT <=p SS: Given formula F = (a1 \/ b1 \/ c1) /\ ... /\ (ar \/ br \/ cr) where ai,bi,ci in {x1,~x1,...,xs,~xs}, construct numbers as follows: . For j = 1,...,s, number xj = 1 followed by s-j 0s followed by r digits where k-th next digit equals 1 if xj appears in clause C_k, 0 otherwise; number ~xj = 1 followed by s-j 0s followed by r digits where k-th next digit equals 1 if ~xj appears in clause C_k, 0 otherwise. . For j = 1,...,r, number Cj = 1 followed by r-j 0s and number C'j = 2 followed by r-j 0s. . Target t = s 1s followed by r 4s. Clearly, this can be constructed in polytime. Example of reduction for F = (x1 \/ ~x2 \/ ~x4) /\ (x2 \/ ~x3 \/ x1) /\ (~x3 \/ x4 \/ ~x2): S = { x1 = 1000110, ~x1 = 1000000, x2 = 0100010, ~x2 = 0100101, x3 = 0010000, ~x3 = 0010011, x4 = 0001001, ~x4 = 0001100, C1 = 0000100, C'1 = 0000200, C2 = 0000010, C'2 = 0000020, C3 = 0000001, C'3 = 0000002 } t = 1111444 Note: slightly different from book to ensure S contains all distinct numbers (book's reduction constructs S with repeated numbers, so S not really a set). If F is satisfiable, then there is a setting of variables such that each clause of F contains at least one true literal. Consider the subset S' = {numbers that correspond to true literals}. By construction, SUM_{x in S'} x = s 1s followed by r digits, each one of which is either 1, 2, or 3 (because each clause contains at least one true literal). This means it is possible to add suitable numbers from {C1,C'1,...,Cr,C'r} so that the last r digits of the sum are equal to 4, i.e., there is a subset S' such that SUM_{x in S'} x = t. If there is a subset S' of S such that SUM_{x in S'} x = t, then S' must contain exactly one of {xj,~xj} for j = 1,...,n, because that is the only way for the numbers in S' to add to the target (with a 1 in the first s digits). Then, F is satisfied by setting each variable according to the numbers in S': for each clause j, the corresponding digit in the target is equal to 4 but the numbers Cj and C'j together only add up to 3 in that digit; this means that the selection of numbers in S' must include some literal with a 1 in that digit, i.e., clause j contains at least one true literal. ----------------- Self-reducibility ----------------- Note: This material is not in the textbook. This summary will therefore be slightly more detailed than usual. Problem of deciding language A sometimes called "decision problem": given input x, solution = yes/no answer. But many problems are more naturally "search problems": given input x, find solution y. Examples: - Given prop. formula F, find satisfying assignment, if one exists. - Given graph G, integer k, find a clique of size k in G, if one exists. - Given graph G, find a Ham. path in G, if one exists. - Given set of numbers S, target t, find subset of S whose sum equals t, if one exists. - etc. Many languages come from natural search problems. Clearly, efficient solution to search problem would give efficient solution to corresponding decision problem. So proof that decision problem is NP-hard implies that search problem is "hard" as well, and does not have efficient solution. But exactly how much more difficult are search problems? Perhaps surprisingly, many (but not all) are only polynomially more difficult than corresponding decision problem, in the following sense: any efficient solution to the decision problem can be used to solve the search problem efficiently. This is called "self-reducibility". Example 1: CLIQUE-SEARCH Input: Undirected graph G, positive integer k. Output: A clique of size k in G, if one exists; special value None if there is no such clique in G. - Idea: For each vertex in turn, remove it iff resulting graph still contains a k-clique. - Details: Assume we have an algorithm CL(G,k) that returns true iff G contains a clique of size k. We construct an algorithm to solve CLIQUE-SEARCH as follows. CLS(G,k): if not CL(G,k): return None # no k-clique in G for each vertex v in V: # remove v and its incident edges V' = V - {v}; E' = E - { (u,v) : u in V } # check if there is still a k-clique if CL(G'=(V',E'),k): # v not required for k-clique, leave it out V = V'; E = E' return V - Correctness: CL(G=(V,E),k) remains true at every step so at the end, V contains every vertex in a k-clique of G. At the same time, every other vertex will be taken out because it is not required, so V will contain no other vertex. Hence, the value returned is a k-clique of G. - Runtime: Each vertex of G examined once, and one call to CL for each one, plus linear amount of additional work (removing edges). Total is O((n+1)*t(n,m) + n*(n+m)) where t(n,m) is runtime of CL on graphs with n vertices and m edges; this is polytime if t(n,m) is polytime. - Exercise: What happens if G contains more than one k-clique? General technique to prove self-reducibility: - assume algorithm to solve decision problem, - write algorithm to solve search problem by making calls to decision problem algorithm (possibly many calls on many different inputs), - make sure that search problem algorithm runs in polytime if decision problem algorithm does -- argue at most polynomially many calls to subroutine are made and at most polytime spent outside those calls. Example 2: HAMPATH-SEARCH Input: Graph G. Output: A Ham. path in G. - Idea 1: For each vertex in turn, remove it iff resulting graph still contains a Ham. path. Problem: Every vertex must be in the path anyway, and this does not say where to put each vertex (which edges to use to travel through this vertex). - Idea 2: For each edge in turn, remove it iff resulting graph still contains a Ham. path -- same as for CLIQUE above, except considering edges one-by-one instead of vertices. Example 3: VERTEX-COVER-SEARCH Input: Graph G, integer k. Output: A vertex cover of size k, if one exists (None otherwise). - Idea 1: Remove vertices one-by-one as long as resulting graph still contains a vertex cover of size k. - Problem: If G contains a VC of size k, then G-v (remove v and all incident edges) also contains a VC of size k, whether or not v is in the cover (unless k=n, trivial to solve)! - Idea 2: Check if G-v contains a VC of size (k-1). Details next week...