Your SlideShare is downloading. ×
chapter24.ppt
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

chapter24.ppt

1,794
views

Published on


0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,794
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
38
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Introduction to Algorithms Second Edition by Cormen, Leiserson, Rivest & Stein Chapter 24
  • 2. Single-Source Shortest Path In a shortest-paths problem , we are given a weighted, directed graph G = ( V , E ), with weight function w : E -> R mapping edges to real-valued-weights. The weight of path p = v 0, v 1, ..., vk is the sum of the weights of its constituent edges:
  • 3. Single-Source Shortest Path We define the shortest-path weight from u to v by
  • 4. Variant of Single-Source Shortest Path Single-destination shortest-paths problem: Find a shortest path to a given destination vertex t from each vertex v . By reversing the direction of each edge in the graph, we can reduce this problem to a single-source problem.
  • 5. Variant of Single-Source Shortest Path Single-pair shortest-path problem: Find a shortest path from u to v for given vertices u and v . If we solve the single-source problem with source vertex u , we solve this problem also.
  • 6. Variant of Single-Source Shortest Path All-pairs shortest-paths problem: Find a shortest path from u to v for every pair of vertices u and v . This problem can be solved by running a single-source algorithm once from each vertex.
  • 7. Single-Source Shortest Path Negative weight edges: If the graph G = ( V , E ) contains no negative-weight cycles reachable from the source s , then for all v ε V , the shortest-path weight δ ( s , v ) remains well defined, even if it has a negative value.
  • 8. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
  • 9. Single-Source Shortest Path Shortest paths are not necessarily unique.
  • 10. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
  • 11. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
  • 12. Single-Source Shortest Path The process of relaxing an edge ( u , v ) consists of testing whether we can improve the shortest path to v found so far by going through u and, if so, updating d [ v ] and π[ v ].
  • 13. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
  • 14. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
  • 15. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
  • 16. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
  • 17. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
  • 18. Single-Source Shortest Path in Directed Acyclic Graphs
    • The algorithm starts by topologically sorting the dag to impose a linear ordering on the vertices.
    • If there is a path from vertex u to vertex v , then u precedes v in the topological sort.
  • 19. Single-Source Shortest Path in Directed Acyclic Graphs
    • We make just one pass over the vertices in the topologically sorted order.
    • As we process each vertex, we relax each edge that leaves the vertex.
  • 20. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
  • 21. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
  • 22. Dijkstra’s Algorithm
    • Dijkstra's algorithm solves the single-source shortest-paths problem on a weighted, directed graph G = ( V , E ) for the case in which all edge weights are nonnegative.
  • 23. Dijkstra’s Algorithm
    • The algorithm repeatedly selects the vertex u є V - S
    • with the minimum shortest-path estimate, adds u to S , and relaxes all edges leaving u .
  • 24. Dijkstra’s Algorithm
    • In the implementation, we are using a min-priority queue Q of vertices, keyed by their d values.
  • 25. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
  • 26. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.