Dijkstra Algorithm Visualizer

Paste weighted graph edges, choose a start and target node, then step through Dijkstra distance updates until the shortest path is highlighted.

Nodes
6
Edges
9
Step
1/17
Distance
unreached

Weighted graph input

Use one non-negative weighted edge per line: source, target, weight.

Step controls

Start at A. Its distance is 0.

Weighted graph diagram

Green marks the current target path. Blue marks the latest relaxed edge.

Visited Current
Dijkstra graph diagramWeighted graph with 6 nodes and 9 edges.4215810263Ad=0Bd=unreachedCd=unreachedDd=unreachedEd=unreachedFd=unreached

Distance table

NodeDistancePreviousStatus
A0-current
Bunreached-unvisited
Cunreached-unvisited
Dunreached-unvisited
Eunreached-unvisited
Funreached-unvisited

Shortest path output

No reachable target path is available at this step.

What is a Dijkstra Algorithm Visualizer?

A Dijkstra algorithm visualizer shows how shortest-path distances are updated in a weighted graph. It is useful for learning graph algorithms, route planning, priority queues, and coding interview shortest-path problems.

This tool lets you paste weighted edges, choose a start node and target node, then step through the distance table and shortest path.

For the full graph and data structure set, browse the Data Structure Visualizers hub.

How to use this Dijkstra visualizer

  • Paste one weighted edge per line, such as A B 4.
  • Choose whether edges are undirected or directed.
  • Enter a start node and optional target node.
  • Click Run Dijkstra.
  • Step through each visit and relaxation update.

Dijkstra works on graphs with non-negative edge weights. This tool ignores negative weights so the visualization stays faithful to the algorithm.

Dijkstra vs BFS

Breadth-first search finds shortest paths in an unweighted graph. Dijkstra extends the idea to weighted graphs by always expanding the unvisited node with the smallest known distance.

If you want to compare weighted and unweighted traversal, try the Graph BFS DFS Visualizer alongside this shortest-path tool. To compare Dijkstra-style search with a target heuristic on a grid, use the A Star Pathfinding Visualizer. For negative edges and negative cycle checks, use the Bellman Ford Visualizer. For component connectivity instead of shortest paths, use the Union Find Visualizer.

Frequently Asked Questions

What input format does the Dijkstra visualizer use?
Paste one edge per line with a source, target, and positive weight, such as `A B 4` or `A -> B 4`.
Can this Dijkstra tool use directed edges?
Yes. Turn on directed graph mode if each edge should only travel from the first node to the second node.
Why does Dijkstra need non-negative weights?
Dijkstra assumes that once the smallest unvisited distance is selected, it will not later become smaller through a negative edge. Negative weights break that assumption.
Does this tool show the shortest path?
Yes. When a target node is reachable, the tool highlights the shortest path and shows its total distance.

Related tools