Question
// Develop an API and implementation that use a version of Dijkstras algorithm // to solve the source-sink shortest path problem on edge-weighted digraphs. public
// Develop an API and implementation that use a version of Dijkstras algorithm // to solve the source-sink shortest path problem on edge-weighted digraphs.
public class hw5
{
public class DijkstraSPSourceSink
{
private DirectedEdge[] edgeTo; // last edge on path to vertex
private double[] distTo; // length of path to vertex
private IndexMinPQ minPQ;
private int target;
private int source;
// This function should compute the shortest path from the // input source s to target t on the edge-weighted directed graph
public DijkstraSPSourceSink(EdgeWeightedDigraph G, int s, int t)
{
edgeTo = new DirectedEdge[G.V()];
distTo = new double[G.V()];
minPQ = new IndexMinPQ<>(G.V());
this.source = s;
this.target = t;
// initialize distances to vertices
for(int v = 0; v < G.V(); v++)
{
distTo[v] = Double.POSITIVE_INFINITY;
}
// TODO
}
private void relax(EdgeWeightedDigraph G, int v)
{
// TODO
} public double distToTarget()
{
// TODO
return 0.0;
}
public boolean hasPathToTarget()
{
// TODO
return false;
}
public Iterable pathToTarget()
{
Stack path = new Stack<>();
if ( hasPathToTarget() )
{
// TODO
}
return path;
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started