Breadth-first search algorithm flowchart
This breadth-first search algorithm flowchart shows the queue-based order that distinguishes BFS from other graph traversals. The process starts by reading a graph and start vertex, marking that vertex visited, and placing it in the queue. The central subroutine then repeats the three essential actions: dequeue a vertex, record it, and enqueue each previously unvisited neighbor.
Open it in the AI editor with a prompt pre-filled — keep what works, change what doesn't.
Scenario
A student documents breadth-first search as a queue-driven graph traversal and needs the visited rule shown alongside the traversal order.
Key decisions
- Queue initialization: The start vertex is marked before it enters the queue, avoiding duplicate work.
- FIFO traversal: Dequeueing the next vertex makes the traversal breadth-first rather than depth-first.
- Visited neighbors: Each unvisited neighbor is marked and enqueued during processing of the current vertex.
- Loop subroutine: The queue-empty condition is stated inside a subroutine so the rendered diagram remains compact.
When to reuse this
Use this for an unweighted graph traversal or shortest-hop explanation. Add parent and distance updates when the diagram is used for shortest paths.
Frequently asked questions
Why does BFS use a queue?
When is a neighbor marked visited?
Can this find shortest paths?
Tweak it with chat, export PNG/SVG, or fork it for your own use case.