# CS5800 09F: Homework 09

Created: Mon 30 Nov 2009

Assigned: Wed 02 Dec 2009
Due: Wed 09 Dec 2009

## Instructions

1. Please review the course syllabus and make sure that you understand the course policies for grading, late homework, and academic honesty.

2. On the first page of your solution write-up, you must make explicit which problems are to be graded for "regular credit", which problems are to be graded for "extra credit", and which problems you did not attempt. Please use a table something like the following

Problem01020304 0506070809...
CreditRCRCRCECRC RCNARCRC...

where "RC" is "regular credit", "EC" is "extra credit", and "NA" is "not applicable" (not attempted). Failure to do so will result in an arbitrary set of problems being graded for regular credit, no problems being graded for extra credit, and a five percent penalty assessment.

3. You must also write down with whom you worked on the assignment. If this changes from problem to problem, then you should write down this information separately with each problem.

## Problems

Required: Do five of the six problems below.
Unless otherwise indicated, exercises and problems are from Introduction to Algorithms by Cormen, Leiserson, Rivest, and Stein. The edition (2nd or 3rd) will be indicated if the numbering differs. * - Indicates problem from Algorithms by Dasgupta, Papadimitriou, and Vazirani.

1. 24.5-2

2. Solve problem 5 on homework 5 by using a graph algorithm for determining shortest paths. Argue that your solution is correct, and analyze its running time. (Hint: You will have one vertex in your graph corresponding to each city.)
3. * Often there are multiple shortest paths between two nodes of a graph. Give a linear-time algorithm for the following task.

Input: Undirected graph G = (V,E) with unit edge lengths; nodes u, v ∈ V.
Output: The number of distinct shortest paths from u to v.

4. * Give an algorithm that takes as input a directed graph with positive edge lengths, and returns the length of the shortest cycle in the graph. ( If the graph is acyclic, it should say so.) Your algorithm should take time at most O(|V3|).
5. * Give an O(|V2|) algorithm for the following task.

Input: Undirected graph G = (V,E) with edge lengths le > 0; an edge e ∈ E.
Output: The length of the shortest cycle containing e.

6. * Generalized shortest-paths problem. In Internet routing, there are delays on lines but also, more significantly, delays at routers. This motivates a generalized shortest-paths problem.

Suppose that in addition to having edge lengths {le : e ∈ E }, a graph also has vertex costs {cv : v ∈ V}. Now define the cost of a path to be the sum of its edge lengths, plus the costs of all vertices on the path (including the endpoints). Give an efficient algorithm for the following problem.

Input: A directed graph G = (V, E); positive edge lengths le and positive vertex costs cv; a starting vertex s ∈ V.
Output: An array cost[⋅] such that for every vertex u, cost[u] is the least cost of any path from s to u (i.e., the cost of the cheapest path), under the definition above.

Notice that cost[s] = cv.

### Switch to:

Harriet Fell
College of Computer Science, Northeastern University
360 Huntington Avenue #340 WVH,
Boston, MA 02115
Email: fell@ccs.neu.edu
Phone: (617) 373-2198 / Fax: (617) 373-5121
The URL for this document is: http://www.ccs.neu.edu/home/fell/CS5800/F09/Homeworks/hw.09.html 