CS2223
HW#4

Due: Monday , November 23

1. (6 points) Prove or give a counterexample to the following

Conjecture: The minimum spanning tree algorithm works correctly even if the lengths can be negative. That is, the spanning tree constructed by Kruskal’s algorithm is a least cost spanning tree, even if  can associate negative lengths with edges.

2. (6 points) Prove or give a counterexample to the following

Conjecture: The single source shortest path algorithm works correctly even if the lengths can be negative. That is, the shortest path constructed by Dijkstra’s algorithm is a shortest path, even if  can associate negative lengths with edges.

3. (10 points) Do Problem 6.21 on page 216 of our text.

CS2223
HW#4 Solutions

1. The conjecture is true. If all edge lengths are positive, there’s nothing to prove. Let e0 be a least cost edge of A. Add |L(e0)| to each length of A, that is, define  by . We know that the algorithm works correctly for lengths L’, since all lengths are non-negative. But since L’ imposes the exact same order on A as L, the algorithm will follow exactly the same sequence of steps for L as for L’, and would construct exactly the same spanning tree, which must have a minimal length.

2. The conjecture is false. Consider the graph

The shortest path from s to c is s,a,c of length 2, although Dijkstra’s algorithm would construct the path s,b,c of length 10.

3. (a) The greedy algorithm is optimal. Assume without loss of generality that si≤si+1, for 1≤i<n. There is a j≤n such that the greedy algorithm packs programs P1,…,Pj. If this packing were not optimal, there must be a larger packing P such that there exist k, l with 1≤k≤j and PkÏP and j<l≤n and PlÎP. But sk≤sl,, so P can be modified by replacing Pl by Pk  and the modified  takes no more space. Continuing in this matter, all of P1,…,Pj  can be added to P, but since nothing else fits along wih P1,…,Pj, we contradict the assumption that a better packing fits. Hence the greedy algorithm must be optimal.
(b) The greedy algorithm is not optimal. If the disk has capacity D=9 and the n=3 programs have sizes 4, 5 and 6, the greedy algorithm will only fit the program of size s3=6 for a utilization of 2/3, whereas an optimal packing (of the smaller two programs) yields a utilization of 1.