20-apsp - Algorithms Lecture 20 All-Pairs Shortest Paths The tree which fills the arms grew from the tiniest sprout the tower of nine storeys rose

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: Algorithms Lecture 20: All-Pairs Shortest Paths The tree which fills the arms grew from the tiniest sprout; the tower of nine storeys rose from a (small) heap of earth; the journey of a thousand li commenced with a single step. — Lao-Tzu, Tao Te Ching , chapter 64 (6th century BC), translated by J. Legge (1891) And I would walk five hundred miles, And I would walk five hundred more, Just to be the man who walks a thousand miles To fall down at your door. — The Proclaimers, “Five Hundred Miles (I’m Gonna Be)”, Sunshine on Leith (2001) Almost there...Almost there... — Red Leader [Drewe Henley], Star Wars (1977) 20 All-Pairs Shortest Paths 20.1 The Problem In the previous lecture, we saw algorithms to find the shortest path from a source vertex s to a target vertex t in a directed graph. As it turns out, the best algorithms for this problem actually find the shortest path from s to every possible target (or from every possible source to t ) by constructing a shortest path tree. The shortest path tree specifies two pieces of information for each node v in the graph: • dist ( v ) is the length of the shortest path (if any) from s to v ; • pred ( v ) is the second-to-last vertex (if any) the shortest path (if any) from s to v . In this lecture, we want to generalize the shortest path problem even further. In the all pairs shortest path problem, we want to find the shortest path from every possible source to every possible destination. Specifically, for every pair of vertices u and v , we need to compute the following information: • dist ( u , v ) is the length of the shortest path (if any) from u to v ; • pred ( u , v ) is the second-to-last vertex (if any) on the shortest path (if any) from u to v . For example, for any vertex v , we have dist ( v , v ) = 0 and pred ( v , v ) = N ULL. If the shortest path from u to v is only one edge long, then dist ( u , v ) = w ( u v ) and pred ( u , v ) = u . If there is no shortest path from u to v —either because there’s no path at all, or because there’s a negative cycle—then dist ( u , v ) = ∞ and pred ( v , v ) = N ULL. The output of our shortest path algorithms will be a pair of V × V arrays encoding all V 2 distances and predecessors. Many maps include a distance matrix—to find the distance from (say) Champaign to (say) Columbus, you would look in the row labeled ‘Champaign’ and the column labeled ‘Columbus’. In these notes, I’ll focus almost exclusively on computing the distance array. The predecessor array, from which you would compute the actual shortest paths, can be computed with only minor additions to the algorithms I’ll describe (hint, hint). 20.2 Lots of Single Sources The obvious solution to the all-pairs shortest path problem is just to run a single-source shortest path algorithm V times, once for every possible source vertex! Specifically, to fill in the one-dimensional subarray dist [ s , · ] , we invoke either Dijkstra’s or Shimbel’s algorithm starting at the source vertex...
View Full Document

This note was uploaded on 10/14/2011 for the course ECON 101 taught by Professor Smith during the Spring '11 term at West Virginia University Institute of Technology.

Page1 / 10

20-apsp - Algorithms Lecture 20 All-Pairs Shortest Paths The tree which fills the arms grew from the tiniest sprout the tower of nine storeys rose

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