1 / 17

6.006- Introduction to Algorithms

6.006- Introduction to Algorithms. Lecture 15 Prof. Silvio Micali. Shortest Paths in a Graph . v 1. v 3. v 5. 4. –2. –5. 1. v 2. v 4. ( p ) = –2. length of edge length of path Given a “source” path from to with You can get from to in length distance from to

enrico
Download Presentation

6.006- Introduction to Algorithms

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 6.006- Introduction to Algorithms Lecture15 Prof. Silvio Micali

  2. Shortest Paths in a Graph v1 v3 v5 4 –2 –5 1 v2 v4 (p) = –2 • length of edge • length of path • Given a “source” • path from to with • You can get from to in length • distance from to • Length of a shortest path from to a

  3. Recall: Dijstra’s Algorithm Distances from when

  4. 8 9 13 9 4 T 4 6 5 5 8 3 2 9 4 3 4 P 7 0

  5. Today: Shortest Paths (from ) in Digraphs with General Edge Length Makes sense when G has no negative cycles!

  6. Notation • length of edge • length of path • Given a “source” • path from to with • distance from to • predecessor of on a best path so far • (initially, and

  7. d[s] 0 • π[s] s • for each vÎV – {s} • dod[v] ¥ • π[v]  nil initialization while there is an edge (u, v) ÎEs.t. d[v] > d[u] + (u, v) do selectarbitrarily one such edge set d[v] d[u] + (u, v) π[v] u endwhile Relaxation (Improvement) Step A generic start

  8. Of course, it will not stop when negative cycles exist

  9. What if no negative cycle .... 4 2 1 v1 4 v2 4 v3 2 v4 2 v5 1 v6 1 v7 8 10 12 13 14 4 13 10 11 12 11 4 6 8 9 10 9 6 7 8 7

  10. What if no negative cycle .... 4 2 1 v1 4 v2 4 v3 2 v4 2 v5 1 v6 1 v7 Analysis = # of relaxations number of vertices Need to be carefulhow you relax!

  11. HOW? (Bellman Ford) • Arbitrarily fix an ordering of the edges: Until no improvement found do: IFis such that PASS Then Cost of one PASS = How many PASSES ?

  12. Let this be shortest path from to 4 -7 +3 -2 19 0 4 -3 0 -2 17 1st Pass 2nd Pass 3rd Pass 4th Pass 5th Pass Ford’s Total Complexity = And if G=(V,E) had cycles?

  13. Take Homes

  14. Optimal substructure Theorem. A subpath of a shortest path is a shortest path. Proof. By contradiction ...

  15. Proof. d(u, v) u v d(u, x) d(x, v) x Triangle inequality Theorem. For all u, v, xÎV, we have d(u, v) £d(u, x) +d(x, v).

  16. Combinatorics vs. Combinatorial Optimization v1 s vn v2 …

  17. “See you latersalligaters”

More Related