{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# lec402 - All-Pairs Shortest Paths Given an n-vertex...

This preview shows pages 1–4. Sign up to view the full content.

All-Pairs Shortest Paths Given an n- vertex directed weighted graph, find a shortest path from vertex i to vertex j for each of the n 2 vertex pairs (i,j) . 1 2 3 4 5 6 7 5 7 1 7 9 1 9 4 4 5 16 4 2 8 1 2 Dijkstra’s Single Source Algorithm Use Dijkstra’s algorithm n times, once with each of the n vertices as the source vertex. 1 2 3 4 5 6 7 5 7 1 7 9 1 9 4 4 5 16 4 2 8 1 2

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

View Full Document
Performance Time complexity is O(n 3 ) time. Works only when no edge has a cost < 0 . Dynamic Programming Solution Time complexity is Theta(n 3 ) time. Works so long as there is no cycle whose length is < 0 . When there is a cycle whose length is < 0 , some shortest paths aren’t finite. If vertex 1 is on a cycle whose length is -2 , each time you go around this cycle once you get a 1 to 1 path that is 2 units shorter than the previous one. Simpler to code, smaller overheads. Known as Floyd’s shortest paths algorithm.
Decision Sequence First decide the highest intermediate vertex (i.e., largest vertex number) on the shortest path from i to j . If the shortest path is i, 2, 6, 3, 8, 5, 7, j the first decision is that vertex 8 is an intermediate vertex on the shortest path and no intermediate vertex is larger than 8 . Then decide the highest intermediate vertex on the path from i to 8 , and so on. i j Problem State (i,j,k) denotes the problem of finding the shortest path from vertex i to vertex j that has no intermediate vertex larger than k . (i,j,n) denotes the problem of finding the shortest path from vertex i to vertex j (with no restrictions on intermediate vertices).

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• 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.

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

• 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.

Dana University of Pennsylvania ‘17, Course Hero Intern

• 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.

Jill Tulane University ‘16, Course Hero Intern