Johnsons algorithm is used to find the shortest path in a directed weighted graph. The weights in the graph can be negative. However, if all of the weights in the graph are already positive is it still necessary to run the Bellman-Ford step in Johnsons Algorithm? Could you jump directly to running Dijkstra’s Algorithm since there is no possibility of a negative weight cycle?
My initial answer was “In Johnsons algorithm, if all weights in a graph are positive we do not need to complete the bellman-ford step. Bellman-Ford is used to detect negative weight cycles, if all the weights in a graph are positive, there cannot be any negative weight cycles.” I was told that this was an incorrect answer to the problem by my professor. From what I understand there would be no need to run Bellman-Ford on a positive weighted graph, but I am unsure why my initial answer was incorrect. On a graph with all positive weights why wouldn’t you just run Dijkstra’s algorithm to find the all pairs shortest path?
JeremyM is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.