This page is about Dijkstra's Algorithm, a famous path-finding algorithm!
Dijkstra's algorithm finds the shortest path from a source node to another given node in a graph.
1| def dijkstra(v):
2| pq = new PriorityQueue()
3| pq.insert([dest: v, pred: null, cost: 0])
4| while (!pq.isEmpty()):
5| [dest, pred, cost] = pq.removeMin()
6| if dest is unvisited:
8| mark dest visited
9| store pred and cost for dest
10| for weight (w) in edges to destination (u) neighbor:
11| pq.insert([u, dest, cost + w])
Worst Case Runtime:
For more information, check out Wikipedia.