CIS 9615. Analysis of Algorithms

Advanced Graph Algorithms

 

1. Single-source shortest paths

In a weighted graph, the weight of a path is the sum of the weights of the edges in the path. A shortest path is a path whose weight has the lowest value among all paths with the same source and destination vertex. A section of a shortest path is also a shortest path. For graph G = (V, E), the shortest path contains less than |V| edges. If a graph contains a negatively-weighted cycle, then there is no shortest path on that cycle.

If all edges are equally-weighted, the breadth-first search algorithm finds shortest paths from a source vertex to all other vertices. However, it does not work if the edges have different weights.

The following algorithm initializes the distance array d and the predecessor array π.
10-01 (9K)

Many shortest-path algorithm use the "relaxation" technique, which tries to improve the shortest distance to vertex v by taking vertex u into consideration, with (u, v) as the last step. The matrix w stores the weights of the edges.
10-02 (7K)

Bellman-Ford algorithm processes the graph |V|-1 passes, and in each pass, tries the edges one-by-one to relax the distance. After that, if there is still possible relaxation, the graph contains negatively-weighted cycle.
10-03 (21K)

The running time is O(V E). Example:
10-04 (50K)

If the graph is a DAG, there are faster solutions. The following algorithm topologically sort the vertices first, then determine the shortest paths for each vertex in that order. It runs in Θ(V + E) time, which comes from topological sorting (and DFS).
10-05 (20K)
Example:
10-06 (68K)

Dijkstra's algorithm works for directed graphs without negative weight. It repeatedly selects the vertex with the shorted path, then use it to relax the paths to other vertices. It is similar to MST-Prim, except here the distance is to the starting vertex, not to the MST.
10-07 (17K)
This is a greedy algorithm. Its running time is O((V + E) lg V). Example:
10-08 (54K)

 

2. All-pairs shortest paths

If we want the shortest paths between every pair of vertices, it is inefficient to repeat an algorithm for single-source.

Many algorithms use the adjacency matrix to remember the shortest paths found so far, and a predecessor matrix Π, where πij is the predecessor of j on some shortest path from i to j. Given it, the following algorithm prints the shortest path recursively.
10-09 (17K)

The following dynamic-programming algorithm extends shortest paths starting with edge, and in each step tries to add one more edge.
10-10 (17K)
Each call to the above algorithm will extend the length of path under consideration by one. Therefore, if we start with L = W, and repeatedly call the algorithm n-1 times, we will get a matrix for the shortest paths. This solution takes Θ(n4) time.

Floyd-Warshall algorithm in each step adds one possible intermediate vertex into the shortest paths.
10-11 (15K)
The running time of the above algorithm is Θ(n3).

A similar algorithm calculates the transitive closure of a graph, where T(n)ij = 1 if and only if there is a path from i to j.
10-12 (22K)

 

3. Maximum flow

Flow network: directed and weighted graph, where weight is interpreted as the flow capacity of the edge, the upper bound of the actual flow. For each vertex, the total "flow-in" and "flow-out" must be the same, except a source vertex and a sink vertex, which have a net flow-in and flow-out, respectively, of the whole network, and the two numbers must be the same.

The following method finds the maximum flow of a given flow network:

Ford-Fulkerson-Method(G, s, t)
1 initialize flow f to 0
2 while there exists an augmenting path p
3     do augment flow f along p
4 return f
Intuitively, an augmenting path is a path from s to t that still has residual (remaining) capacity, and the additional flow is decided by the edge in the path that has the smallest difference between the flow capacity and the current flow.

Example: Figure 26.5

When an algorithm follows this method and uses BFS to scan the paths, the running time of the algorithm is O(V E2). See the textbook for details.