# hw_2_soln - CS 473: Algorithms, Fall 2010 HW 2 Solutions 1....

This preview shows pages 1–3. Sign up to view the full content.

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS 473: Algorithms, Fall 2010 HW 2 Solutions 1. (30 pts) Suppose you are given a directed graph G = ( V , E ) with non-negative edge lengths; ‘ ( e ) is the length of e ∈ E . You are interested in the shortest path distance between two given locations / nodes s and t . It has been noticed that the existing shortest path distance between s and t in G is not satisfactory and there is a proposal to add exactly one edge to the graph to improve the situation. The candidate edges from which one has to be chosen is given by E = { e 1 , e 2 ,..., e k } and you can assume that E ∩ E = ; . The length of the e i is α i ≥ 0. Your goal is figure out which of these k edges will result in the most reduction in the shortest path distance from s to t . Describe an algorithm for this problem that runs in time O (( m + n ) log n + k ) where m = | E | and n = | V | . Note that one can easily solve this problem in O ( k ( m + n ) log n ) by running Dijkstra’s algorithm k times, one for each G i where G i is the graph obtained by adding e i to G . Solution: R EDUCE S HORTEST P ATH ( G , E , s , t ) : Create an array d storing shortest paths from v i to v j where v i ∈{ s , t } and v j ∈ V d ( s , s ) ← For each vertex v ∈ V \ s d ( s , v ) ←∞ Execute D IJKSTRA ( G , s ) to compute d ( s , v ) , ∀ v ∈ V Reverse the edges in the graph G to create the graph G d ( t , t ) ← For each vertex v ∈ V \ t d ( t , v ) ←∞ Execute D IJKSTRA ( G , t ) to compute d ( t , v ) , ∀ v ∈ V least ← d ( s , t ) bestindex ← NONE For each edge e i = ( u i , v i ) ∈ E dist ← d ( s , u i )+ weight ( u i , v i )+ d ( t , v i ) IF least > dist least ← dist bestindex ← i Output e bestindex Description The problem asks us to find exactly one edge from the set of edges E , such that the addition of that edge will result in the most reduction of the shortest path from s to t. Initially, we start off with implementing the Dijkstra’s algorithm with the vertex s as the source. As Dijkstra’s algorithm is a single source shortest path algorithm, after the implementation of the algorithm, the shortest distance from the source s to all nodes in V is now available. We now reverse the edges of the original graph G to create the graph G . We now implement a Dijkstra’s algorithm on the graph G with node t as the source. We now get shortest path from any node in the graph G to the node t , this is because we have the shortest distance from t to any node in graph G . Then we pick edges e i ∈ E one by one, and look at the shortest path from s to t containing the edge e i . In order for calculating the shortest path from s to t that is guaranteed to contain an edge ( u , v ) , we need to sum the shortest distance from s to u , the weight of the edge ( u , v ) ∈ E and the shortest 1 distance from the node v to t . We pick the edge e i whose addition to the graph G results in the minimum length path from s to t ....
View Full Document

## This note was uploaded on 04/18/2011 for the course CS 473 taught by Professor Chekuri,c during the Spring '08 term at University of Illinois, Urbana Champaign.

### Page1 / 6

hw_2_soln - CS 473: Algorithms, Fall 2010 HW 2 Solutions 1....

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online