University of California Berkeley CS170: Efficient Algorithms and Intractable Problems November 19, 2001 Professor Luca Trevisan. Midterm 2 Solutions

Similar documents
Midterm 2. DO NOT turn this page until you are instructed to do so

Do not turn this page until you have received the signal to start. Please fill out the identification section above. Good Luck!

CS173 Lecture B, November 3, 2015

Efficient Algorithms and Intractable Problems Spring 2016 Alessandro Chiesa and Umesh Vazirani Midterm 2

Algorithms Exam TIN093 /DIT602

1 Basic Definitions. 2 Proof By Contradiction. 3 Exchange Argument

Quiz 1 Solutions. Problem 2. Asymptotics & Recurrences [20 points] (3 parts)

Discrete Wiskunde II. Lecture 5: Shortest Paths & Spanning Trees

Proof Techniques (Review of Math 271)

Lecture 4: An FPTAS for Knapsack, and K-Center

CS1800: Mathematical Induction. Professor Kevin Gold

Notes for Lecture 21

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Dynamic Programming II Date: 10/12/17

Computational Complexity. IE 496 Lecture 6. Dr. Ted Ralphs

Lecture 17: Trees and Merge Sort 10:00 AM, Oct 15, 2018

x 1 + x 2 2 x 1 x 2 1 x 2 2 min 3x 1 + 2x 2

Computational Integer Programming. Lecture 2: Modeling and Formulation. Dr. Ted Ralphs

Chapter 1 Review of Equations and Inequalities

CS325: Analysis of Algorithms, Fall Final Exam

CMPSCI611: The Matroid Theorem Lecture 5

3.10 Lagrangian relaxation

This means that we can assume each list ) is

CMPSCI 611 Advanced Algorithms Midterm Exam Fall 2015

Algebra Exam. Solutions and Grading Guide

Introduction to Basic Proof Techniques Mathew A. Johnson

NATIONAL UNIVERSITY OF SINGAPORE CS3230 DESIGN AND ANALYSIS OF ALGORITHMS SEMESTER II: Time Allowed 2 Hours

Aditya Bhaskara CS 5968/6968, Lecture 1: Introduction and Review 12 January 2016

Optimisation and Operations Research

Lecture 2: Divide and conquer and Dynamic programming

FINAL EXAM PRACTICE PROBLEMS CMSC 451 (Spring 2016)

Practice Second Midterm Exam I

University of New Mexico Department of Computer Science. Final Examination. CS 362 Data Structures and Algorithms Spring, 2007

) (d o f. For the previous layer in a neural network (just the rightmost layer if a single neuron), the required update equation is: 2.

CS 170 Algorithms Spring 2009 David Wagner Final

CS 360, Winter Morphology of Proof: An introduction to rigorous proof techniques

CS 350 Algorithms and Complexity

P, NP, NP-Complete, and NPhard

Final Exam Comments. UVa - cs302: Theory of Computation Spring < Total

Section Notes 8. Integer Programming II. Applied Math 121. Week of April 5, expand your knowledge of big M s and logical constraints.

Math 381 Midterm Practice Problem Solutions

CS 5114: Theory of Algorithms. Tractable Problems. Tractable Problems (cont) Decision Problems. Clifford A. Shaffer. Spring 2014

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Matroids and Greedy Algorithms Date: 10/31/16

U.C. Berkeley Better-than-Worst-Case Analysis Handout 3 Luca Trevisan May 24, 2018

CS 350 Algorithms and Complexity

Computer Science 385 Analysis of Algorithms Siena College Spring Topic Notes: Limitations of Algorithms

1 T 1 = where 1 is the all-ones vector. For the upper bound, let v 1 be the eigenvector corresponding. u:(u,v) E v 1(u)

Essential facts about NP-completeness:

CS103 Handout 08 Spring 2012 April 20, 2012 Problem Set 3

In case (1) 1 = 0. Then using and from the previous lecture,

II. Analysis of Linear Programming Solutions

Data Structures in Java

CS 561, Lecture: Greedy Algorithms. Jared Saia University of New Mexico

Quick Sort Notes , Spring 2010

Econ Slides from Lecture 1

Tutorial on Mathematical Induction

1 Some loose ends from last time

Today s Outline. CS 561, Lecture 15. Greedy Algorithms. Activity Selection. Greedy Algorithm Intro Activity Selection Knapsack

COL351: Analysis and Design of Algorithms (CSE, IITD, Semester-I ) Name: Entry number:

Linear Programming Duality

1 Reductions and Expressiveness

Discrete Optimization 2010 Lecture 2 Matroids & Shortest Paths

Midterm Exam 2 Solutions

Lecture 12 : Graph Laplacians and Cheeger s Inequality

Lecture 6: Greedy Algorithms I

UNIVERSITY of OSLO. Faculty of Mathematics and Natural Sciences. INF 4130/9135: Algorithms: Design and efficiency Date of exam: 12th December 2014

Linear Programming and its Extensions Prof. Prabha Shrama Department of Mathematics and Statistics Indian Institute of Technology, Kanpur

Mathematics for Decision Making: An Introduction. Lecture 13

The Inductive Proof Template

Lecture 13: Dynamic Programming Part 2 10:00 AM, Feb 23, 2018

CS 6820 Fall 2014 Lectures, October 3-20, 2014

directed weighted graphs as flow networks the Ford-Fulkerson algorithm termination and running time

CS60007 Algorithm Design and Analysis 2018 Assignment 1

Price of Stability in Survivable Network Design

At the start of the term, we saw the following formula for computing the sum of the first n integers:

Optimization Methods in Management Science

1 Closest Pair of Points on the Plane

Midterm 1. Your Exam Room: Name of Person Sitting on Your Left: Name of Person Sitting on Your Right: Name of Person Sitting in Front of You:

Information Theory and Coding Prof. S. N. Merchant Department of Electrical Engineering Indian Institute of Technology, Bombay

Review Solutions, Exam 2, Operations Research

Algorithm Design and Analysis

Greedy Algorithms My T. UF

Convex envelopes, cardinality constrained optimization and LASSO. An application in supervised learning: support vector machines (SVMs)

8. TRANSFORMING TOOL #1 (the Addition Property of Equality)

Complexity Theory Part I

CS261: A Second Course in Algorithms Lecture #12: Applications of Multiplicative Weights to Games and Linear Programs

Computer Science & Engineering 423/823 Design and Analysis of Algorithms

Lecture 12 : Recurrences DRAFT

Special Theory of Relativity Prof. Shiva Prasad Department of Physics Indian Institute of Technology, Bombay. Lecture - 15 Momentum Energy Four Vector

0. Introduction 1 0. INTRODUCTION

1. (7pts) Find the points of intersection, if any, of the following planes. 3x + 9y + 6z = 3 2x 6y 4z = 2 x + 3y + 2z = 1

10.3 Matroids and approximation

Discrete Structures Proofwriting Checklist

Integer Linear Programs

Algorithms: Lecture 12. Chalmers University of Technology

Lecture 5. x 1,x 2,x 3 0 (1)

BCCS: Computational methods for complex systems Wednesday, 16 June Lecture 3

Lecture 4. 1 Estimating the number of connected components and minimum spanning tree

CS583 Lecture 11. Many slides here are based on D. Luebke slides. Review: Dynamic Programming

U.C. Berkeley CS294: Spectral Methods and Expanders Handout 11 Luca Trevisan February 29, 2016

Lecture 15 - NP Completeness 1

Transcription:

University of California Berkeley Handout MS2 CS170: Efficient Algorithms and Intractable Problems November 19, 2001 Professor Luca Trevisan Midterm 2 Solutions Problem 1. Provide the following information: Your name; Your SID number; Your section number (and/or your TA name); Name of the person on your left (if any); Name of the person on your right (if any). Solutions The correct spelling of the TA s names are Scott Aaronson, Shyam Lakshmin, Iordanis (Jordan) Kerenidis, Joseph (Joe) Polastre, Beini Zhou. We gave full credit as long as you could spell your own name. (And we were not too strict in checking that, either.) Common mistakes involved the spelling of Beini s and Jordan s last names. Problem 2. Consider a undirected graph G = (V, E) with nonnegative weights w(i, j) 0 on its edges (i, j) E. Let s be a node in G. Assume you have computed the shortest paths from s, and minimum spanning tree of the graph. Suppose we change the weights on every edge by adding 1 to each of them. The new weights are w (i, j) = w(i, j) + 1 for every (i, j) E. (a) Would the minimum spanning tree change due to the change in weights? Give an example where it changes or prove that it cannot change. (b) Would the shortest paths change due to the change in weights? Give an example where it changes or prove that it cannot change. Solutions The first question was, if T is a minimum spanning tree of a graph G, and if every edge weight of G is incremented by 1, is T still an MST of G? The answer is yes. The simplest proof is that, if G has n vertices, then any spanning tree of G has n 1 edges. Therefore incrementing each edge weight by 1 increases the cost of every spanning tree by a constant, n 1. So any spanning tree with minimal cost in the original graph also has minimal cost in the new graph. There are alternative proofs that amount to more complicated ways of saying the same thing. For example: assume by way of contradiction that T is not an MST of the new graph. Then there is some other spanning tree of G, call it T T, with lower cost on the new graph. Given a cut (R, S) of G, T has exactly one edge e and T has exactly one edge ê crossing the cut. Suppose ê e and ê has lower cost than e. Then by replacing e with

Handout MS2: Midterm 2 Solutions 2 ê, we obtain a new spanning tree for the original graph with lower cost than T, since the ordering of edge weights is preserved when we add 1 to each edge weight. This contradicts the assumption that T was an MST of the original graph. Many people gave an argument based on Kruskal s algorithm: that algorithm finds an MST by repeatedly choosing the minimum-weight edge that does not create a cycle. Incrementing each edge weight by 1 leaves the ordering of edge weights unchanged; therefore Kruskal s algorithm returns the same MST that it returned previously. The problem with this argument is that it applies only to the particular MST returned by (some implementation of) Kruskal s algorithm, not to the collection of all MST s. Thus, we only gave partial credit for this argument. Some people misinterpreted the question after pointing out, correctly, that G need not have a unique MST, they said that the MST could change if a randomized algorithm chose a different MST for the new graph than for the original graph. But the question was whether the collection of MST s can change. Other people said that the MST changes trivially since the weights of its edges change. But the MST is defined by the collection of edges in it, not the weights of those edges. The second question was, if P is a shortest path from s to t in G, is P still necessarily the shortest path after every edge weight of G is incremented by 1? The answer is no. Suppose, for example, that G consists of an edge from s to t of weight 1, and edges from s to a, a to b, and b to t each of weight 0. Then the shortest path is s a b t, with cost 0. But when we increment each edge weight by 1, the shortest path becomes s t, with cost 2. Again, some people misinterpreted the question, and said the answer is no because the cost of the shortest path changes trivially, even if the set of edges in the path does not change. Problem 3. There has been a lot of hype recently about Star Wars Episode II with the release of the newest theatrical trailer. For this problem, suppose you are managing the construction of billboards on the Anakin Skywalker Memorial Highway, a heavily-travelled stretch of road that runs west-east for M miles. The possible sites for billboards are given by numbers x 1, x 2,..., x n, each in the interval [0, M] (specified by their position along the highway measured in miles from its western end). If you place a billboard at location x i, you receive a revenue of r i > 0 You want to place billboards at a subset of the sites in {x 1,..., x n } so as to maximize your total revenue, subject to the following restrictions: 1. Environmental Constraint. You cannot build two billboards within less than 5 miles of one another on the highway. 2. Boundary Constraint. You cannot build a billboard within less than 5 miles of the western or eastern ends of the highway. A subset of sites satisfying these two restrictions will be called valid. Example Suppose M = 20, n = 4 {x 1, x 2, x 3, x 4 } = {6, 8, 12, 14}

Handout MS2: Midterm 2 Solutions 3 and {r 1, r 2, r 3, r 4 } = {5, 6, 5, 1} Then the optimal solution would be to place billboards at x 1 and x 3 for a total revenue of 10. Give an algorithm of running time polynomial in n, that takes an instance of this problem as input, and returns the maximum total revenue that can be obtained from any valid subset of sites. Solutions Dynamic Programming was the correct way to approach this problem. A key observation is that we want to iterate over the indices of the elements in x 1, x 2,..., x n, not the values of x 1, x 2,..., x n in order to develop an algorithm polynomial in n. We were searching for an algorithm that ran in time polynomial in n. The intuition behind the algorithm involved recognizing that at each step, you have two choices: build a billboard at x i or not build a billboard at x i. If we build a billboard at x i and receive revenue r i, then we can t build at billboard in the interval [x i 4, x i 1]. Assume that the values of x i are real numbers (fractions, etc...) and x 1, x 2,..., x n are in an arbitrary order. Solution 1: An O(n 2 ) solution. Let the subproblems be defined: OP T [i] = the maximum revenue one can receive given the constraints and selecting a subset of the sites between x 1 and x i. Define a new function δ(i, j) which returns 1 if it is acceptable to build at x j knowing that a billboard has been built at x i. δ is defined: { 1 if x j 5, x j M 5, x j x i 5 δ(i, j) = 0 otherwise Notice that if we don t build at x i, we simply want the best thing that happened so far, or OP T [i 1]. If we do build at x i, we want the best thing that happened up to x i 5 or OP T [j] + r i where x j x i 5. From these definitions, the recurrence is: OP T [i] = max 0 j i {OP T [i 1], OP T [j] + δ(i, j)r i} The resulting value of OP T [n] is the maximum revenue achievable by building at a subset of sites between x 1 and x n. The correctness of this algorithm can be verified by the fact that all of the constraints are accounted for by the δ(i, j) matrix (which takes O(n 2 ) time to compute). Instead of using δ(i, j) in your solution, you could have simply put the constraints underneath the max in the recurrence and still had a completely acceptable correct solution. Why does this algorithm return a maximum? At each step, it is calculating the best thing to do looking at all the options. Assume that the solution does something non-optimal at step i. Then it would have chosen to build or not build at x i, one of which being optimal, the other being non-optimal. But we check which choice results in a better revenue, and we

Handout MS2: Midterm 2 Solutions 4 check this over all previous values. Since no choices are overlooked, the result is that the best subset for x 1,..., x i is always chosen at OP T [i]. The running time of this algorithm is O(n 2 ). Each iteration requires checks i values, and this is iterated over all n OP T [i] values. The result is n i=1 i = O(n2 ). Solution 2: An O(n) solution The O(n) solution is a heuristic modification to the above algorithm. Instead of storing δ(i, j), we want to store the index of the greatest position x k x i 5. Define a new function γ(i) that returns such a k if it exists, and 0 otherwise. We can precompute γ(i) for i i n in O(n) time before we start solving the problem with the recurrence. This solution assumes that x 1, x 2,..., x n is sorted. If it is, the algorithm described takes O(n) time, otherwise it will take O(n log n) time dominated by sorting the values of x 1, x 2,..., x n. Simply change the recurrence above to: OP T [i] = max {OP T [i 1], OP T [γ(i)] + r i } The correctness follows from the correctness of solution 1, and the running time is O(n) for precomputing γ(i) plus another O(n) for calculating OP T [i] for 1 i n. Solution 3: An O(Mn) solution did not receive full credit An algorithm that runs in time O(Mn) is considered to be pseudo-polynomial and is not polynomial in n. Such a solution is detailed below and did not receive full credit. Assume that x 1, x 2,..., x n has been sorted in increasing order. Let the subproblems be defined: OP T [i, m] = the maximum revenue one can receive given the constraints, selecting a subset of the sites between x 1 and x i, and placing the billboards upto mile m from the left end. OP T [i 1, m] if x i > m OP T [i, m] = OP T [i, m 1] if x i < m max {OP T [i 1, m], OP T [i 1, m 5] + r i } if x i = m and x i 5 and x i M 5 We initialized the matrix OP T to be zero everywhere. The interesting case is when x i = m. We then have two choices: OP T [i 1, m] corresponds to the case where we don t pick site x i and the second quantity OP T [i 1, m 5] + r i is the case where we pick site x i. Since we have to obey the boundary constraint, the second index in the second quantity becomes m 5, i.e., we cannot place any billboard within five miles of x i. The final answer is stored at OP T [n, M]. Note A lot of students have come up with solutions along the lines of the above ones. For each solution, there s more than one way to write down the recurrence, thus your recurrence does not have to look exactly like the ones above to receive credit.

Handout MS2: Midterm 2 Solutions 5 Common Mistakes The common mistake is the O(M n) or O(M) solution. Neither of these is a polynomial function in n. If you recall the knapsack problem from lecture 14, the dynamic-programming solution to this problem runs in O(nB). Therefore, this is not a polynomial-time solution to the knapsack problem. One should also notice that when placing billboards in a universe far far away, the solution to this problem is not identical to the knapsack problem. Placing billboards has no upper bound on the number of billboards that may be built rather the constraints are on which elements we can pick. This is inherently opposite of knapsack which has constraints on the size of the knapsack but not on the items that are chosen. We ll see later in this class that solving the knapsack problem in polynomial time is conjectured to be a hard problem. However, for this Star Wars problem on the midterm, there s a polynomial time solution as detailed above. Problem 4. In a country with no antitrust laws, m software companies with values W 1,..., W m are merged as follows. The two least valuable companies are merged, thus forming a new list of m 1 companies. The value of the merged company is the sum of the values of the two companies that merged (we call this value the volume of the merge). this continues until only one company remains. Let V be the total reported volume of the merges. For example if initially we had 4 companies of value (3,3,2,2), the merges yield and V = 4 + 6 + 10 = 20 (3, 3, 2, 2) (4, 3, 3) (6, 4) (10) Let us consider a situation with initial values W 1,..., W m, and let V be the total volume of the merges in the sequence of merges described above. Prove that merging the smallest pair at each step results in the minimum possible total volume after all companies are merged (i.e., V V where V is the result of our algorithm and V is the result of any other algorithm for merging companies). Solution The process of merging the companies is similar to the construction of a Huffman encoding. In fact we are creating a tree, as prescribed by Huffman encoding, where: the original companies are the encoded symbols, and the frequencies, f i, used to calculate the code are the original values, w i, of these companies. We wish to minimize the total sum of all of the mergers, V. In relation to our tree, V is the sum of the weights of all of the non-leaf nodes (created companies). However, we can sum these values in a different way. The weight of one of these created companies is the sum of the weights of the original companies it encompasses. So each original weight, W i, is present in the number of mergers that company i was involved in. Let us call the number of mergers company i was involved in n i.

Handout MS2: Midterm 2 Solutions 6 So V = Σ i W i n i. But notice that the number of mergers, n i, that company i was involved in is exactly the depth of a company i, in the tree (i.e. the number of bits in the encoding of that symbol). Huffman minimizes the sum Σ i f i d i. (No need to reprove this!) However, this is precisely V. So our algorithm will minimize V. Common Mistakes. First off, some errors came from misunderstanding the problem to begin with. Yes, the volume of the final company is always constant, but that s not what we re asking about. We re concerned with the sum of all intermediate companies. Other misinterpretations led people astray as well. The most common method of attack people tried (after they understood the problem) was a merge by merge analysis (or in some cases, induction on the number of merges). This actually tries to prove something stronger, that the total sum of the reported volume of the mergers is minimized after every merger. We only wish to show that it is minimized at the end. Not surprisingly, this stronger statement ends up requiring some effort. At first it seems rather straight-forward. Using our method, the volume of the merger we are producing at a particular step is minimal since the two companies we chose were minimal. This implies that another algorithm which chooses any other pair would increase the value reported here. Since V is the sum of the reported volumes and this other algorithm reports a larger volume at this step, the other algorithm will produce a larger V. This is not a logical implication! The problem is that once this other algorithm performs a merge that differs from our algorithm it will proceed with a different set of values. Our argument that our algorithm produces the smallest reported volume no longer holds after this step. Example: Consider the example (3, 3, 2, 2) as in the exam. Our algorithm first reports 4, then 6, and then 10. Consider an algorithm that first merges the 3 s (reporting 6), then merges the 2 s (reporting 4), and finally reports 10. This algorithm reports a higher value after the first merger, but that allowed it beat our algorithm on the second merger. This doesn t mean that the stronger claim doesn t hold, but it s just more of a pain. The key to the problem was to use the already established optimality of Huffman codes. Problem 5. Given a satisfiable system of linear inequalities a 11 x 1 + + a 1n x n b 1 a m1 x 1 + + a mn x n b m we say that an inequality is forced-equal in the system if for every x that satisfies the system, the inequality is satisfied as an equality. (Equivalently, an inequality i a ijx i b j is not forced-equal in the system if there is an x that satisfies the whole system and such that in that inequality the left-hand side is strictly smaller than the right-hand side, that is i a ijx i < b j.) For example in

Handout MS2: Midterm 2 Solutions 7 x 1 + x 2 2 x 1 x 2 2 x 1 1 x 2 0 the first two inequalities are forced-equal, while the third and fourth are not forced-equal. Observe that, in any satisfiable system, there is always a solution where all inequalities that are not forced-equal have a left-hand side strictly smaller than the right-hand side. In the above example, we can set x 1 = 1 and x 2 = 3, so that we have x 1 < 1 and x 2 < 0, as well as x 1 + x 2 = 2 and x 1 x 2 = 2. Given a satisfiable system of linear inequalities, show how to use linear programming to determine which inequalities are forced-equal, and to find a solution where all inequalities that are not forced-equal have a left-hand side strictly smaller than the right-hand side. Solution We want to find out which of the constraints are forced equal and then find a solution where the rest of the constraints have a LHS strictly less than the RHS. The easiest way to do this is to introduce a new slack variable for each constraint so that the i-th constraint will become: n a ij x j + t i b i j=1 We also need some constraints on these slack variables so we add the constraints t i 0, t i 1, for all i We need t i s to be positive but we also need an upper bound on them so that the problem will remain bounded! Then, we use linear programming trying to maximize i t i, the summation of the slack variables. Every constraint i for which t i = 0 is forced-equal, and for every constraint such that t i > 0 we have that j a ijx j + b i t i < b i, so the solution found by the linear program is the solution that the problem was asking for. Many people tried to make a case considering the two dimensional case, arguing that forced equal inequalities will give you a feasible region which will actually be a line. However, plotting the constraints and checking what the feasible region looks like cannot solve the problem, since there is no algorithm that can actually look at a picture and decide what it looks like. There were also a few mistakes by people misinterpreting the meaning of forced equal, so please read the problems carefully before trying to answer them. Points were taken off if you used the same slack variable for every constraint (if there is even one forced-equal constraint, the single variable will be zero, and you will be unable to distinguish the forcedequal constraint from the others) or if you didn t specify an upper bound (which could make the linear program unbounded).