Vous êtes sur la page 1sur 1

HW 7

Questions
The next 4 questions refer to the following problem:
P
You are given a set of items i1 , i2 , . . . in . Item ii has a weight of wi . Let W = i∈[n] wi . The
items need to be shipped from a factor to a retail store. You have trucks that can carry a total
weight of W/2. You want to decide if you need two or three trucks to make the shipment.
Notice that if two trucks can be used, then both will hold a weight of exactly W/2. We will
use dynamic programming to solve this problem.

1. Let T (W 0 , k) be 1 if there is a subset of the items 1, 2, . . . , k such that their total weight
is W 0 and 0 otherwise. Say that all entires T (W 0 , k) have been computed (over all
possible W 0 ’ and k). How can we tell if two trucks can be used?
2. We want to compute T (W 0 , k). Say that there is a subset of items 1, 2, . . . , k − 1 whose
total weight is W 0 . In this case, what is the entry for T (W 0 , k)?
3. Say that no subset of items 1, 2, . . . , k − 1 has total weight W 0 . Can we conclude that
T (W 0 , k) should be set to 0?
4. How can we recursively check if T (W 0 , k) is 0 or 1? That is, compute T (W 0 , k) assuming
that you have stored T (W 00 , k 0 ) for any W 00 ≤ W 0 and k 0 < k.

The next 3 questions refer to the following problem:

In class we have looked at the shortest path problem. Now we consider the longest path
problem. Say we have a directed graph G = (V, E). Assume all edge weights are 1. We will
say that the vertices v1 , v2 , . . . vn are ordered if all edges go from nodes vi to vj only if i < j.
We assume that the vertices of G can be ordered. Note that not all graphs admit such an
ordering. Our goal is to find the longest path in this graph.
This problem has numerous applications including the following. Say that each node in
the network represents a machine in a manufacturing line. Each machine begin production
independently, however some machines require parts produced by earlier machines. Each
edge (i, j) represents that a part produced by machine i is needed by j before machine j can
begin production. The longest path in the network represents the time it takes to make a
single product.

5. Let OP T (i) denote the length of the longest path that ends with vertex vi . If we
compute OP T (i) for all vertices vi how can we tell the length of the longest path in the
graph?
6. Say that vi has no incoming edges, then what is OP T (i)?
7. Say that OP T (j) has been computed for all j < i. How can we compute OP T (i)?