public class DijkstraAllPairsSP extends Object
This implementation runs Dijkstra's algorithm from each vertex. The constructor takes time proportional to V (E log V) and uses space proprtional to V2, where V is the number of vertices and E is the number of edges. Afterwards, the dist() and hasPath() methods take constant time and the path() method takes time proportional to the number of edges in the shortest path returned.
For additional documentation, see Section 4.4 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.
| Constructor and Description |
|---|
DijkstraAllPairsSP(EdgeWeightedDigraph G)
Computes a shortest paths tree from each vertex to to every other vertex in
the edge-weighted digraph G.
|
| Modifier and Type | Method and Description |
|---|---|
double |
dist(int s,
int t)
Returns the length of a shortest path from vertex s to vertex t.
|
boolean |
hasPath(int s,
int t)
Is there a path from the vertex s to vertex t?
|
Iterable<DirectedEdge> |
path(int s,
int t)
Returns a shortest path from vertex s to vertex t.
|
public DijkstraAllPairsSP(EdgeWeightedDigraph G)
G - the edge-weighted digraphIllegalArgumentException - if an edge weight is negativeIllegalArgumentException - unless 0 ≤ s ≤ V - 1public Iterable<DirectedEdge> path(int s, int t)
s - the source vertext - the destination vertexpublic boolean hasPath(int s,
int t)
s - the source vertext - the destination vertexpublic double dist(int s,
int t)
s - the source vertext - the destination vertexCopyright © 2014. All Rights Reserved.