Shortest paths
Fewest edges or least total weight: BFS, Dijkstra, Bellman-Ford, Floyd-Warshall and A*.
- Shortest paths in unweighted graphs; path reconstruction In an unweighted graph BFS finds shortest paths. Distance labels spread outward and parent arrows trace each path back to the source.
- Dijkstra's algorithm Dijkstra’s algorithm finds shortest paths with non-negative weights. It settles the closest unsettled vertex and relaxes its edges using a…
- Bellman-Ford and negative edges Bellman-Ford relaxes every edge n − 1 times, so it handles negative weights. One more round that still improves a distance reveals a…
- 0-1 BFS and multi-source BFS When edge weights are only 0 or 1, a deque replaces the priority queue. Multi-source BFS starts from many sources at once, as in rotting…
- Floyd-Warshall: all pairs Floyd-Warshall finds shortest paths between every pair of vertices. The distance matrix updates once for each vertex allowed as a midpoint.
- A* search with heuristics A* adds a heuristic estimate of the remaining distance to Dijkstra’s cost. A good heuristic aims the search at the goal and expands fewer…