What does a breadth-first search (BFS) do, and how does its order differ from DFS?
BFS explores in rounds around its start vertex s: first s, then all neighbours of s, then all not yet visited neighbours of those, and so on, so it reaches the vertices in order of their distance from s. Like DFS it visits every vertex and edge and finds connectivity, the components and a spanning forest in $O(n + m)$; in addition, the path it finds to each vertex uses the fewest possible edges.
DFS runs down one path as far as it can; BFS fans out evenly, like the rings spreading from a stone dropped into water. Each ring is called a level: $L_0$ is the start vertex, $L_1$ its neighbours, $L_2$ the vertices two edges away, and so on.
The difference shows wherever a graph offers both short and long routes. DFS may reach a neighbour of s only after a long detour through the rest of the graph; BFS reaches all neighbours of s before anything further away. That is why only BFS answers "how many edges apart are these two vertices?" and "which path has the fewest edges?". For everything else, components, spanning forests, cycles and some path between two vertices, the two searches are interchangeable.
On a tree, BFS from the root is the familiar breadth-first or level-order traversal: all nodes of depth 0, then depth 1, then depth 2. The graph version only adds the labels, which are needed because a vertex can be the neighbour of several vertices of the previous level.
Go deeper:
Breadth-first search โ the queue-based algorithm, its analysis and its applications.