Breadth-first and depth-first search

Breadth-first and depth-first search one step at a time, with the queue or stack shown, and a check of which extra edges fit the BFS levels.

Figure 1.4.Choose BFS or DFS and press Step. When BFS has finished, test the candidate edges: an edge can only join vertices on the same level or on adjacent levels. Open on its own

BFS visits every vertex at distance 1 before any at distance 2, so its levels are distances from the start.

DFS backtracks only when the current vertex has no unvisited neighbours.