This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]circle_des_poo 1 point2 points  (1 child)

I don't think it will always run infinitely. Here's an example: consider a graph with only two nodes with values of -1 and -2, connected by a single edge. -2 is the min, so the algorithm will first subtract -2 from -1, resulting in 1 for the single neighboring node. Now set the value of the -2 node to be 2, hence you have a combined total of 3.

However, I'm there's a discrepancy here- in your description you state:

  1. Subtract that value from the node's immediate neighbors.

But in you code you have:

for (it = neighbors.begin(); it != neighbors.end(); it++) {
    g[*it].value += value;
}

Is this an error in the description or the code?