Dijkstra’s Shortest Path
Dijkstra’s algorithm finds the shortest path between two nodes in a graph that has weights. Think of the weights as having lengths on the graph with a higher number needing a longer distance to get there.
How to use Dijkstra’s algorithm
- Start at the source node. This is the node you are starting from.
- Find the node with the smallest weight. This is the node that is closest to the source node.
- Update the weights of the neighbouring nodes. If the weight of the neighbouring node is less than the current weight, update it.
- Repeat steps 2 and 3 until you reach the destination node.