Download presentation
Presentation is loading. Please wait.
Published bySri Jayadi Modified over 6 years ago
1
Data Structures and Algorithms (AT70. 02) Comp. Sc. and Inf. Mgmt
Data Structures and Algorithms (AT70.02) Comp. Sc. and Inf. Mgmt. Asian Institute of Technology Instructor: Prof. Sumanta Guha Slide Sources: CLRS “Intro. To Algorithms” book website (copyright McGraw Hill) adapted and supplemented
2
CLRS “Intro. To Algorithms” Ch. 24: Single-Source Shortest Paths
3
The shortest-path weight from s to v is denoted δ(s,v)
5
Π(v) is the predecessor of v in the shortest path to v
= parent in the shortest-paths tree
6
d [v] is the shortest path estimate to v. In fact, d [v] will
always be at least as long as the actual shortest path.
8
Properties of shortest paths and relaxation
Triangle inequality: for any edge (u,v) E, we have δ(s,v) δ(s,u) + w(u,v). Upper bound property: We always have d[v] ≥ δ(s,v) for all vertices v V, and once d[v] achieves the value δ(s,v), it never changes (even with further relaxations). No-path property: If there is no path from s to v, then we always have d[v] = δ(s,v) = . Convergence property: If s … u v is a shortest path in G for some u, v V, and if d[u] = δ(s,u) at any time prior to relaxing edge (u,v), then d[v] = δ(s,v) at all times afterwards. Path relaxation property: If p = (v0, v1, …, vk) is a shortest path from s = v0 to vk, and the edges of p are relaxed in the order (v0,v1), (v1,v2), …, (vk-1,vk), then d[vk] = δ(s,vk). This property holds regardless of any other relaxation steps that occur, even if they are intermixed with relaxations of the edges of p. Predecessor-subgraph property: Once d[v] = δ(s,v) for all v V, the predecessor subgraph is a shortest paths tree rooted at s. (In fact, if there is no negative-weight cycle reachable from s then the predecessor subgraph is always a tree rooted at s.)
9
If there is no negative edge
weight cycle reachable from s then Bellman-Ford returns TRUE and d[v] = δ(s,v) for every vertex v. If there is a negative edge then Bellman-Ford returns FALSE. Running time: (|V||E|)
10
Topologically Sorting a DAG (Directed Acyclic Graph)
A topological sort of the nodes of a DAG G is a linear ordering such that there is no edge of G going from a node to a predecessor in the ordering.
13
// all edge weights are assumed non-negative
S = {v : d [v] = δ(s,v)}, i.e., vertices for which the shortest path from s has been determined. Q is a min heap of vertices of G keyed by their d (i.e., estimate) values.
14
Proof that Dijkstra is correct
15
x1 – x2 ≤ 0, x1 – x5 ≤ -1, x2 – x5 ≤ 1, x3 – x1 ≤ 5, x4 – x1 ≤ 4, x4 – x3 ≤ -1, x5 – x3 ≤ -3, x5 – x4 ≤ -3. Th. 24.9: Given a system Ax ≤ b of difference equations, let G = (V, E) be the corresponding constraint graph. If G contains no negative-weight cycles, then x = ( δ(v0, v1), δ(v0, v2), …, δ(v0, vk) ) is a feasible solution for the system. If G contains a negative-weight cycle, then there is no feasible solution for the system.
16
Problems Ex. 24.1-1 Ex. 24.2-1 Ex. 24.3-1 Ex. 24.3-2 Ex. 24.3-4
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.