edited by
247 views
2 votes
2 votes

Let $G(V, E)$ be an undirected graph with some edge weights being negative but without any negative weight cycle. Which of the following is/are TRUE when $G$ is given as input with a given source $s$? (Mark all the appropriate choices)

  1. Dijkstra's algorithm will always correctly output the shortest path to all vertices from $s$
  2. Dijkstra's algorithm will always fail to correctly output the shortest path to all vertices from $s$
  3. Bellman-Ford algorithm will always correctly output the shortest path to all vertices from $s$
  4. Bellman-Ford algorithm will always fail to correctly output the shortest path to all vertices from $s$
edited by

1 Answer

Best answer
2 votes
2 votes
Dijkstra's algorithm is not designed to work for graphs with negative edges. Still, for some graphs with negative edges, it can output the correct shortest path - the cut edges being the only negative edges is an example. So, options A and B are false.
    
    Bellman-Ford algorithm will always output the correct shortest path even when the edge weights are negative as long as there is no negative weighted cycle reachable from source.
selected by
Answer:

Related questions

4 votes
4 votes
1 answer
1