1. Home
  2. Computer Science MCQs
  3. Algorithms and Data Structures
  4. Which algorithm solves the all-pairs shortest path problem…

Added 12 Sep 2025

Which algorithm solves the all-pairs shortest path problem for graphs with negative weight edges?

  1. Dijkstra's Algorithm
  2. Bellman-Ford Algorithm
  3. Floyd-Warshall Algorithm
  4. Johnson's Algorithm Correct answer

Correct answer

D. Johnson's Algorithm

18 views

MCQSEXAM

Explanation

Johnson's algorithm reweights edges using Bellman-Ford and then runs Dijkstra from every vertex, solving all-pairs shortest paths with negative edge weights (no negative cycles) efficiently. Bellman-Ford alone is a single-source algorithm.

Reference

Asked in: GATE CS, UGC NET CS

https://www.geeksforgeeks.org/bellman-ford-algorithm-dp-23/

Preparing for an exam?

Doubts & discussion

Not sure why the answer is D? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More Algorithms and Data Structures MCQs

Practise all Algorithms and Data Structures MCQs

Similar MCQs