We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Dijkstra's Algorithm

Edsger Dijkstra, a legendary OG programmer, created Dijkstra's algorithm in the 1950s. It traverses a graph to find the shortest path between a source and a destination.

Click to play video

  • The algorithm tracks the "shortest distance so far" as it goes, updating as it finds shorter paths.
  • Once all of a node's neighbors have been checked and their distances have been updated, it's marked "visited."
  • At each step, the algorithm moves to the nearest (by total path length) unvisited neighbor.
  • This continues until the destination node is reached and its shortest path is determined.
  • Dijkstra's algorithm always returns the shortest path, not just a "good" one.