Chapter 4: Q6E (page 133)
Question: Prove that for the array prev computed by Dijkstra's algorithm, the edges form a tree.
Short Answer
All the edges form a tree follows this condition if the nodes are connected so there is no cycle.
Chapter 4: Q6E (page 133)
Question: Prove that for the array prev computed by Dijkstra's algorithm, the edges form a tree.
All the edges form a tree follows this condition if the nodes are connected so there is no cycle.
All the tools & learning materials you need for study success - in one app.
Get started for freeYou are given a set of cities, along with the pattern of highways between them, in the form of an undirected graph G = (V , E). Each stretch of highway connects two cities, and you know its length in miles, le. You want to get from city s to city t. There’s one problem: your car can only hold enough gas to cover L miles. There are gas stations in each city, but not between cities. Therefore, you can only take a route if every one of its edges has length
(a) Given the limitation on your car’s fuel tank capacity, show how to determine in linear time whether there is a feasible route from sto t.
(b) You are now planning to buy a new car, and you want to know the minimum fuel tank capacity that is needed to travel from s to t. Give analgorithm to determine this.
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
Question: 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
Output: The number of distinct shortest paths from utov.
Consider a directed graph in which the only negative edges are those that leaves; all other edges are positive. Can Dijkstra's algorithm, started at s, fail on such a graph? Prove your answer.
You are given a directed graph with (possibly negative) weighted edges, along with a specific node and a tree . Give an algorithm that checks whether T is a shortest-path tree for G with starting point s . Your algorithm should run in linear time.
What do you think about this solution?
We value your feedback to improve our textbook solutions.