DSA · Reimagined
Graphs medium time O(V + E) space O(V)

Breadth-First Search

BFS visits everything one step away, then everything two steps away, and so on. A queue holds the frontier, and marking nodes seen the moment they are enqueued stops the same node being queued twice. On an unweighted graph this finds shortest paths.

ABCDEF
queue
A
0
visit orderempty

BFS from A: the queue starts holding just the source.

1 / 22
A fixed scene — scrub through it, or open the code.

Practice

Machine twin: /dsa-viz-v2/graph-bfs.json — the full deterministic run as structured data.