JavaScript icon indicating copy to clipboard operation
JavaScript copied to clipboard

added changes to your bellmanford.js

Open Ujwal200707 opened this issue 1 month ago • 0 comments

The change replaces the final loop with a direct return statement. Previously, the code looped through all vertices to find the destination and then returned its distance. This loop was unnecessary because the destination index is already known. By using:

return dis[dest]

the code becomes more efficient and readable. It removes redundant iterations, reduces time complexity for that part from O(V) to O(1), and makes the function cleaner without affecting the output.

Ujwal200707 avatar Nov 26 '25 05:11 Ujwal200707