GATE Computer Science · Programming, Data Structures, and Algorithms · hard
Which two statements accurately compare Dijkstra's single-source shortest-path algorithm and the Bellman-Ford algorithm on a directed weighted graph G = (V, E)? (Select two.)
Published · Last updated · checked before publication — how we verify questions
Options
Answers: B. Dijkstra's greedy relaxation requires non-negative edge weights for correctness; D. Bellman-Ford handles negative edge weights and detects negative cycles in O(|V||E|)
Dijkstra's greedy relaxation assumes non-negative edge weights and can fail when negative-weight edges exist, whereas Bellman-Ford relaxes all |E| edges |V| - 1 times in O(|V||E|) time, correctly handles negative edge weights, and detects reachable negative-weight cycles on a |V|-th pass.
Why the other options are wrong
- A. Dijkstra's algorithm finds shortest paths even when negative-weight cycles exist — Shortest paths are undefined (-infinity) when a negative-weight cycle is reachable, and Dijkstra fails even on simple negative edges.
- C. Bellman-Ford runs in O(|V| + |E|) linear time on arbitrary dense graphs — Bellman-Ford relaxes |E| edges across |V| - 1 iterations, taking O(|V||E|) time.
More Programming, Data Structures, and Algorithms questions
All Programming, Data Structures, and Algorithms questions and the topic overview →
GATE is a mark of the Indian Institute of Science and the Indian Institutes of Technology. PrepIQ Hub is not affiliated with, endorsed by, or sponsored by the GATE Committee.