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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Lecture 18 - shortest path algorthms<br />

Although this is slick, observe that even is slower than running Dijkstra's algorithm starting<br />

from each vertex!<br />

Listen To Part 20-12<br />

<strong>The</strong> Floyd-Warshall <strong>Algorithm</strong><br />

An alternate recurrence yields a more efficient dynamic programming formulation. Number the vertices<br />

from 1 to n.<br />

Let be the shortest path from i to j using only vertices from 1, 2,..., k as possible intermediate<br />

vertices.<br />

What is ? With no intermediate vertices, any path consists of at most one edge, so .<br />

In general, adding a new vertex k+1 helps iff a path goes through it, so<br />

Although this looks similar to the previous recurrence, it isn't. <strong>The</strong> following algorithm implements it:<br />

for k=1 to n<br />

for i=1 to n<br />

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

for j=1 to n

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

Saved successfully!

Ooh no, something went wrong!