Breadth-First Search definition
Breadth-first search explores a graph in layers of increasing edge distance from a starting vertex.
Breadth-First Search in a picture
How it works
Use a queue: mark the start as discovered and put it at the back. Remove vertices from the front and enqueue each undiscovered neighbor. Mark neighbors when first enqueued so a vertex is processed only once. On an unweighted graph it finds shortest distances to reachable vertices.
Worked examples
With edges A–B, A–C, and B–D, which vertices are at distance one from A?
B and C.
What distance does the search find for D?
Two, using A–B–D.
Does a single-start search visit an unreachable vertex?
No. Only reachable vertices enter the queue.
Common mistake
Mark a vertex when you enqueue it. Otherwise multiple neighbors may enqueue the same vertex.
Quick check
Can it find an unweighted shortest path?
Show answer
Yes. Save each discovered vertex’s predecessor.
Does neighbor order change the shortest distance?
Show answer
No, although it can change which tied path is returned.
Sources
Flashcard
Breadth-First Search
Reveal the definition
Breadth-first search explores a graph in layers of increasing edge distance from a starting vertex.
Effortless Math. “Breadth-First Search.” Math Dictionary.



