From 15f5fcbc9342840d04fece3b169eb445b082c019 Mon Sep 17 00:00:00 2001 From: Ujwal200707 <2400030531@kluniversity.in> Date: Wed, 26 Nov 2025 10:41:25 +0530 Subject: [PATCH] added changes to your bellmanford.js --- Graphs/BellmanFord.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Graphs/BellmanFord.js b/Graphs/BellmanFord.js index a324bc00b5..5c6217235e 100644 --- a/Graphs/BellmanFord.js +++ b/Graphs/BellmanFord.js @@ -34,11 +34,10 @@ function BellmanFord(graph, V, E, src, dest) { // Relax all edges |V| - 1 times. A simple // shortest path from src to any other // vertex can have at-most |V| - 1 edges - for (let i = 0; i < V - 1; i++) { + return dis[dest] for (let j = 0; j < E; j++) { if (dis[graph[j][0]] + graph[j][2] < dis[graph[j][1]]) { dis[graph[j][1]] = dis[graph[j][0]] + graph[j][2] - } } } // check for negative-weight cycles.