{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

assignment2_tempsol - CSIS0250B Sample solution for...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CSIS0250B - Sample solution for Assignment 2 (2009-03-12) 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 C g3404 min g2931g1488C g4668p g2931 g4669. Algorithm. First of all, we topologically sort the DAG in linear time. Let v g2869 ,uni2026v g2924 be the topological order. Then the following function finds the cost array in linear time. find_costs() g4668 for i g3404 n to 1 costg4670v g2919 g4671g3404 p g2932 g3167 for all (v g2919 ,v g2920 )g1488uni0045 if (costg3427v g2920 g3431g3407costg4670v g2919 g4671) (costg4670v g2919 g4671g3404costg3427v g2920 g3431) Question 2 Question 2 Question 2 Define matrix D so that D g2919g2920 is the length of the shortest path from vertex i to vertex uni006A in the input graph. Row i of the matrix can be computed by a run of Diuni006Akstra’s algorithm in time uni004F(uni007Cuni0056uni007C g2870 ). Suni004F we can calculate all of the D in time uni004F(uni007Cuni0056uni007C g2871 ).
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}