{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

cse101_11_9_11

# cse101_11_9_11 - c Suppose the shortest path from s to t is...

This preview shows pages 1–2. Sign up to view the full content.

General shortest paths 1. Dijkstra’s alg a. Given G = (V, E) {le}, s For all u in V: Dist[u] = inf Dist[s] = 0 H = V While H != 0 U = node in H with smallest dist[] Remove u from H For all (u, w) in E If dist[w] > dist[u] = l(u, w) Dist[w] = dist[u] + l(u, w) b. Basic principle Shortest path to any node goes through nodes that are closer. Not true with negative edges. 2. Bellman – Ford algorithm – general algorithm a. Dijkstra is basically doing a bunch of update operations: Procedure update ((u, w) in E) If dist[w] > dist[u] + l(u, w) Dist[w] = dist[u] + l(u, w) b. U w b.i. Update is safe – it will never make a dist[] value too small b.ii. If the shortest path to w has u as its second-last node, and dist[u] is correctly set, then update(u, w) will correctly set dist[w]

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: c. Suppose the shortest path from s to t is S -> u1 -> u2 -> u3 -> t Suppose we do a long sequence of update operations that include (s1, u1) , ut, t) In that order, then dist[t] will be correctly set. What sequence of updates is guaranteed to have this property? Ans: update every edge V – 1 times. d. Procedure Bellman-Ford(G, l, s) For all u in V Dist[u] = inf Dist[s] = 0 Repeat V – 1 times: For all c in E Update€ Procedure update (u, w) If dist[w] > dist[u] + l(u, w) Dist[w] = dist[u] + l(u, w) Time: O(V * E) slower than dijkstras S A B C D E 0 inf inf inf inf inf 0 10 inf inf 4 2 0 10 6 10 3 2 0 5 6 10 3 2 5 1 9 3 2 4 1 9 3 2 e....
View Full Document

{[ snackBarMessage ]}

### Page1 / 2

cse101_11_9_11 - c Suppose the shortest path from s to t is...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online