Hard Problems
Tyler Moore
CSE 3353, SMU, Dallas, TX
April 30, 2013
The many cases of finding shortest paths
We’ve already seen how to calculate the shortest path in an unweighted graph (BFS traversal) We’ll now study how to compute the shortest path in different circumstances for weighted graphs
1
Single-source shortest path on a weighted DAG (review from last week)
2
Single-source shortest path on a weighted graph with nonnegative weights (Dijkstra’s algorithm)
3
Single-source shortest path on a weighted graph including negative weights (Bellman-Ford algorithm)
4
All-pairs shortest path on a weighted graph with nonnegative weights (Floyd-Warshall algorithm)
2 / 22
From single-source to all-pairs shortest paths
The algorithms discussed so far calculated the shortest path to all vertices from a single source We might instead be interested in the shortest path to all vertices from all sources We could run Dijkstra’s or Bellman-Ford n times, one for each source But more efficient solutions exist, particularly when graphs are dense Floyd-Warshall algorithm uses recursion or DP to compute shortest paths between all pairs of vertices
Start by placing nodes in arbitrarily sorted order d(u, v, k): length of shortest path from u to v using first k nodes as intermediaries d(u, v, k) = min(d(u, v, k − 1), d(u, k, k − 1) + d(k, v, k − 1) Repeatedly solve for all pairs with increasing k
3 / 22
All-pairs shortest path application
Let’s compare distances between airport hubs City New York Los Angeles Seattle Atlanta Dallas New York 2470 2400 760 1390 LA 2470 950 1940 1230 Seattle 2400 950 2180 1660 Atlanta 760 1940 2180 729 Dallas 1390 1230 1660 729 Total 7020 7548 8148 5609 5009 The farness of a node in a connected graph is the sum of all shortest path distances to other nodes Closeness centrality: inverse of the average length of all shortest paths from a vertex
4 / 22