I've looked at the implementation of dijkstra's algorithm found here , but it seems to work fine for negative weights.
Specifically, the relax method updates the vertex's distance in the priority queue or inserts it back in if it wasn't originally in the queue.
And since there aren't any checks to make sure we don't reinsert an already known vertex, wouldn't this implementation be more like a bellman-ford algorithm where we keep inserting vertices to visit and relax until run out of edges that reduce distance?
For example:
When running it on the image below with A as the source, we first determine the following distances:
C = 0
B = 1
D = 99
Then after our queue removals, we are left with (D, 99), which makes us visit vertex D and relax it. When relaxing vertex D, we find that (D to B = -300), which makes the distance to B to be -201. Now using the "relax" method above, we reinsert (B, -201) back in the queue. Now we take the min of the queue which is the (B, -201) that we just inserted. From this, we relax B and we can get the distance to C to be -200.
I know that any negative cycle will make the program not terminate, but what if we are given a graph with no negative cycle? Hopefully I'm not missing anything trivial here. Thanks for any help!