Skip to main content
Tweeted twitter.com/#!/StackCompSci/status/282574920645476352
made briefer, clearer; formatted; linked; latexified; changed title
Link

Bellman ford-Ford algorithm, does it matter if I take different series of - Why can edges when updating the costbe updated out of the vertexorder?

made briefer, clearer; formatted; linked; latexified;
Source Link

In Bellman ford algorithmThe , one has to findBellman-Ford algorithm determines the shortest partpath from all vertex to a source vertex s$s$ to all other vertices. Initially the distance between $s$ and all other vertices beside s is madeset to infinity$\infty$. Then each nodethe shortest path from s is calculated and least distance$s$ to each vertex is computed,computed; this goes on for upto V-1 times $|V|-1$ iterations. My questions are:

  • Why does there need to be $|V|-1$ iterations?
  • Would it matter if I checked the edges in a different order?
    Say, if I first check edges 1,2,3, but then on the second iteration I check 2,3,1.

My question is first why is it upto V-1 times and my second question is would it matter if I did not check the edges in the order so say suppose I check edge 1,2,3 then second iteration I check 2,3,1 . I was watching a mit video and profMIT Prof.Eric Eric said that it did notthe order didn't matter, which is a bit confusing say suppose Ibut this confuses me: wouldn't the algorithm incorrectly update a node based on edge x whose$x_2$ if its value could have beenwas dependent on the next edge x2$x_1$ but because the second time I updated some other say suppose x2, the node did not increase the value as it$x_1$ is supposed to.updated after $x_2$?

In Bellman ford algorithm , one has to find the shortest part from all vertex to a source vertex s. Initially all vertices beside s is made to infinity. Then each node from s is calculated and least distance is computed, this goes on for upto V-1 times.

My question is first why is it upto V-1 times and my second question is would it matter if I did not check the edges in the order so say suppose I check edge 1,2,3 then second iteration I check 2,3,1 . I was watching a mit video and prof.Eric said that it did not matter, which is a bit confusing say suppose I update a node based on edge x whose value could have been dependent on the next edge x2 but because the second time I updated some other say suppose x2, the node did not increase the value as it is supposed to.

The Bellman-Ford algorithm determines the shortest path from a source $s$ to all other vertices. Initially the distance between $s$ and all other vertices is set to $\infty$. Then the shortest path from $s$ to each vertex is computed; this goes on for $|V|-1$ iterations. My questions are:

  • Why does there need to be $|V|-1$ iterations?
  • Would it matter if I checked the edges in a different order?
    Say, if I first check edges 1,2,3, but then on the second iteration I check 2,3,1.

MIT Prof. Eric said the order didn't matter, but this confuses me: wouldn't the algorithm incorrectly update a node based on edge $x_2$ if its value was dependent on the edge $x_1$ but $x_1$ is updated after $x_2$?

Source Link
user1675999
  • 1k
  • 7
  • 16
  • 23

Bellman ford algorithm, does it matter if I take different series of edges when updating the cost of the vertex

In Bellman ford algorithm , one has to find the shortest part from all vertex to a source vertex s. Initially all vertices beside s is made to infinity. Then each node from s is calculated and least distance is computed, this goes on for upto V-1 times.

My question is first why is it upto V-1 times and my second question is would it matter if I did not check the edges in the order so say suppose I check edge 1,2,3 then second iteration I check 2,3,1 . I was watching a mit video and prof.Eric said that it did not matter, which is a bit confusing say suppose I update a node based on edge x whose value could have been dependent on the next edge x2 but because the second time I updated some other say suppose x2, the node did not increase the value as it is supposed to.