Deign and Analyi of Algorithm April 29, 2015 Maachuett Intitute of Technology 6.046J/18.410J Prof. Erik Demaine, Srini Devada, and Nancy Lynch Problem Set 8 Solution Problem Set 8 Solution Thi problem et i due at 11:59pm on Friday, April 24, 2015. Exercie 8-1. Read CLRS, Chapter 29. Exercie 8-2. Exercie 29.2-2. Exercie 8-3. Exercie 29.2-4. Exercie 8-4. Read CLRS, Chapter 34. Exercie 8-5. Exercie 34.2-8. Exercie 8-6. Exercie 34.3-5. Problem 8-1. A Simple Simplex Example [25 point] Conider a linear program (LP) coniting of two variable x 1 and x 2 atifying the following three contraint: x 1 + x 2 10 x 2 4x 1 20 x 1 + 3x 2 24 x 1, x 2 0 The goal i to maximize the value of the objective function p = 4x 1 + x 2. (a) [5 point] Draw a diagram of the feaible region. See Figure 1.
2 Problem Set 8 Solution Figure 1: The feaible region of the LP problem. Image courtey of Finite mathematic & Applied calculu (http://www.zweigmedia.com). (b) [5 point] Write the given LP in tandard form, and tranform thi tandard form repreentation into lack form. Standard form: Maximize p = 4x 1 + x 2, ubject to: x 1 + x 2 10 4x 1 x 2 20 x 1 + 3x 2 24 x 1, x 2 0 Slack form: Introduce three new variable x 3, x 4, x 5. Maximize p = 4x 1 + x 2, ubject to: x 3 = 10 x 1 x 2 x 4 = 20 4x 1 + x 2 x 5 = 24 x 1 3x 2 x 1,..., x 5 0 (c) [10 point] Ue Simplex to olve the reulting lack form LP. Identify the pivot you chooe and give the reulting modified LP and the ucceive feaible olution. Indicate the ucceive olution on your diagram from Part (a).
Problem Set 8 Solution 3 Start with x 1 = x 2 = 0, x 3 = 10, x 4 = 20, x 5 = 24, that i, the olution (0, 0, 10, 20, 24), with objective function value p = 0. The firt nonbaic variable we elect for pivoting can be either x 1 or x 2, ince both have poitive coefficient in the objective function. To be pecific, let chooe x 2. A we increae x 2, the value of x 3 and x 5 decreae. The limiting contraint i the one for x 5 : we can only increae x 2 to 8, becaue any more would make x 5 negative. We exchange x 2 with x 5 : We olve the third contraint for x 2, obtaining x 2 = 8 1x 3 1 1x 3 5. Then we ubtitute, reulting in the following new LP: Maximize p = 8 + 11 x 1 1 x 5, ubject to: 3 3 2 1 x 3 = 2 x 1 + x 5 3 3 13 1 x 4 = 28 x 1 x 5 3 3 1 1 x 2 = 8 x 1 x 5 3 3 x 1,..., x 5 0 We get a new olution by etting the non-baic variable, x 1 and x 5 equal to 0 and calculating the other: (0, 8, 2, 28, 0). The value of the objective function i now p = 8. The only option now for pivoting i x 1, becaue the coefficient of x 5 in the objective function i negative. A we increae x 1, the value of x 2, x 3, and x 4 all decreae. The limiting contraint i the one for x 3 ; we can only increae x 1 to 3. We exchange x 1 3 1 with x 3, and olve the firt contraint for x 1, obtaining x 1 = 3 2 x 3 + 2 x 5. We get the following new LP: Maximize p = 19 11 x 3 + 3 x 5, ubject to: 2 2 3 1 x 1 = 3 x 3 + x 5 2 2 13 5 x 4 = 15 + x 3 x 5 2 2 1 1 x 2 = 7 + x 3 x 5 2 2 x 1,..., x 5 0 We get a new olution by etting x 3 and x 5 to 0, obtaining (3, 7, 0, 14, 0). The value of the objective function i now p = 19. Next, we pivot on x 5. Increaing x 5 caue x 4 and x 2 to decreae, with the limiting contraint being the one for x 4. We exchange x 5 with x 4, and obtain x 5 = 6 + 13 x 3 5 2 x 5 4. We obtain the following new LP:
4 Problem Set 8 Solution Maximize p = 28 8 5 x 3 5 3 x 4, 1 1 x 1 = 6 x 3 x 4 5 5 13 2 x 5 = 6 + x 3 x 4 5 5 4 1 x 2 = 4 x 3 + x 4 5 5 x 1,..., x 5 0 We get a new olution by etting x 3 and x 4 to 0, obtaining (6, 4, 0, 0, 6), with an objective function value of 28. At thi point no further pivot are poible (their coefficient in the objective function are both negative). Thu, an optimal olution i x 1 = 6, x 2 = 4. In the above proce, we tarted from the baic olution (0,0) meaning x 1 = 0, x 2 = 0, gradually improved our etimate through (0,8), (3,7), and finally arrived at the final olution (6,4). In Figure 1, thi correpond to travering four corner of the white region tarting from the origin in the clockwie direction. (d) [5 point] Give the dual LP of your tandard-form LP from Part (b) and give it optimal value. (Hint: Ue your olution to Part (c).) The tandard-form LP from Part (b) i: Maximize p = 4x 1 + x 2, ubject to: x 1 + x 2 10 4x 1 x 2 20 x 1 + 3x 2 24 x 1, x 2 0 A in CLRS p. 880, the dual LP ue new variable y 1, y 2, and y 3. The LP i: Minimize 10y 1 + 20y 2 + 24y 3, ubject to: y 1 + 4y 2 + y 3 4 y 1 y 2 + 3y 3 1 y 1, y 2, y 3 0 By LP duality (Theorem 29.10), the minimum value for thi LP i 28. Thi value i attained when y 1 = 5 8, y 2 = 5 3, and y 3 = 0. You can find thi olution manually, or by conidering the final lack form LP in your olution in Part (c) and uing formula (29.91) on p. 882.
Problem Set 8 Solution 5 Problem 8-2. NP-Completene [25 point] In thi problem, you will prove NP-completene of a few deciion problem. To prove NPhardne, you may reduce from any problem that ha been hown, in cla or in CLRS, to be NP-complete. (a) [5 point] Let TRIPLE-SAT denote the following deciion problem: given a Boolean formula φ, decide whether φ ha at leat three ditinct atifying aignment. Prove that TRIPLE-SAT i NP-complete. To how that TRIPLE-SAT i in NP, for any input formula φ, we need only gue three ditinct aignment and verify that they atify φ. To how that TRIPLE-SAT i NP-hard, we reduce SAT to it. Let φ denote the input Boolean formula to a SAT problem and uppoe that the et of variable in φ are X = {x 1,..., x n }. We contruct a TRIPLE-SAT problem with a Boolean formula φ / over a new variable et X / a follow: X / = {x 1,..., x n, y, z}. φ / = φ. Now we claim φ i atifiable iff φ / ha at leat 3 atifying aignment. If φ i atifiable, then we can augment any particular aignment by adding any of the 4 poible pair of value for {y, z} to give at leat four atifying aignment overall. On the other hand, if φ i not atifiable, then neither i φ /. (b) [10 point] In Problem Set 1, we conidered how one might locate donut hop at ome of the vertice of a treet network, modeled a an arbitrary undirected graph G = (V, E). Each vertex u ha a nonnegative integer value p(u), which decribe the potential profit obtainable from a hop located at u. Two hop cannot be located at adjacent vertice. The problem wa to deign an algorithm that output a ubet U V that maximize the total profit u U p(u). No doubt, you found an algorithm with time complexity that wa exponential in the graph parameter. Now we will ee why. Define DONUT to be the following deciion problem: given an undirected graph G = (V, E), given a mapping p from vertice u V to nonnegative integer profit p(u), and given a nonnegative integer k, decide whether there i a ubet U V uch that no two vertice in U are neighbor in G, and uch that u U p(u) k. Prove that DONUT i NP-hard. (Hint: Try a reduction from 3SAT.) Alo, explain why thi implie that, if there i a polynomial-time algorithm to olve the original problem, i.e., to output a ubet U that maximize the total profit, then P = NP.
6 Problem Set 8 Solution Let φ = C 1 C 2... C m be the input formula to a 3SAT problem, where each claue C c ha three literal choen from {x i, x i11 i n}. We contruct a DONUT problem (G, p, k) a follow. The vertice V of G are {v c,j 11 c m, 1 j 3}, where v c,j correpond to literal j in claue C c. We label each vertex v c,j with x i or x i, whichever appear in poition j of claue C c. The edge E of G are of two type: For each claue C c, an edge between each pair of vertice correponding to literal in claue C c, that i, between v c,j1 and v c,j2 for j 1 = j 2. For each i, an edge between each pair of vertice for which one i labeled by x i and the other by x i. The function p map all vertice to 1. The threhold k i equal to m. We claim that φ i atifiable iff the total profit in the DONUT problem (G, p, k) can be at leat k. Firt, uppoe that φ i atifiable. Then there i ome truth aignment A mapping the variable to {true, fale}. A mut make at leat one literal per claue true; for each claue, elect the vertex correponding to one uch literal to be in the et U. Since there are m claue, thi yield exactly m = k vertice, o the total profit i k. Moreover, we claim that U cannot contain two neighboring vertice in G. Suppoe for contradiction that u, v U and (u, v) E. Then the edge (u, v) mut be of one of the two type above. But u and v cannot correpond to literal in the ame claue becaue we elected only one vertex for each claue. And u and v cannot be labeled by x i and x i for the ame i, becaue A cannot make both a variable and it negation true. Since neither poibility can hold, U cannot contain two neighboring vertice. U achieve a total profit of k for the DONUT problem (G, p, k). Converely, uppoe that there exit U V, U k = m containing no two neighbor in G. Since U doe not contain neighbor, it cannot contain two vertice from the ame claue. Therefore, we mut have U = m, with exactly one vertex from each claue. Now define a truth aignment A for the variable: A(x i ) = true if ome vertex with label x i i in U, and A(x i ) = fale if ome vertex with label x i i in U. For other variable the truth value can be arbitrary. Alo ince U doe not contain neighbor, U cannot contain two vertice with contradictory label, o aignment A i well-defined. A atifie all claue by making one literal correponding to a vertex in U true in each claue. Therefore, A atifie φ. For the lat quetion, uppoe that there i a polynomial-time algorithm to olve the original problem, i.e., to output a ubet U that maximize the total profit. Then thi algorithm can be eaily adapted to a polynomial-time algorithm for DONUT: for any (G, p, k), imply run the aumed algorithm and obtain an optimal ubet U. Then output true if k U, and fale otherwie. Since we have already hown that DONUT i NP-hard, thi implie that P= NP.
Problem Set 8 Solution 7 (c) [10 point] Suppoe we have one machine and a et of n tak a 1, a 2,..., a n. Each tak a j require t j unit of time on the machine, yield a profit of p j, and ha a deadline d j. Here, the t j, p j, and d j value are nonnegative integer. The machine can proce only one tak at a time. Not all tak have to be run, but if a tak tart running, it mut run without interruption and mut complete by it deadline. A chedule for a ubet of the tak decribe when each of the tak in the ubet tart running. A chedule mut oberve the contraint given above. The profit for the chedule i the um of all the p j value for the tak a j in the chedule. The problem i to produce a chedule for a ubet of the tak that return the greatet poible amount of profit. State thi problem a a deciion problem and how that it i NP-complete. In howing thi, you may reduce from any problem that ha been hown, in cla or in CLRS, to be NP-complete. Define SCHED to be the following deciion problem: given (T, P, D, k) where T, P, and D are equence {t j }, {p j } and {d j }, each of length n, decide whether there exit a ubet I {1,..., n} and an ordering i 1, i 2,..., i m of I, uch that: 1. For every j, j l=1 T (i l) D(i j ). That i, the um of the running time of the firt j tak being run i no greater than the deadline for the j th tak. That mean that, when run in the given order, all tak meet their deadline. 2. m l=1 P (i l ) k. That i, the total profit i at leat k. To ee that SCHED i in NP, given an intance (T, P, D, k), we can gue a ubet of the tak and a equence of tart time, and verify that it meet all the contraint for a chedule and that it finihe within the given time k. To how that SCHED i NP-hard, we can reduce from SUBSET-SUM, defined on p. 1097 of CLRS. Given an intance (S, t) of SUBSET-SUM, where S = n, order the element of S arbitrarily, a 1,..., n. We contruct an intance (T, P, D, k) of SCHED a follow: Let T = P = { 1,..., n } in that order, let D be a length-n equence coniting of t in every poition, and let k = t. We claim that the anwer to the SUBSET-SUM problem (S, t) i ye, iff the anwer to the SCHED problem (T, P, D, k) i ye. Firt, the anwer to the SUBSET-SUM problem (S, t) i ye. Then there i a ubet S / of the element in S whoe um i exactly t. Let I be the et of indice of the S / element within the equence 1,..., n, and let i 1, i 2,..., i m order I in increaing m order. Then the um of the running time of all tak i exactly t, that i, l=1 T (i l) = t. Thi implie that all tak meet their deadline. Moreover, the total profit i exactly m l=1 P (i l) = t = k. Therefore, the anwer to the SCHED problem (T, P, D, k) i ye. Converely, uppoe the anwer to the SCHED problem (T, P, D, k) i ye. Then there i a ubet I of 1,..., n and an ordering i 1, i 2,..., i m of I, uch that: 1. For every j, j l=1 T (i l) D(i j ).
8 Problem Set 8 Solution m 2. l=1 P (i l) k. Since all of the deadline are equal to k = t, thi i the ame a aying: m 1. l=1 T (i l) t. 2. m l=1 P (i l) t. m m Since each T (i j ) = P (i j ), thi ay that l=1 T (i l ) = l=1 P (i l ) = t. Now let S / be the ubet of S correponding to the indice in I, that i, S / = { i 1i I}. Then the um of the element of S / i exactly t. Therefore, the anwer to the SUBSET-SUM problem (S, t) i ye.
MIT OpenCoureWare http://ocw.mit.edu 6.046J / 18.410J Deign and Analyi of Algorithm Spring 2015 For information about citing thee material or our Term of Ue, viit: http://ocw.mit.edu/term.