lect24-floyd-warshall

lect24-floyd-warshall - Lecture Notes CMSC 251 1 5 4 1 4 3...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Lecture Notes CMSC 251 1 5 4 1 4 3 2 1 4 12 0 5 5 0 1 ? 0 3 9 1 (2) D = 3 4 7 5 7 2 3 1 5 4 1 4 3 3 (1) 13 7 2 3 4 7 0 5 6 ? 2 9 4 ? 0 ? ? 0 1 ? 0 8 ? 1 ? = infinity W = 9 1 2 4 8 1 4 3 2 1 13 2 3 3 9 5 12 2 2 1 5 0 1 6 0 3 4 1 (3) D = = D Figure 29: Shortest Path Example. Lecture 24: Floyd-Warshall Algorithm (Thursday, April 23, 1998) Read: Chapt 26 (up to Section 26.2) in CLR. Floyd-Warshall Algorithm: We continue discussion of computing shortest paths between all pairs of ver- tices in a directed graph. The Floyd-Warshall algorithm dates back to the early 60’s. Warshall was interested in the weaker question of reachability: determine for each pair of vertices u and v , whether u can reach v . Floyd realized that the same technique could be used to compute shortest paths with only minor variations. The Floyd-Warshall algorithm improves upon this algorithm, running in Θ( n 3 ) time. The genius of the Floyd-Warshall algorithm is in finding a different formulation for the shortest path subproblem than the path length formulation introduced earlier. At first the formulation may seem most unnatural, but it leads to a faster algorithm. As before, we will compute a set of matrices whose entries are d ( k ) ij . We will change the meaning of each of these entries. For a path p = h v 1 , v 2 , . . . , v ‘ i we say that the vertices v 2 , v 3 , . . . , v ‘- 1 are the intermediate vertices of this path. Note that a path consisting of a single edge has no intermediate vertices. We define d ( k ) ij to be the shortest path from i to j such that any intermediate vertices on the path are chosen from the set { 1 , 2 , . . . , k } . In other words, we consider a path from i to j which either consists of the single edge ( i, j ) , or it visits some intermediate vertices along the way, but these intermediate can only be chosen from { 1 , 2 , . . . , k } . The path is free to visit any subset of these vertices, and to do so in any order. Thus, the difference between Floyd’s formulation and the previous formulation is that here the superscript ( k ) restricts the set of vertices that the path is allowed to pass through, and there the superscript ( m ) restricts the number of edges the path is allowed to use. For example, in the digraph shown in the following figure, notice how the value of d ( k ) 32 changes as k varies....
View Full Document

This note was uploaded on 01/13/2012 for the course CMSC 351 taught by Professor Staff during the Fall '11 term at University of Louisville.

Page1 / 4

lect24-floyd-warshall - Lecture Notes CMSC 251 1 5 4 1 4 3...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online