{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

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

View Full Document Right Arrow Icon
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
Image of page 1

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

View Full Document Right Arrow Icon
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.
Image of page 2
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).
Image of page 3

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

View Full Document Right Arrow Icon
Image of page 4
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