Example with the first pass k 1 we attempt passing

Info icon This preview shows pages 123–134. Sign up to view the full content.

Example With the first pass, k = 1 , we attempt passing through vertex v 1 We update each of these 2 3 4 5 1 3 4 5 1 1 4 1 1 2 3 5 1 2 3 4
Image of page 123

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

Example After all the steps, we end up with the matrix P = ( p i,j ) : 2 3 4 5 3 3 4 4 1 1 4 4 5 5 5 5 2 2 2 2
Image of page 124
Example These are all the adjacent edges that are still the shortest distance For each of these, p i,j = j In all cases, the shortest distance from vertex 1 is the direct edge 2 3 4 5 3 3 4 4 1 1 4 4 5 5 5 5 2 2 2 2
Image of page 125

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

Example From vertex v 2 , p 2,3 = 3 and p 2,4 = 4 ; we go directly to vertices v 3 and v 4 But p 2,1 = 3 and p 3,1 = 1 ; the shortest path to v 1 is (2, 3, 1) Also, p 2,5 = 4 and p 4,5 = 5 ; the shortest path to v 5 is (2, 4, 5) 2 3 4 5 3 3 4 4 1 1 4 4 5 5 5 5 2 2 2 2
Image of page 126
Example From vertex v 3 , p 3,1 = 1 and p 3,4 = 4 ; we go directly to vertices v 1 and v 4 But p 3,2 = 1 and p 1,2 = 2 ; the shortest path to v 2 is (3, 1, 2) Also, p 3,5 = 4 and p 4,5 = 5 ; the shortest path to v 5 is (3, 4, 5) 2 3 4 5 3 3 4 4 1 1 4 4 5 5 5 5 2 2 2 2
Image of page 127

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

Example From vertex v 4 , p 4,5 = 5 ; we go directly to vertex v 5 But p 4,1 = 5, p 5,1 = 2, p 2,1 = 3, p 3,1 = 1 ; the shortest path to v 1 is (4, 5, 2, 3, 1) 2 3 4 5 3 3 4 4 1 1 4 4 5 5 5 5 2 2 2 2
Image of page 128
Example From vertex v 5 , p 5,2 = 2 ; we go directly to vertex v 2 But p 5,4 = 2 and p 2,4 = 4 ; the shortest path to v 4 is (5, 2, 4) 2 3 4 5 3 3 4 4 1 1 4 4 5 5 5 5 2 2 2 2
Image of page 129

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

Which Vertices are Connected? Finally, what if we only care if a connection exists? Recall that with Dijkstra’s algorithm, we could find the shortest paths by recording the previous node In this case, can make the observation that: A path from v i to v j exists if either: A path exists through the vertices from v 1 to v k –1 , or A path, through those same nodes, exists from v i to v k and a path exists from v k to v j
Image of page 130
Which Vertices are Connected? The transitive closure is a Boolean graph: bool tc[num_vertices][num_vertices]; // Initialize the matrix tc: Theta(|V|^2) // ... // Run Floyd-Warshall for ( int k = 0; k < num_vertices; ++k ) { for ( int i = 0; i < num_vertices; ++i ) { for ( int j = 0; j < num_vertices; ++j ) { tc[i][j] = tc[i][j] || (tc[i][k] && tc[k][j]); } } }
Image of page 131

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

Example Consider this directed graph Each pair has only one directed edge Vertex v 1 is a source and v 4 is a sink We will apply all three matrices Shortest distance Paths Transitive closure
Image of page 132
Example We set up the three initial matrices T T T T T T F F T F F T F T T F T F F F F F F F F T T T T T F T F T F T F F T T F F 2 3 4 5 6 7 4 7 2 4 6 2 3 4 6 7 2 4 7 3 4
Image of page 133

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

Image of page 134
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern