0% found this document useful (0 votes)
16 views

Shortest Path Algorithm

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Shortest Path Algorithm

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Shortest Path Algorithm

➢ Let us begin our study of routing algorithms with a simple technique for computing

optimal paths given a complete picture of the network.

➢ 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

shortest path between them on the graph.

DR V RAMA KRISHNA TOTTEMPUDI 1


➢ The concept of a shortest path deserves some explanation.

➢ One way of measuring path length is the number of hops.

➢ 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

much longer than ABE (assuming the figure is drawn to scale).

➢ 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

packet, as measured by hourly runs.

➢ With this graph labeling, the shortest path is the fastest path rather than the path

with the fewest edges or kilometers.

➢ In the general case, the labels on the edges could be computed as a function of the

distance, bandwidth, average traffic, communication cost, measured delay, and

other factors.

➢ By changing the weighting function, the algorithm would then compute the

‘‘shortest’’ path measured according to any one of a number of criteria or to a

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

all destinations in the network.

➢ Each node is labeled (in parentheses) with its distance from the source node along

the best known path.

➢ The distances must be non-negative, as they will be if they are based on real

quantities like bandwidth and delay.

DR V RAMA KRISHNA TOTTEMPUDI 2


➢ Initially, no paths are known, so all nodes are labelled with infinity.

➢ As the algorithm proceeds and paths are found, the labels may change, reflecting

better paths.

➢ A label may be either tentative or permanent.

➢ Initially, all labels are tentative.

➢ When it is discovered that a label represents the shortest possible path from the

source to that node, it is made permanent and never changed thereafter.

➢ 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.

➢ We want to find the shortest path from A to D.

➢ We start out by marking node A as permanent, indicated by a filled-in circle.

➢ Then we examine, in turn, each of the nodes adjacent to A (the working node),

relabeling each one with the distance to A.

➢ Whenever a node is relabeled, we also label it with the node from which the probe

was made so that we can reconstruct the final path later.

➢ 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

node with the same distance.

➢ 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

permanent, as shown in Fig. 5-7(b).

➢ This one becomes the new working node.

DR V RAMA KRISHNA TOTTEMPUDI 3


➢ We now start at B and examine all nodes adjacent to it. If the sum of the label on B

and the distance from B to the node being considered is less than the label on that

node, we have a shorter path, so the node is relabeled.

➢ 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

labeled node with the smallest value.

➢ This node is made permanent and becomes the working node for the next round.

➢ Figure 5-7 shows the first six steps of the algorithm.

➢ To see why the algorithm works, look at Fig. 5-7(c).

➢ At this point we have just made E permanent.

➢ 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

has not been.

➢ 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,

allowing E to be probed from Z.

➢ This algorithm is given in C in Fig. 5-8. The global variables n and dist describe the

graph and are initialized before shortest path is called.

DR V RAMA KRISHNA TOTTEMPUDI 4

You might also like