{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

17 Graphs Part 3

# 17 Graphs Part 3 - Graph Algorithms part 3 15-211...

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

Graph Algorithms, part 3 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller 23 March 2010 Reading for today: Chapter 14

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

View Full Document
Announcements Homework 6 is available Theory due Tuesday, April 6 in class Programming due Thursday, April 8 11:59pm Reading: Weiss Chapter 14 2
Last time … Topological Sorting c d a f g b e NOT YET VISITED BEING VISITED NOW DONE VISITING f g Step: 8 3 8 g d c e a Stack 3

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

View Full Document
Last time … Topological Sorting c d a f g b e NOT YET VISITED BEING VISITED NOW DONE VISITING f g d c e a b Step: 14 3 8 9 10 11 12 14 Notice these are monotonically decreasing b Stack
The correctness of toposort Let G=(V,E) be a DAG and (u,v) 2 E. We must show that u was added to the head of the list after v was added (and thus appears in front of v in the list). Intuition: During the recursive call on u what colors can v be? Not GREY, or we’d have a cycle (and it’s a DAG). Black: Then v is already on list. White (green): The algorithm will make a recursive call on v; When the the recursive call finishes (backtracks), it will put v on the list. But the recursive call on u has not completed. Therefore u will be put on the head of the list after v was added.

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

View Full Document
Today: More graph algorithms Shortest paths Preliminaries… BFS for unweighted graphs Single source weighted paths Dijkstra’s algorithm for weighted graphs without negative weights Weighted graphs without negative cycles img sources: Google Maps and Discover magazine
Single-Source Shortest Paths 7

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

View Full Document
Airline routes PVD BOS JFK ORD LAX SFO DFW BWI MIA 337 2704 1846 1464 1235 2342 802 867 849 740 187 144 1391 184 1121 946 1090 1258 621 8
Shortest path Suppose we live in Baltimore (BWI) and want the shortest path to San Francisco (SFO). 9

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

View Full Document
Many applications Shortest paths model many useful real- world problems. Minimization of latency in the Internet. Minimization of cost in power delivery. Job and resource scheduling. Route planning. Counting change for large denominations. (!?) 10
Distance in a graph Let G(V,E) be a directed graph with edge weights W. Definition : The cost of a path P = v 0 ,v 1 …,v k-1 ,v k is the sum of the weights of its edges. Confusion alert: the length of a path P is the number of edges in P We define the δ (s,v) as cost of shortest path from s to v. If no such path exits δ (s, v) = 11

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

View Full Document
Brute Force A path is simple if it contains any vertex at most once. Note that there are only finitely many simple paths (even if there are cycles in the graph). Enumerate all simple paths starting at s. Collect all simple paths with target t. Compute their cost, determine the min. 12
Brute force: bad idea Even in an acyclic graph, the number of simple paths may be exponential in n. Exercise: determine the number of paths s to t.

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.

{[ snackBarMessage ]}

### Page1 / 82

17 Graphs Part 3 - Graph Algorithms part 3 15-211...

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

View Full Document
Ask a homework question - tutors are online