Class ShortestPathAllPairsJohnson

java.lang.Object
com.jgalgo.alg.shortestpath.ShortestPathAllPairsAbstract
com.jgalgo.alg.shortestpath.ShortestPathAllPairsJohnson
All Implemented Interfaces:
ShortestPathAllPairs

public class ShortestPathAllPairsJohnson extends ShortestPathAllPairsAbstract
Johnson's algorithm for all pairs shortest path.

Calculate the shortest path between each pair of vertices in a graph in \(O(n m + n^2 \log n)\) time using \(O(n^2)\) space. Negative weights are supported.

The algorithm is faster than using ShortestPathSingleSourceBellmanFord \(n\) times, as it uses ShortestPathSingleSourceBellmanFord once to compute a potential for each vertex, resulting in an equivalent positive weight function, allowing us to use ShortestPathSingleSourceDijkstra from each vertex as a source.

Author:
Barak Ugav