Chapter 4: Paths in Graphs
Q10E
You are given a directed graph with (possibly negative) weighted edges, in which the shortest path between any two vertices is guaranteed to have at most edges. Give an algorithm that finds the shortest path between two vertices u and v in time.
Q11E
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 .
Q12E
Give an algorithm for the following task.
Input:An undirected graph ; edge lengths ;an edge .
Output:The length of the shortest cycle containing edge e
Q14E
You are given a strongly connected directed graph with positive edge weights along with a particular . Give an efficient algorithm for finding shortest paths between all pairs of nodes, with the one restriction that these paths must all pass through .
Q15E
Shortest paths are not always unique: sometimes there are two or more different paths with the minimum possible length. Show how to solve the following problem in time.
Input:An undirected graph ;edge lengths ; starting vertex .
Output:A Boolean array for each node u , the entry should be if and only if there is a unique shortest path s to u (Note:)
Q18E
In cases where there are several different shortest paths between two nodes (and edges have varying length),the most convenient of these paths is often the one with fewest edges. Forinstance, if nodes represent cities and edge lengths represent costs of flying between cities, theremight be many ways to get from cityto city t which all have the same cost. The mostconvenientof these alternatives is the one which involves the fewest stopovers. Accordingly, for a specific starting node S , define
minimum number of edges in a shortest path from S to u .
In the example below, thebestvalues for nodes are , respectively.

Give an efficient algorithm for the following problem.
Input:Graph ; positive edge lengths ; starting node .
Output: The values of should be set for all nodes
Q19E
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 ,a graph also has vertex costs . Now define the cost of a path to be the sum of its edge lengths, plusthe costs ofall vertices on the path (including the endpoints). Give an efficient algorithm for the followingproblem.
Input:A directed graph positive edge lengths and positive vertex costs ; a starting vertex .
Output:An array such that for every vertex , is the least cost of any path from s to u (i.e., the cost of the cheapest path), under the defnition above.
Notice that .
Q1E
Suppose Dijkstra’s algorithm is run on the following graph, starting at node A.
a) Draw a table showing the intermediate distance values of all the nodes at each iteration of the algorithm.
b) Show the final shortest-path tree.
Q20E
There is a network of roads G=(V,E) connecting a set of cities . Each road in E has an associated length . There is a proposal to add one new road to this network, and there is a list E' of pairs of cities between which the new road can be built. Each such potential road localid="1659075853079" has an associated length. As a designer for the public works department you are asked to determine the road localid="1659075866764" whose addition to the existing network G would result in the maximum decrease in the driving distance between two fixed cities s and t in the network. Give an efficient algorithm for solving this problem.
Q21P
Shortest path algorithms can be applied in currency trading. Let be various currencies; for instance, might be dollars, pounds, and lire.
For any two currencies and , there is an exchange rate ; this means that you can purchase units of currency in exchange for one unit of . These exchange rates satisfy the condition that so that if you start with a unit of currency , change it into currency and then convert back to currency localid="1658917254028" , you end up with less than one unit of currency (the difference is the cost of the transaction).
a. Give an efficient algorithm for the following problem: Given a set of exchange rates , and two currencies s and t , find the most advantageous sequence of currency exchanges for converting currency into currency . Toward this goal, you should represent the currencies and rates by a graph whose edge lengths are real numbers.
The exchange rates are updated frequently, rejecting the demand and supply of the various currencies. Occasionally the exchange rates satisfy the following property: there is a sequence of currencies such that . This means that by starting with a unit of currency and then successively converting it to currencies , and finally back to , you would end up with more than one unit of currency . Such anomalies Last only a fraction of a minute on the currency exchange, but they provide an opportunity for risk-free profits.
b. Give an efficientalgorithm for detecting the presence of such an anomaly. Use the graph representation you found above.