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.
/*! This file is auto-generated */ .wp-block-button__link{color:#fff;background-color:#32373c;border-radius:9999px;box-shadow:none;text-decoration:none;padding:calc(.667em + 2px) calc(1.333em + 2px);font-size:1.125em}.wp-block-file__button{background:#32373c;color:#fff;text-decoration:none}
Learning Materials
Features
Discover
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 free
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
Squares.Design and analyse an algorithm that takes as input an undirected graph G(V,E) and determines whether graph contains a simple cycle (that is, a cycle which doesn’t intersect itself) of length four. Its running time should be at most time.
You may assume that the input graph is represented either as an adjacency matrix or with adjacency lists, whichever makes your algorithm simpler.
Here's a proposal for how to find the length of the shortest cycle in an undirected graph with unit edge lengths. When a back edge, say , is encountered during a depth-first search, it forms a cycle with the tree edges from . The length of the cycle is where the level of a vertex is its distance in the DFS tree from the root vertex. This suggests the following algorithm:
• Do a depth-first search, keeping track of the level of each vertex.
• Each time a back edge is encountered, compute the cycle length and save it if it is smaller than the shortest one previously seen. Show that this strategy does not always work by providing a counterexample as well as a brief (one or two sentence) explanation.
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.
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:)
What do you think about this solution?
We value your feedback to improve our textbook solutions.