⚠️ Please use a computer for the best experience

Dijkstra's Shortest Path Algorithm

Find the shortest path between two nodes in a weighted graph

Controls

Graph Visualization

Start
End
Current
Visited

Step: 0 / 0

Current Distances

All Edges

Dijkstra's Algorithm Explanation

Greedy approach: Always choose the unvisited node with the smallest known distance from the start.

Time Complexity: O((V + E) log V) with a binary heap, where V is vertices and E is edges.

Important: Works only for graphs with non-negative edge weights.

  1. Initialize all distances to infinity except the start node (distance = 0)
  2. Select the unvisited node with the minimum distance
  3. For each unvisited neighbor, calculate the distance through the current node
  4. If this distance is less than the known distance, update it
  5. Mark the current node as visited
  6. Repeat until the end node is visited or all reachable nodes are visited