A single-source shortest-path algorithm finds the shortest distances from one starting vertex to every other vertex. It answers a different question from an all-pairs algorithm, which finds distances between every pair. section 9.1
Choose an approach based on the graph and the question:
- Dijkstra’s algorithm handles one starting vertex and is described as suitable when edge weights are positive. section 9.1
- Bellman–Ford also handles one starting vertex, while supporting negative edge weights and detecting negative cycles. section 9.3
- For sparse graphs, repeatedly running a single-source algorithm can be more performant than Floyd–Warshall’s all-pairs computation. section 9.3
One starting point
If you are at Node A and need distances to the rest of a network, that is a single-source problem. If you need distances between every possible pair, it is an all-pairs problem. section 9.1


