I have a question which I was asked in some past exams at my school and I can't find an answer to it.
Is it possible knowing the final matrix after running the Johnson Algorithm on a graph, to know if it previously had negative cycles or not? Why?
Johnson Algorithm
Johnson's Algorithm is a technique that is able to compute shortest paths on graphs. Which is able to handle negative weights on edges, as long as there does not exist a cycle with negative weight.
The algorithm consists of (from Wikipedia):
- First, a new node
qis added to the graph, connected by zero-weight edges to each of the other nodes. - Second, the Bellman–Ford algorithm is used, starting from the new vertex
q, to find for each vertexvthe minimum weighth(v)of a path fromqtov. If this step detects a negative cycle, the algorithm is terminated. - Next the edges of the original graph are reweighted using the values computed by the Bellman–Ford algorithm: an edge from
utov, having lengthw(u, v), is given the new lengthw(u,v) + h(u) − h(v). - Finally,
qis removed, and Dijkstra's algorithm is used to find the shortest paths from each nodesto every other vertex in the reweighted graph.

