Guided Lesson Notes
Understanding Breadth-First Search
Breadth-First Search focuses on relationships, reachability, paths, cycles, connectivity, and optimization over edges. Breadth-first search explores level by level using a queue and naturally finds shortest paths in unweighted graphs.
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, Breadth-First Search 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.
