Open meetme2meat opened 2 years ago
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.
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]