VisuAlgo Single-Source Shortest Paths
Exploration ModeHome

Random Graph

Sample Graphs

BFS

Bellman Ford's Algo

Dijkstra's Algo

Positive Weights Only

With Negative Weights

CP3 4.3 (unweighted)

CP3 4.17

CP3 4.18 (negative weight)

CP3 4.19 (negative cycle)

GO

GO

Original

Modified

About Team Terms of use
slow
fast
go to beginning previous frame pause play next frame go to end
In the Single-Source Shortest Path (SSSP) problem, we aim to find the shortest paths from a particular start node to all other vertices in the graph (if they exist).

Different algorithms can be used depending on the nature of the graph, i.e. weighted/ unweighted, with/without negative weights/ cycles.
Next
Choose a sample graph and try running the different SSSP algorithms on it:

The O(V + E) Breadth-first search (only for unweighted graphs),
The general purpose O(VE) Bellman Ford's algorithm, or
The O((V + E) log V) Dijkstra's algorithm (only for graphs without negative weights/negative weight cycles)
Next
When the SSSP algorithm animation is running, the input graph will be shown on the left, and the SSSP spanning tree will be shown on the right with the corresponding distance information.
Next
The status bar explains the execution of the algorithm at each animation step.
Next
You can also follow the psuedocode highlights to trace the algorithm.
Next
Control the animation with the player controls! Keyboard shortcuts are:
Spacebar: play/pause/replay
Left/right arrows: step backward/step forward
-/+: decrease/increase speed
Next
Return to "Exploration Mode" to start exploring!