You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
why do we need to check for negative cycle n-1 times again? Can we just loop over the edges to see if distance is decreasing and detect negative cycle?
Having int i = 0; i < V - 1; ++i will take into account the initial state, that is to say 0, so why would we need to reach the termination state fully at V - 1 since we are starting at 0 (first iteration)? Having your proposed change <= will result in the terminating state to go one above the original i < V - 1 making the end state V not the required V - 1. Hope that helps
If I understand the algorithm correctly, since we need to do relaxation n-1 times shouldn't the loop run from i=0; i<=V-1 ?
Algorithms/src/main/java/com/williamfiset/algorithms/graphtheory/BellmanFordAdjacencyList.java
Line 57 in 65dcc1b
why do we need to check for negative cycle n-1 times again? Can we just loop over the edges to see if distance is decreasing and detect negative cycle?
Algorithms/src/main/java/com/williamfiset/algorithms/graphtheory/BellmanFordAdjacencyList.java
Line 66 in 65dcc1b
The text was updated successfully, but these errors were encountered: