Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static double[] bellmanFord(List<Edge>[] graph, int V, int start) {
dist[start] = 0;

// For each vertex, apply relaxation for all the edges
for (int i = 0; i < V - 1; i++)
for (int i = 0; i <=V - 1; i++)
for (List<Edge> edges : graph)
for (Edge edge : edges)
if (dist[edge.from] + edge.cost < dist[edge.to])
Expand All @@ -63,7 +63,6 @@ public static double[] bellmanFord(List<Edge>[] graph, int V, int start) {
// Run algorithm a second time to detect which nodes are part
// of a negative cycle. A negative cycle has occurred if we
// can find a better path beyond the optimal solution.
for (int i = 0; i < V - 1; i++)
for (List<Edge> edges : graph)
for (Edge edge : edges)
if (dist[edge.from] + edge.cost < dist[edge.to]) dist[edge.to] = Double.NEGATIVE_INFINITY;
Expand Down