18.04.2013 Views

The.Algorithm.Design.Manual.Springer-Verlag.1998

The.Algorithm.Design.Manual.Springer-Verlag.1998

The.Algorithm.Design.Manual.Springer-Verlag.1998

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Lecture 18 - shortest path algorthms<br />

Thus in our discussions, we will assume that all edge weights are positive. Other algorithms deal<br />

correctly with negative cost edges.<br />

Minimum spanning trees are uneffected by negative cost edges.<br />

Listen To Part 20-4<br />

Dijkstra's <strong>Algorithm</strong><br />

We can use Dijkstra's algorithm to find the shortest path between any two vertices and t in G.<br />

<strong>The</strong> principle behind Dijkstra's algorithm is that if is the shortest path from to t, then<br />

had better be the shortest path from to x.<br />

This suggests a dynamic programming-like strategy, where we store the distance from to all nearby<br />

nodes, and use them to find the shortest path to more distant nodes.<br />

<strong>The</strong> shortest path from to , d(,)=0. If all edge weights are positive, the smallest edge incident to , say (,x),<br />

defines d(,x).<br />

We can use an array to store the length of the shortest path to each node. Initialize each to to start.<br />

Soon as we establish the shortest path from to a new node x, we go through each of its incident edges to<br />

see if there is a better way from to other nodes thru x.<br />

Listen To Part 20-5<br />

for i=1 to n,<br />

for each edge (,v), dist[v]=d(,v)<br />

last=<br />

while ( )<br />

file:///E|/LEC/LECTUR16/NODE18.HTM (5 of 10) [19/1/2003 1:35:18]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!