Equilibrium's blog

By Equilibrium, 10 years ago, In English

Hey , I have a question about BellmanFord algorithm . As i have seen in pseudocodes they say for a u-v edge , we check if we can shorter the distance or not (if(Distance[u]+Weight[u-v]<Distance[v] then Distance[v]=Distance[u]+Weight[u-v]) but my question is when edges are bidirectional are we supposed to check for the other endpoint or one is enough ?

Thanks.

  • Vote: I like it
  • -1
  • Vote: I do not like it

»
10 years ago, # |
  Vote: I like it 0 Vote: I do not like it

I think it's enough to only check if (weight [u-v]> abs(distance (v)-distance (u)) is true or false If it was true there will be no need to update distance (v) or distance (u) But if it was false you need to update your distances