Newest Viewed Downloaded

Single Source Single DestinationTerminate single source all destinations greedy algorithm as soon as shortest path to desired vertex has been generated.

Shortest Path Problems Directed weighted graph. Path length is sum of weights of edges on path. The vertex at which the path begins is the source vertex. The vertex at which the path ends is the destination vertex.

Example

1 2 3 4 5 6 7 2 6 16 7 8 10 3 14 4 4 5 3 1 1 7 Path length is 14. A path from 1 to 7.

Example

1 2 3 4 5 6 7 2 6 16 7 8 10 3 14 4 4 5 3 1 Path length is 11. Another path from 1 to 7.

Shortest Path Problems Single source single destination. Single source all destinations. All pairs (every vertex is a source and destination).

Single Source Single Destination

Possible greedy algorithm: Leave source vertex using cheapest/shortest edge. Leave new vertex using cheapest edge subject to the constraint that a new vertex is reached. Continue until destination is reached.

Greedy Shortest 1 To 7 Path

1 2 3 4 5 6 7 2 6 16 7 8 10 3 14 4 4 5 3 1 Path length is 12. Not shortest path. Algorithm doesn’t work!

Single Source All Destinations

Need to generate up to n (n is number of vertices) paths (including path from source to itself). Greedy method: Construct these up to n paths in order of increasing length. Assume edge costs (lengths) are >= 0. So, no path has length < 0. First shortest path is from the source vertex to itself. The length of this path is 0. The solution to the problem consists of up to n paths. The greedy method suggests building these n paths in order of increasing length. First build the shortest of the up to n paths (I.e., the path to the nearest destination). Then build the second shortest path, and so on.

Greedy Single Source All Destinations

1 2 3 4 5 6 7 2 6 16 7 8 10 3 14 4 4 5 3 1 Path Length 1 0 1 3 2 1 3 5 5 1 2 6 1 3 9 5 4 1 3 10 6 1 3 11 6 7

Greedy Single Source All Destinations

Path Length 1 0 1 3 2 1 3 5 5 1 2 6 1 3 9 5 4 1 3 10 6 1 3 11 6 7 Each path (other than first) is a one edge extension of a previous path. Next shortest path is the shortest one edge extension of an already generated shortest path.

Greedy Single Source All Destinations

Let d(i) (distanceFromSource(i)) be the length of a shortest one edge extension of an already generated shortest path, the one edge extension ends at vertex i. The next shortest path is to an as yet unreached vertex for which the d() value is least. Let p(i) (predecessor(i)) be the vertex just before vertex i on the shortest one edge extension to i.

Greedy Single Source All Destinations

1 2 3 4 5 6 7 2 6 16 7 8 10 3 14 4 4 5 3 1 [1] [2] [3] [4] [5] [6] [7] d p 0 - 1 2 3 4 7 6 1 2 1 16 1 - - - - 14 1 2

Greedy Single Source All Destinations

1 2 3 4 5 6 7 2 6 16 7 8 10 3 14 4 4 5 3 1 [1] [2] [3] [4] [5] [6] [7] d p 1 0 - 6 1 2 1 16 1 - - - - 14 1 1 3 2 5 6 5 3 10 3 5

Greedy Single Source All Destinations

1 2 3 4 5 6 7 2 6 16 7 8 10 3 14 4 4 5 3 1 [1] [2] [3] [4] [5] [6] [7] d p 1 0 - 6 1 2 1 16 1 - - - - 14 1 1 3 5 3 10 3 1 3 5 4 7 9 5 6

Greedy Single Source All Destinations

1 2 3 4 5 6 7 2 6 16 7 8 10 3 14 4 4 5 3 1 [1] [2] [3] [4] [5] [6] [7] d p 1 0 - 6 1 2 1 9 5 - - - - 14 1 1 3 5 3 10 3 1 3 5 1 2 4 9

Greedy Single Source All Destinations

1 2 3 4 5 6 7 2 6 16 7 8 10 3 14 4 4 5 3 1 [1] [2] [3] [4] [5] [6] [7] d p 1 0 - 6 1 2 1 9 5 - - - - 14 1 1 3 5 3 10 3 1 3 5 1 2 1 3 5 4 7 12 4 10

Greedy Single Source All Destinations

1 2 3 4 5 6 7 2 6 16 7 8 10 3 14 4 4 5 3 1 [1] [2] [3] [4] [5] [6] [7] d p 0 - 6 1 2 1 9 5 - - - - 14 1 5 3 10 3 12 4 1 3 6 7 11 6

Greedy Single Source All Destinations

Path 1 0 1 3 2 1 3 5 5 1 2 6 1 3 9 5 4 1 3 10 6 1 3 11 6 7 Length [1] [2] [3] [4] [5] [6] [7] 0 - 6 1 2 1 9 5 - - - - 14 1 5 3 10 3 12 4 11 6

Single Source Single Destination

Terminate single source all destinations greedy algorithm as soon as shortest path to desired vertex has been generated.

Data Structures For Dijkstra’s Algorithm

The greedy single source all destinations algorithm is known as Dijkstra’s algorithm. Implement d() and p() as 1D arrays. Keep a linear list L of reachable vertices to which shortest path is yet to be generated. Select and remove vertex v in L that has smallest d() value. Update d() and p() values of vertices adjacent to v.

Complexity

O(n) to select next destination vertex. O(out-degree) to update d() and p() values when adjacency lists are used. O(n) to update d() and p() values when adjacency matrix is used. Selection and update done once for each vertex to which a shortest path is found. Total time is O(n2 + e) = O(n2).

Showing 1 - 20 of 21 items Details

Name: 
chap13-1
Author: 
Preferred Customer
Company: 
N/A
Description: 
Single Source Single DestinationTerminate single source all destinations greedy algorithm as soon as shortest path to desired vertex has been generated.
Tags: 
path | source | single | the | vertex | shortest | all | greedy
Created: 
6/17/1995 11:31:02 PM
Slides: 
21
Views: 
1
Downloads: 
0
Rating: 
0


> Comment



Share this presentation
|

Comments

Share this presentation:

|
Sitemap