This algorithm allows us to find the shortest path from one node to another in a directed weighted graph without negative-weighted edges.
The algorithm follows these basic steps:
- Set as the cost for all nodes (except the origin node).
- Set the cheapest node as the
node
to be analyzed - While the list of nodes to be analyzed is not null:
- Calculate the costs for every neighbor of the
node
- If the cost for this node is lower than the cost registered in the table:
- Set the cost as the cost
- Set the
node
as the parent
- If the cost for this node is lower than the cost registered in the table:
- Add the
node
to the list of processed nodes - Set the cheapest neighbor as the new to be analyzed
- Calculate the costs for every neighbor of the