Data Structures & AlgorithmsVery hardGATE CS · TCS NQT · Product Company SDE

A directed weighted graph has edges A→B:3, A→C:5, B→D:5, D→E:9, A→D:5, C→E:-2 (some weights are negative, but there is no negative-weight cycle). Using Bellman-Ford from A, what is the shortest-path distance to E?

  1. A. 3
  2. B. 2
  3. C. 5
  4. D. 4

Correct answer: A. 3

Relax all edges |V|-1 times from A: A=0, B=3, C=5, D=5, E=3. Dijkstra cannot be used safely here because of the negative edge.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic