Shortest-Paths Problem
Alternatively, refer to all-pair-shortest-path.
- By breadth-first search, , construct one of the paths by traverse and so on. (for unweighted graphs)
- Optimal substructure: any subpath is also a shortest path from to .
- Predecessor subgraph: , and shortest-paths tree
- Relaxation technique
- Maintains attribute which is an upper bound on the weight of a shortest path from to, i.e. shortest-path estimate.
- Test whether going through improves shortest path to found so far, if so update and .
- Different algorithms relaxes a vertex different times
RELAX(u, v, w)
if v.d > u.d + w(u, v)
v.d = u.d + w(u, v)
v.pi = u
- Algorithms
- Bellman-Ford Algorithm
- For a dag, simply perform topological-sort, and relax the edges in the adjacency list of each vertex.
- Dijkstra’s Algorithm