Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 24: Single-Source Shortest Paths

Similar presentations


Presentation on theme: "Chapter 24: Single-Source Shortest Paths"— Presentation transcript:

1 Chapter 24: Single-Source Shortest Paths
Input: - Directed graph G(V,E). - Weight (‘length’) function w: E  R. Notions: Weight/length of a directed path. Shortest path from u to v, denoted DELTA(u,v): length of minimum weight/length path from u to v. Other variants: Single-source shortest paths All-pair shortest paths

2 Observations Subpaths of shortest paths are shortest path
Can a shortest path contain a cycle? Answer: Neither negative nor positive length

3 Representation of shortest path
Weighted directed graph. Nodes show shortest path from s. Shaded edges: shortest path tree rooted at s. Another shortest path tree.

4 The two case: Does edge uv relax d(v)?
d(v) shortest distance from s to v based on ‘current knowledge’ Growth of ‘current knowledge’ from one step of an algorithm to the next: key difference between algorithms

5 Bellman-Ford algorithm
Initialize d(s)  0; all other v in V: d(v)  ‘infinity |V|-1 rounds: For every edge u v: RELAX(U,V) Do the same in round |V|. If any change: return FALSE Inductive claim: If shortest simple path from s to v has i edges then following round i d(v) <= DELTA(s,v) Complexity: O(|E| |V|)

6 Single/all source shortest/longest paths in DAGs
PERT graphs: important in operations research, compiler One variant: - Start with vertices who in-degree is 0. Peel and relax. Repeat. Note: topological sort is redundant. Similar point to 22.4

7 Dijkstra’s algorithm All edge weights are non-negative.
d(s) is final distance of s. RELAX all edges su for all u. v – the vertex whose d(s) is minimum over {u: d(u) not finalized}; finalize d(v); RELAX vu for all u.

8 Correctness proof of Dijkstra’s algorithm
Inductive Claim: Following iteration i, d(v) = DELTA(s,v) for every vertex v whose d(v) was finalized by the end of iteration i. Sketch of proof: Assume the inductive claims for i-1. Suppose that d(u) is finalized in iteration i , but there is a path (e.g., p2 in figure) from s to u, which is shorter than all paths restricted to previously finalized nodes (set S in figure) plus u. Let y be the first node in p2 outside S; but d(y) must be < d(u) at the time that u was picked as minimum outside S. A contradiction.

9 Complexity of Dijktra’s algorithm
O(|E|) DECREASE-KEY queries and O(|V|) EXTRACT-MIN queries lead to O((|E|+|V|) log |V|) time. Can be improved to to O(|E|+|V| log |V|) time.

10

11


Download ppt "Chapter 24: Single-Source Shortest Paths"

Similar presentations


Ads by Google