Upcoming SlideShare
×

Like this presentation? Why not share!

chapter24.ppt

on Feb 07, 2010

• 1,755 views

Views

Total Views
1,755
Views on SlideShare
1,755
Embed Views
0

Likes
0
32
0

No embeds

Report content

• Comment goes here.
Are you sure you want to

chapter24.pptPresentation Transcript

• Introduction to Algorithms Second Edition by Cormen, Leiserson, Rivest & Stein Chapter 24
• 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:
• Single-Source Shortest Path We define the shortest-path weight from u to v by
• 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.
• 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.
• 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.
• 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.
• Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
• Single-Source Shortest Path Shortest paths are not necessarily unique.
• Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
• Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
• 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 ].
• Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
• Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
• Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
• Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
• Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
• 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.
• 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.
• Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
• Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
• 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.
• 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 .
• Dijkstra’s Algorithm
• In the implementation, we are using a min-priority queue Q of vertices, keyed by their d values.
• Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
• Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.