Shortest Path Algorithms Visualizer

Explore Dijkstra's algorithm with interactive weighted graph visualization

Graph Setup

Algorithm Controls

Graph Visualization

Nodes

0

Edges

0

Visited

0

Shortest Distance

-

Node Distances

No algorithm run yet. Select a source node and click "Start Dijkstra".

Shortest Path

No path computed yet. Select source and target nodes, then run the algorithm.

Help

What is Dijkstra's Algorithm?
  • Dijkstra's Algorithm: Finds shortest paths from a source node to all other nodes
  • Works on weighted graphs with non-negative edge weights
  • Uses a greedy approach, always selecting the unvisited node with smallest known distance
  • Maintains a priority queue of nodes to visit
  • Time complexity: O((V + E) log V) with binary heap
  • Guarantees optimal shortest paths for non-negative weights
How to Use
  • Add nodes by entering labels (A, B, C, etc.)
  • Connect nodes by selecting two nodes, entering a weight, and clicking Add Edge
  • All edges are undirected (bidirectional)
  • Select a source node (required) and optionally a target node
  • Use Start to animate or Step to advance manually
  • Current node is shown in red, visited nodes in light blue
  • The shortest path to target (if selected) is highlighted in green
  • Node distances are displayed on the graph and in the distances table
Algorithm Details
  • Initialization: Set source distance to 0, all others to infinity
  • Selection: Pick unvisited node with smallest distance
  • Relaxation: Update distances to neighbors if shorter path found
  • Repeat: Continue until all reachable nodes are visited
  • Path Reconstruction: Use parent pointers to trace shortest path
  • Yellow nodes are in the priority queue (to be visited)