As long as all the edge weights are nonnegative, the shortest-paths tree is well defined. Un- fortunately, things get stopics related to shortest paths, we usually focus on solving problems in directed graphs. It should be noted, however, that most such algorithms can be easily adapted for undirected graphs.
In this chapter, the terms “edge” and “arc” are used interchangeably. We discuss two well- known algorithms for constructing a shortest-paths tree: Dijkstra’s algorithm and the Bellman- Ford algorithm. Dijkstra’s algorithm assumes that all edge weights in the graph are nonnegative, whereas the Bellman-Ford algorithm allows negative-weight edges in the graph. If there is no negative-weight cycle, the Bellman-Ford algorithm produces the shortest paths and their weights. Otherwise, the algorithm detects the negative cycles and indicates that no solution exists.