nextupprevious
Next:7.3 Warshall's AlgorithmUp:7.2 Shortest Paths ProblemPrevious:7.2.2 Dynamic Programming Algorithm

7.2.3 All Pairs Shortest Paths Problem: Floyd's Algorithm

REF.
Robert W Floyd. Algorithm 97 (Shortest Path). Communications of the ACM, Volume 5, Number 6, pp. 345, 1962.
tex2html_deferredGiven $\textstyle :$ $\displaystyle \mbox{A digraph $G = (V, E)$\space in which eacharc $v \rightarrow w$\space has}$  
    $\displaystyle \mbox{a nonnegative cost $C[v,w]$ }$  
$\displaystyle \mbox{{\bf To find}}$ $\textstyle :$ $\displaystyle \mbox{For each ordered pair of vertices $(v,w)$ , thesmallest}$  
    $\displaystyle \mbox{ length of any path from $v$\space to $w$ }$  

Floyd's Algorithm


Figure 7.9: A digraph example for Floyd's algorithm
\begin{figure}\centerline{\psfig{figure=figures/Ffloyd2.ps}}\end{figure}

Example: See Figure 7.9.

C$\displaystyle \left[\vphantom{\begin{array}{ccc} 2 & 8 & 5 \\ 3 & \infty& \infty\\ \infty& 2 & \infty\\ \end{array} }\right.$$\displaystyle \begin{array}{ccc} 2 & 8 & 5 \\ 3 & \infty& \infty\\ \infty& 2 & \infty\\ \end{array}$$\displaystyle \left.\vphantom{\begin{array}{ccc} 2 & 8 & 5 \\ 3 & \infty& \infty\\ \infty& 2 & \infty\\ \end{array} }\right]$
A0 = $\displaystyle \left[\vphantom{\begin{array}{ccc} 0 & 8 & 5 \\ 3 & 0 & \infty\\ \infty& 2 &0 \\ \end{array} }\right.$$\displaystyle \begin{array}{ccc} 0 & 8 & 5 \\ 3 & 0 & \infty\\ \infty& 2 &0 \\ \end{array}$$\displaystyle \left.\vphantom{\begin{array}{ccc} 0 & 8 & 5 \\ 3 & 0 & \infty\\ \infty& 2 &0 \\ \end{array} }\right]$;   A1$\displaystyle \left[\vphantom{\begin{array}{ccc} 0 & 8 & 5 \\ 3 &0 & 8 \\ \infty& 2 & 0 \\ \end{array} }\right.$$\displaystyle \begin{array}{ccc} 0 & 8 & 5 \\ 3 &0 & 8 \\ \infty& 2 & 0 \\ \end{array}$$\displaystyle \left.\vphantom{\begin{array}{ccc} 0 & 8 & 5 \\ 3 &0 & 8 \\ \infty& 2 & 0 \\ \end{array} }\right]$ (7.15)
A2 = $\displaystyle \left[\vphantom{\begin{array}{ccc} 0 & 8 & 5 \\ 3 & 0 & 8 \\ 5 & 2 & 0 \\ \end{array}}\right.$$\displaystyle \begin{array}{ccc} 0 & 8 & 5 \\ 3 & 0 & 8 \\ 5 & 2 & 0 \\ \end{array}$$\displaystyle \left.\vphantom{\begin{array}{ccc} 0 & 8 & 5 \\ 3 & 0 & 8 \\ 5 & 2 & 0 \\ \end{array}}\right]$;   A3$\displaystyle \left[\vphantom{\begin{array}{ccc} 0 & 8 & 5 \\ 3 & 0 & 8 \\ 5 & 2 & 0 \\ \end{array}}\right.$$\displaystyle \begin{array}{ccc} 0 & 8 & 5 \\ 3 & 0 & 8 \\ 5 & 2 & 0 \\ \end{array}$$\displaystyle \left.\vphantom{\begin{array}{ccc} 0 & 8 & 5 \\ 3 & 0 & 8 \\ 5 & 2 & 0 \\ \end{array}}\right]$  

nextupprevious
Next:7.3 Warshall's AlgorithmUp:7.2 Shortest Paths ProblemPrevious:7.2.2 Dynamic Programming Algorithm
eEL,CSA_Dept,IISc,Bangalore