Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relaxation in Bellman Ford #316

Open
choprasaurav7 opened this issue Jul 16, 2022 · 1 comment
Open

Relaxation in Bellman Ford #316

choprasaurav7 opened this issue Jul 16, 2022 · 1 comment

Comments

@choprasaurav7
Copy link

choprasaurav7 commented Jul 16, 2022

  1. 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 ?

  2. 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?

@josephAttia
Copy link

@choprasaurav7

  1. 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants