cse101_11_4_11 - First the node closest to s (ie. S itself)...

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

View Full Document Right Arrow Icon
Shortest paths in graphs 1. Breadth-first search a. Given a graph G = (V,E) and a node S in V, BFS finds distances from s to all other nodes. (If node is not reachable from s, distance = infinity) b. Time O(V + E), linear c. Strategy: Identify nodes at dist 0 (just s) Then dist 1 Then dist 2 … and so on. d. Problem: BFS treats all edges as having the same length. This is rarely true in shortest paths applications. Ex. How to drive from SD to SF? Edge lengths could denote: Physical distance Time taken Amount of gas Or any other quantity we wish to conserve. Assume each edge e in E now has a length l(e). e. To find shortest paths when the edge lengths are positive we can use dijkstra’s algorithm. A common implementation of Dijkstra takes time O((V+E) log (V)), not too much worse than linear 2. Dijkstra’s algorithm a. Given: graph G = (V,E) Edge lengths l€ > 0 Starting node S in V Find distances from S to all other nodes b. Strategy: finalize distances to other nodes in increasing order of distance from S.
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: First the node closest to s (ie. S itself) Then the second closest Then third closest c. Example Graph with nondirected edges with a value for the edge, take shortest paths Add up the distances along the way S A B C D E F I I I I I I 0 2 6 I I I I 0 2 6 3 I I I 4 6 8 I 5 8 I 7 I 8 d. Why does this work? Suppose we have identified the k closest nodes to S, with correct distance values Distance estimate to u === length of shortest path to u using only the k closest nodes >= length of shortest path to u. Say w is the (k+1) st closest node. The shortest path to it uses only the k closest nodes. Therefore, estimate for w is correct, and w will be finalized next. e. Dijkstras algorithm For all u in V Dist[u] = infinity Dist[s] = 0 H =V (nodes to which distance is not yet finalized) While H is not empty 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) f....
View Full Document

This note was uploaded on 01/09/2012 for the course CSE 101 taught by Professor Staff during the Spring '08 term at UCSD.

Page1 / 2

cse101_11_4_11 - First the node closest to s (ie. S itself)...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online