Shortest Path Algorithm
Shortest Path Algorithm
➢ Let us begin our study of routing algorithms with a simple technique for computing
➢ These paths are the ones that we want a distributed routing algorithm to find, even
though not all routers may know all of the details of the network.
➢ The idea is to build a graph of the network, with each node of the graph representing
a router and each edge of the graph representing a communication line, or link.
➢ To choose a route between a given pair of routers, the algorithm just finds the
➢ Using this metric, the paths ABC and ABE in Fig. 5-7 are equally long.
➢ Another metric is the geographic distance in kilometers, in which case ABC is clearly
➢ However, many other metrics besides hops and physical distance are also possible.
➢ For example, each edge could be labeled with the mean delay of a standard test
➢ With this graph labeling, the shortest path is the fastest path rather than the path
➢ In the general case, the labels on the edges could be computed as a function of the
other factors.
➢ By changing the weighting function, the algorithm would then compute the
combination of criteria.
➢ Several algorithms for computing the shortest path between two nodes of a graph
are known.
➢ This one is due to Dijkstra (1959) and finds the shortest paths between a source and
➢ Each node is labeled (in parentheses) with its distance from the source node along
➢ The distances must be non-negative, as they will be if they are based on real
➢ As the algorithm proceeds and paths are found, the labels may change, reflecting
better paths.
➢ When it is discovered that a label represents the shortest possible path from the
➢ To illustrate how the labeling algorithm works, look at the weighted, undirected
graph of Fig. 5-7(a), where the weights represent, for example, distance.
➢ Then we examine, in turn, each of the nodes adjacent to A (the working node),
➢ Whenever a node is relabeled, we also label it with the node from which the probe
➢ If the network had more than one shortest path from A to D and we wanted to find
all of them, we would need to remember all of the probe nodes that could reach a
➢ Having examined each of the nodes adjacent to A, we examine all the tentatively
labeled nodes in the whole graph and make the one with the smallest label
and the distance from B to the node being considered is less than the label on that
➢ After all the nodes adjacent to the working node have been inspected and the
tentative labels changed if possible, the entire graph is searched for the tentatively
➢ This node is made permanent and becomes the working node for the next round.
➢ Suppose that there were a shorter path than ABE, say AXYZE (for some X and Y).
➢ There are two possibilities: either node Z has already been made permanent, or it
➢ If it has, then E has already been probed (on he round following the one when Z was
made permanent), so the AXYZE path has not escaped our attention and thus cannot
be a shorter path.
➢ Now consider the case where Z is still tentatively labeled. If the label at Z is greater
than or equal to that at E, then AXYZE cannot be a shorter path than ABE.
➢ If the label is less than that of E, then Z and not E will become permanent first,
➢ This algorithm is given in C in Fig. 5-8. The global variables n and dist describe the