Guided Lesson Notes
Understanding Floyd-Warshall Algorithm
Floyd-Warshall Algorithm focuses on relationships, reachability, paths, cycles, connectivity, and optimization over edges. Floyd-Warshall computes all-pairs shortest paths by gradually allowing more intermediate vertices.
The mental model is this: draw vertices as dots and edges as connections; then decide whether direction, weight, or capacity matters. That picture matters because it tells the student what information is available immediately and what must be searched, stored, or recomputed.
The core invariant is that visited, distance, parent, component, or flow arrays must match what has actually been discovered so far. If a solution cannot state that rule, the code may still run on a sample input but fail on edge cases.
A strong implementation usually uses adjacency lists or matrices, queues, stacks, priority queues, union-find, and repeated edge relaxation. The goal is not just to memorize an API; the goal is to know why each operation is allowed and what it costs.
In competitive programming, Floyd-Warshall Algorithm tends to appear when the problem mentions roads, networks, prerequisites, components, shortest paths, spanning costs, or dependency order. Spotting that signal is often the difference between a nested-loop solution and an efficient one.
