Dijkstra's Algorithm


Created by Edsger W. Dijkstra in 1956. It was the default shortest pathfinding algorithm for games until A* came along in 1968. A* was essentially an extension of Dijsktra's algorithm with the addition of a heuristic. However, it continues to be widely used by routers in their routing protocols to update their forwarding tables by finding the shortest cost path from the source router to the rest of the routers in the network. This allows you to figure out how which routers and in which order to send a given data packet through to achieve the highest efficiency. With a min priority queue, the time complexity of Dijkstra's Algorithm is Θ(V + E logV).

Psuedocode

  1. function Dijkstra(Graph, Source):

  2. for each vertex V in Graph

  3. distance[V] <- infinite

  4. previous[V] <- NULL

  5. If V != Source, add V to Priority Queue Q

  6. distance[Source] <- 0

  7. while Q IS NOT EMPTY

  8. U <- Extract MIN from Q

  9. for each unvisited neighbour V of U

  10. tempDistance <- distance[U] + edge_weight(U, V)

  11. if tempDistance < distance[V]

  12. distance[V] <- tempDistance

  13. previous[V] <- U

  14. return distance[], previous[]

Sources:

  1. Pathfinding Algorithms in Game Development
  2. Dijkstra's Algorithm - Computerphile
  3. Dijkstra's Algorithm GIF
  4. Psuedocode for Dijkstra's Algorithm