This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: CSIS0250B - Sample solution for Assignment 2 (2009-03-12) 1 Question 1 Question 1 Question 1 Question 1 For a general graph, the cost value of any two nodes in the same strongly connected component will be the same since both are reachable from each other. Hence, it is sufficient to run the below algorithm on the DAG of the strongly connected components of the graph. For a node corresponding to component C, we consider the cost of the node p ¡ ¢ min £¤¡ ¥p £ ¦. Algorithm. First of all, we topologically sort the DAG in linear time. Let v § , U v ¨ be the topological order. Then the following function finds the cost array in linear time. find_costs() ¥ for i ¢ n to 1 cost©v ª « ¢ p ¬ for all (v ª , v ® ) ¤ ¯ if (cost°v ® ± ² cost©v ª «) (cost©v ª « ¢ cost°v ® ±) Question 2 Question 2 Question 2 Question 2 Define matrix D so that D ª® is the length of the shortest path from vertex i to vertex ³ in the input graph. Row i of the matrix can be computed by a run of Di³kstra’s algorithm in time ´(µ¶µ · ). S´ we can calculate all of the D in time ´(µ¶µ ¸...
View Full Document
This note was uploaded on 03/01/2010 for the course CS 1234 taught by Professor Chan during the Spring '10 term at University of the Bío-Bío.
- Spring '10