Algorithms icon indicating copy to clipboard operation
Algorithms copied to clipboard

Update the for loop to run V-1 times

Open meetme2meat opened this issue 4 years ago • 1 comments
trafficstars

The following code change in the following dist array from this

[0.0, 1.0, -Infinity, -Infinity, -Infinity, 5.0, 5.0, 8.0, Infinity]

to this

[0.0, 1.0, -Infinity, -Infinity, -Infinity, 5.0, 5.0, 8.0]

meetme2meat avatar Oct 26 '21 11:10 meetme2meat

Supposed the number of vertices is V = 3, then we want to iterate V-1 = 2 times for bellman ford.

With the clause i=0; i <= V-1; i++ that would include indeces i=0, i=1, and i=2 for a total of 3 iterations, not 2.

williamfiset avatar Nov 30 '21 02:11 williamfiset