Bellman Ford and One Olympiad Questions?

后端 未结 2 1773
梦如初夏
梦如初夏 2021-02-19 09:01

I took an Olympiad Exam three days ago. I ran into a nice question as follows.

We know the bellman-ford algorithm checks all edges in each step, and for each edge if,

相关标签:
2条回答
  • 2021-02-19 09:25

    1 is incorrect. First of all, we always find shortest paths with k edges, if any. But also, if we happen to relax the arcs in the topological order of a shortest path tree, then we converge in one iteration, despite the fact that the shortest path tree may be arbitrarily deep.

    s --> t --> u --> v
    
    Relax s->t, t->u, u->v; shortest path from s->v is three hops,
    but B--F has made two iterations.
    

    2 is incorrect, because who knows what the weights are?

      100
    s --> t
    
    Relax s->t; weight is 100, but B--F has made two iterations.
    

    3 is correct, because by an averaging argument at least one arc of a negative cycle would be unrelaxed. Let v1, ..., vn be a cycle. Since the arcs are relaxed, we have d(vi) + len(vi->vi+1) - d(vi+1) >= 0. Sum the inequalities for all i and telescope the d terms to simplify to sum_i len(vi->vi+1) >= 0, which says that the cycle is nonnegative.

    0 讨论(0)
  • 2021-02-19 09:39

    i think option 3 is incorrect because to know if there is negative weight cycle ,the Bellman ford algorithm needs to run n times. first n-1 times to calculate the shortest path and then one more time to check if there is any improvement in the distances if there are improvements ,it means there is a negative weight cycle.

    0 讨论(0)
提交回复
热议问题