Build fluency in the vocabulary of computing shortest distances between every pair of nodes in one unified pass.
0 / 5 completed
1 / 5
At standup, a dev mentions computing the shortest distance between every single pair of nodes in a graph at once, by repeatedly checking whether routing through each node in turn as an intermediate stop shortens any pair's known distance. What is this algorithm called?
Floyd–Warshall algorithm is exactly this: the Floyd–Warshall algorithm computes the shortest distance between every pair of nodes in a graph simultaneously, by repeatedly considering each node in turn as a possible intermediate stop and updating any pair's distance whenever routing through that intermediate node turns out shorter. A hash collision is an unrelated hash-table concept about two keys sharing a bucket. This all-pairs, try-every-intermediate-node approach is exactly why the Floyd–Warshall algorithm answers every pair's shortest distance in one pass, instead of running a single-source algorithm once per node.
2 / 5
During a design review, the team picks the Floyd–Warshall algorithm for a dense graph where shortest distances between every single pair of nodes are needed, specifically because computing all pairs at once with dynamic programming over intermediate nodes avoids re-running a single-source algorithm separately for every node. Which capability does this provide?
Floyd–Warshall algorithm here provides All-pairs shortest distances computed in one unified pass, since the algorithm progressively allows more nodes to serve as intermediate stops, and by the time every node has been considered, every pair's shortest distance is known at once, all within roughly the same cost as running a single-source algorithm once per node from scratch. Running a single-source algorithm separately for every node would need to repeat much of the same bookkeeping over and over. This unified-pass-over-all-pairs behavior is exactly why the Floyd–Warshall algorithm is favored on a reasonably small, dense graph where all-pairs distances are genuinely needed.
3 / 5
In a code review, a dev notices an all-pairs shortest-distance feature over a dense graph runs a single-source shortest-path algorithm separately once for every single node, instead of computing every pair's distance together in one unified pass. What does this represent?
This is a missed Floyd–Warshall opportunity, since considering every node in turn as a possible intermediate stop, the way the Floyd–Warshall algorithm does, would compute every pair's shortest distance together in one unified pass instead of repeating a single-source algorithm once per node. A cache eviction policy is an unrelated concept about discarded cache entries. This repeated-single-source pattern is exactly the kind of duplicated effort a reviewer flags once all-pairs distances over a reasonably small, dense graph are the actual goal.
4 / 5
An incident report shows an all-pairs shortest-distance computation over a dense graph took far longer than expected, because it re-ran a single-source shortest-path algorithm separately for every single node instead of computing every pair together in one pass. What practice would prevent this?
Switching to the Floyd–Warshall algorithm's unified all-pairs dynamic-programming pass eliminates the repeated per-node bookkeeping. Continuing to re-run a single-source shortest-path algorithm separately for every node regardless of how many nodes need all-pairs distances computed is exactly what caused the issue described in this incident. This unified all-pairs approach is the standard fix once all-pairs shortest distances over a reasonably small, dense graph are genuinely required.
5 / 5
During a PR review, a teammate asks why the team reaches for the Floyd–Warshall algorithm instead of running Dijkstra's algorithm once per node, given that Dijkstra's algorithm is already well understood and efficient for a single source. What is the reasoning?
The Floyd–Warshall algorithm computes every pair's shortest distance together in one unified dynamic-programming pass, which is convenient and simple to implement on a reasonably small, dense graph, while running Dijkstra's algorithm once per node can be faster on a large, sparse graph but requires explicitly managing that repetition and its bookkeeping. This is exactly why the Floyd–Warshall algorithm is favored for smaller, denser graphs, while repeated single-source runs scale better on large, sparse ones.