UtilityToolsLab

© 2026 UtilityToolsLab. Built and maintained by the UtilityToolsLab Team.

Free eBooks·About·Changelog·Privacy Policy·Terms of Service·Report a bug
HomeCompetitive ProgrammingDijkstra Visualizer

Related Tools

Code FormatterMatrix GeneratorComplexity CalcBit VisualizerBitwise VisualizerBit ManipulationBitmask PlannerPrime FactorsMEX CalcInterval MergerMatrix RotationPBDS GeneratorSegment TreeGraph VisualizerStress TesterModulo CalcConvex HullPath FinderOffline JudgeBig-O AnalyzerCombinatoricsDP Table BuilderExtended GCDSieve VisualizerBinary SearchSorting VisualizerSparse Table RMQUnion-Find DSU

Dijkstra Shortest Path Visualizer

Step through Dijkstra's algorithm on your own weighted edge list: each heap pop, relaxation and stale entry, then every shortest path from the source.

You Might Also Like

All Competitive Programming

Code Formatter

Format and beautify C++, Java, and Python code with consistent indentation. 100% client-side — no code leaves your browser.

Matrix Generator

Generate grid/matrix inputs for competitive programming. Random, zeros, identity, or sequential fill. Outputs in multiple formats.

Complexity Calc

Estimate Big-O operations and runtime for any N. Interactive reference table for all complexity classes from O(1) to O(N!).

Bit Visualizer

Toggle 32/64-bit grids. Click bits to flip them live and see decimal recalculate. Shows popcountll, clzll, ctzll, and MSB instantly.

Most Dijkstra animations hide the part that trips people up in contests: the priority queue holds old, longer distances that have to be thrown away. This Dijkstra Shortest Path Visualizer runs the same lazy-deletion loop you would write with std::priority_queue and shows every pop, every relaxation and every stale entry it skips.

Paste a weighted edge list, pick a source, and step forward or press Play. The graph, the queue and the distance table move in lockstep, and the last step draws the shortest-path tree.

Worked Example: Five Nodes and Two Stale Entries

The tool opens on 0 1 4, 0 2 2, 1 3 5, 2 1 1, 2 3 8, 3 4 3, 4 0 7, read as a directed graph from node 0:

  • Node 0 settles first and pushes (4, 1) and (2, 2)
  • Node 2 settles at 2 and improves node 1 from 4 to 3, leaving (4, 1) behind in the queue
  • Node 1 settles at 3, then node 3 at 8; at that step the old (4, 1) is popped and discarded
  • Node 4 settles at 11 by way of 0 → 2 → 1 → 3 → 4, after the stale (10, 3) is skipped

Five settle steps, two stale pops. Switch to Undirected and node 4 drops to 7, because the edge 4 0 7 can now be walked backwards. Choose a node under Highlight path to to colour its route in the final step.

Algorithm: Lazy Deletion With a Binary Heap

Instead of decreasing a key inside the heap, each improvement pushes a new (distance, node) pair. When a pair comes off the top with a distance larger than the one already recorded, it is stale and skipped. That gives O((V + E) log V) with at most E pushes. Ties are broken by node label, so a run always replays the same way. Copy C++ Template gives the same loop as contest code, and Copy Distances exports every distance with its path.

Edge Cases: Negative Weights and Unreachable Nodes

A negative weight breaks the greedy step Dijkstra relies on, so the input is refused with a pointer to the right algorithm: “Line 2 has weight -2. Dijkstra's algorithm needs non-negative weights; use Bellman–Ford for graphs with negative edges.” Nodes the source cannot reach keep a distance of ∞ and are listed as unreachable. Duplicate edges and self-loops are allowed. The drawing handles up to 50 nodes and 300 edges, with labels from 0 to 9999 and weights up to one billion.

4251837001∞2∞3∞4∞
step 0 / 5

Start: dist[0] = 0, every other node is ∞, and the queue holds (0, 0).

queue: (0, 0)

Nodedist (now)prevShortest path (final)
00—0 (0)
1∞—0 → 2 → 1 (3)
2∞—0 → 2 (2)
3∞—0 → 2 → 1 → 3 (8)
4∞—0 → 2 → 1 → 3 → 4 (11)

Orange outline: source and the node being settled. Shaded: settled. At the last step, dark edges form the shortest-path tree. O((V + E) log V) with a binary heap.