Presentation is loading. Please wait.

Presentation is loading. Please wait.

Data Structures and Algorithms (AT70.02) Comp. Sc. and Inf. Mgmt. Asian Institute of Technology Instructor: Dr. Sumanta Guha Slide Sources: CLRS “Intro.

Similar presentations


Presentation on theme: "Data Structures and Algorithms (AT70.02) Comp. Sc. and Inf. Mgmt. Asian Institute of Technology Instructor: Dr. Sumanta Guha Slide Sources: CLRS “Intro."— Presentation transcript:

1 Data Structures and Algorithms (AT70.02) Comp. Sc. and Inf. Mgmt. Asian Institute of Technology Instructor: Dr. 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)

4

5 Π(v) is the predecessor of v in the shortest path to v.

6

7

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 = (v 0, v 1, …, v k ) is a shortest path from s = v 0 to v k, and the edges of p are relaxed in the order (v 0,v 1 ), (v 1,v 2 ), …, (v k-1,v k ), then d[v k ] = δ(s,v k ). 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 weight cycle reachable from s then Bellman-Ford returns FALSE. Running time:  (|V||E|)

10

11

12

13

14 // all edge weights are assumed non-negative

15 Proof that Dijkstra is correct

16 x 1 – x 2 ≤ 0, x 1 – x 5 ≤ -1, x 2 – x 5 ≤ 1, x 3 – x 1 ≤ 5, x 4 – x 1 ≤ 4, x 4 – x 3 ≤ -1, x 5 – x 3 ≤ -3, x 5 – x 4 ≤ -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 = ( δ(v 0, v 1 ), δ(v 0, v 2 ), …, δ(v 0, v k ) ) is a feasible solution for the system. If G contains a negative-weight cycle, then there is no feasible solution for the system.

17 Problems Ex Ex Ex Ex Ex Ex Ex Ex


Download ppt "Data Structures and Algorithms (AT70.02) Comp. Sc. and Inf. Mgmt. Asian Institute of Technology Instructor: Dr. Sumanta Guha Slide Sources: CLRS “Intro."

Similar presentations


Ads by Google