Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Optimizing Billboard Placement on a Highway, Exams of Computer Science

An optimization problem related to the placement of billboards along a highway. The problem involves finding the optimal subset of billboard sites to maximize total revenue, subject to environmental constraints. Several algorithmic solutions to this problem, including an o(n^2) solution and an o(n) solution. It also discusses common mistakes in approaching this problem, such as considering pseudo-polynomial solutions. Insights into the differences between this problem and the classic knapsack problem, highlighting the unique constraints involved in billboard placement. Overall, this document offers a detailed analysis of a practical optimization problem with applications in the real world.

Typology: Exams

2020/2021

Uploaded on 08/12/2024

siddharth-yadav-3
siddharth-yadav-3 🇺🇸

1 document

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
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 sbe 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 w0(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 Tis a minimum spanning tree of a graph G, and if every edge
weight of Gis incremented by 1, is Tstill an MST of G? The answer is yes. The simplest
proof is that, if Ghas nvertices, then any spanning tree of Ghas n1 edges. Therefore
incrementing each edge weight by 1 increases the cost of every spanning tree by a constant,
n1. 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 Tis not an MST of the new
graph. Then there is some other spanning tree of G, call it b
T6=T, with lower cost on the
new graph. Given a cut (R, S ) of G,Thas exactly one edge eand b
Thas exactly one edge
becrossing the cut. Suppose be6=eand behas lower cost than e. Then by replacing ewith
pf3
pf4
pf5

Partial preview of the text

Download Optimizing Billboard Placement on a Highway and more Exams Computer Science in PDF only on Docsity!

University of California — Berkeley Handout MS 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̂ 6 = 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 ̂ e crossing the cut. Suppose ̂e 6 = e and ̂e has lower cost than e. Then by replacing e with

̂ e, 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 , ..., xn, 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 xi, you receive a revenue of ri > 0 You want to place billboards at a subset of the sites in {x 1 , ..., xn} 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 }

check this over all previous values. Since no choices are overlooked, the result is that the best subset for x 1 , ..., xi 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(n

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 xk ≤ xi − 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 , ..., xn 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 , ..., xn. Simply change the recurrence above to:

OP T [i] = max {OP T [i − 1], OP T [γ(i)] + ri}

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(M n) solution — did not receive full credit

An algorithm that runs in time O(M n) 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 , ..., xn 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 xi, and placing the billboards upto mile m from the left end.

OP T [i, m] =

OP T [i − 1 , m] if xi > m OP T [i, m − 1] if xi < m max {OP T [i − 1 , m], OP T [i − 1 , m − 5] + ri} if xi = m and xi ≥ 5 and xi ≤ M − 5

We initialized the matrix OP T to be zero everywhere. The interesting case is when xi = m. We then have two choices: OP T [i − 1 , m] corresponds to the case where we don’t pick site xi and the second quantity OP T [i − 1 , m − 5] + ri is the case where we pick site xi. 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 xi. 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.

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 , ..., Wm 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 com- panies of value (3,3,2,2), the merges yield

and V = 4 + 6 + 10 = 20 Let us consider a situation with initial values W 1 ,... , Wm, 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, fi, used to calculate the code are the original values, wi, 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, Wi, 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 ni.

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 ∑

j=

aij xj + ti ≤ bi

We also need some constraints on these “slack” variables so we add the constraints

ti ≥ 0 , ti ≤ 1 , for all i

We need ti’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 ti, the summation of the “slack” variables. Every constraint i for which ti = 0 is forced-equal, and for every constraint such that ti > 0 we have that

j aij^ xj^ +^ ≤^ bi^ −^ ti^ < bi, 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 forced- equal constraint from the others) or if you didn’t specify an upper bound (which could make the linear program unbounded).