
The knapsack Problem ² There is a set of n items. + + ² Item i has value vi 2 Z and weight wi 2 Z . ² We are given K 2 Z+ and W 2 Z+. ² knapsack asks if there exists a subset S ⊆ f1; 2; : : : ; ng P P such that i2S wi · W and i2S vi ¸ K. { We want to achieve the maximum satisfaction within the budget. °c 2011 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 357 knapsack Is NP-Completea ² knapsack 2 NP: Guess an S and verify the constraints. ² We assume vi = wi for all i and K = W . ² knapsack now asks if a subset of fv1; v2; : : : ; vng adds up to exactly K. { Picture yourself as a radio DJ. { Or a person trying to control the calories intake. aKarp (1972). °c 2011 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 358 The Proof (continued) ² We shall reduce exact cover by 3-sets to knapsack. ² The primary di®erences between the two problems are:a { Sets vs. numbers. { Union vs. addition. ² We are given a family F = fS1;S2;:::;Sng of size-3 subsets of U = f1; 2;:::; 3mg. ² exact cover by 3-sets asks if there are m disjoint sets in F that cover the set U. aThanks to a lively class discussion on November 16, 2010. °c 2011 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 359 The Proof (continued) ² Think of a set as a bit vector in f0; 1g3m. { 001100010 means the set f3; 4; 8g. { 110010000 means the set f1; 2; 5g. 3m z }| { ² Our goal is 11 ¢ ¢ ¢ 1. °c 2011 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 360 The Proof (continued) ² A bit vector can also be seen as a binary number. ² Set union resembles addition. { 001100010 + 110010000 = 111110010, which denotes the set f1; 2; 3; 4; 5; 8g, as desired. ² Trouble occurs when there is carry. { 010000000 + 010000000 = 100000000, which denotes the set f1g, not the desired f2g. { 001100010 + 001110000 = 011010010, which denotes the set f2; 3; 5; 8g, not the desired f3; 4; 5; 8g.a aCorrected by Mr. Chihwei Lin (D97922003) on January 21, 2010. °c 2011 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 361 The Proof (continued) ² Carry may also lead to a situation where we obtain our solution 11 ¢ ¢ ¢ 1 with more than m sets in F . { 000100010 + 001110000 + 101100000 + 000001101 = 111111111. { But the set on the left-hand side, f1; 3; 4; 5; 6; 7; 8; 9g, is not an exact cover. { And it uses 4 sets instead of the required m = 3.a ² To ¯x this problem, we enlarge the base just enough so that there are no carries. ² Because there are n vectors in total, we change the base from 2 to n + 1. aThanks to a lively class discussion on November 20, 2002. °c 2011 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 362 The Proof (continued) ² Set vi to be the integer corresponding to the bit vector encoding Si in base n + 1: X 3m¡j vi = (n + 1) j2Si ² Now in base n + 1, if there is a set S such that 3m P z }| { i2S vi = 11 ¢ ¢ ¢ 1, then every bit position must be contributed by exactly one vi and jSj = m. ² Finally, set 3m 3Xm¡1 z }| { K = (n + 1)j = 11 ¢ ¢ ¢ 1 (base n + 1): j=0 °c 2011 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 363 The Proof (continued) ² Suppose F admits an exact cover, say fS1;S2;:::;Smg. ² Then picking S = f1; 2; : : : ; mg clearly results in 3m z }| { v1 + v2 + ¢ ¢ ¢ + vm = 11 ¢ ¢ ¢ 1 : { It is important to note that the meaning of addition (+) is independent of the base.a { It is just regular addition. { But an Si may give rise to di®erent integer vi's under di®erent bases. aContributed by Mr. Kuan-Yu Chen (R92922047) on November 3, 2004. °c 2011 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 364 The Proof (concluded) ² On the other hand, suppose there exists an S such that 3m P z }| { i2S vi = 11 ¢ ¢ ¢ 1 in base n + 1. ² The no-carry property implies that jSj = m and fSi : i 2 Sg is an exact cover. °c 2011 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 365 An Example ² Let m = 3, U = f1; 2; 3; 4; 5; 6; 7; 8; 9g, and S1 = f1; 3; 4g; S2 = f2; 3; 4g; S3 = f2; 5; 6g; S4 = f6; 7; 8g; S5 = f7; 8; 9g: ² Note that n = 5, as there are 5 Si's. °c 2011 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 366 An Example (concluded) ² Our reduction produces 3£3 3£X3¡1 z }| { K = 6j = 11 ¢ ¢ ¢ 1 (base 6) = 2015539; j=0 v1 = 101100000 = 1734048; v2 = 011100000 = 334368; v3 = 010011000 = 281448; v4 = 000001110 = 258; v5 = 000000111 = 43: ² Note v1 + v3 + v5 = K. ² Indeed, S1 [ S3 [ S5 = f1; 2; 3; 4; 5; 6; 7; 8; 9g, an exact cover by 3-sets. °c 2011 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 367 bin packing ² We are given N positive integers a1; a2; : : : ; aN , an integer C (the capacity), and an integer B (the number of bins). ² bin packing asks if these numbers can be partitioned into B subsets, each of which has total sum at most C. ² Think of packing bags at the check-out counter. Theorem 46 bin packing is NP-complete. °c 2011 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 368 integer programming ² integer programming asks whether a system of linear inequalities with integer coe±cients has an integer solution. ² In contrast, linear programming asks whether a system of linear inequalities with integer coe±cients has a rational solution. °c 2011 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 369 integer programming Is NP-Completea ² set covering can be expressed by the inequalities P ~ n Ax ¸ 1, i=1 xi · B, 0 · xi · 1, where { xi is one if and only if Si is in the cover. { A is the matrix whose columns are the bit vectors of the sets S1;S2;:::. { ~1 is the vector of 1s. { The operations in Ax are standard matrix operations. ² This shows integer programming is NP-hard. ² Many NP-complete problems can be expressed as an integer programming problem. aPapadimitriou (1981). °c 2011 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 370 Christos Papadimitriou °c 2011 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 371 Easier or Harder?a ² Adding restrictions on the allowable problem instances will not make a problem harder. { We are now solving a subset of problem instances. { The independent set proof (p. 309) and the knapsack proof (p. 358). { sat to 2sat (easier by p. 292). { circuit value to monotone circuit value (equally hard by p. 266). aThanks to a lively class discussion on October 29, 2003. °c 2011 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 372 Easier or Harder? (concluded) ² Adding restrictions on the allowable solutions may make a problem easier, as hard, or harder. ² It is problem dependent. { min cut to bisection width (harder by p. 335). { linear programming to integer programming (harder by p. 369). { sat to naesat (equally hard by p. 303) and max cut to max bisection (equally hard by p. 333). { 3-coloring to 2-coloring (easier by p. 343). °c 2011 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 373 coNP and Function Problems °c 2011 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 374 coNP ² NP is the class of problems that have succinct certi¯cates (recall Proposition 35 on p. 276). ² By de¯nition, coNP is the class of problems whose complement is in NP. ² coNP is therefore the class of problems that have succinct disquali¯cations: { A \no" instance of a problem in coNP possesses a short proof of its being a \no" instance. { Only \no" instances have such proofs. °c 2011 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 375 coNP (continued) ² Suppose L is a coNP problem. ² There exists a polynomial-time nondeterministic algorithm M such that: { If x 2 L, then M(x) = \yes" for all computation paths. { If x 62 L, then M(x) = \no" for some computation path. ² Note that if we swap \yes" and \no" of M, the new algorithm M 0 decides L¹ 2 NP in the classic sense (p. 77). °c 2011 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 376 [∈/ [∉/ \HV \HV QR \HV \HV \HV \HV \HV QR \HV °c 2011 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 377 coNP (concluded) ² Clearly P ⊆ coNP. ² It is not known if P = NP \ coNP: { Contrast this with R = RE \ coRE (see Proposition 11 on p. 135). °c 2011 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 378 Some coNP Problems ² validity 2 coNP. { If Á is not valid, it can be disquali¯ed very succinctly: a truth assignment that does not satisfy it. ² sat complement 2 coNP. { sat complement is the complement of sat. { The disquali¯cation is a truth assignment that satis¯es it. ² hamiltonian path complement 2 coNP. { The disquali¯cation is a Hamiltonian path. °c 2011 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 379 Some coNP Problems (concluded) ² optimal tsp (d) 2 coNP. { optimal tsp (d) asks if the optimal tour has a total distance of B, where B is an input.a { The disquali¯cation is a tour with a length < B. aDe¯ned by Mr. Che-Wei Chang (R95922093) on September 27, 2006. °c 2011 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 380 A Nondeterministic Algorithm for sat complement Á is a boolean formula with n variables.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages43 Page
-
File Size-