LOGBOOK

HELP

Quiz Entry - updated: 2026.11.27

Run DFS and BFS from vertex 1 on the graph with vertices 1, 4, 5, 6, 7, 9 and edges 1–4, 1–5, 1–6, 1–9, 4–6, 4–7, 4–9, 5–6, 5–7, 6–7, 7–9, taking neighbours in ascending order. Which spanning trees result?

  • DFS: 1–4, 4–6, 6–5, 5–7, 7–9, visiting 1, 4, 6, 5, 7, 9: the tree is a single path.
  • BFS: 1–4, 1–5, 1–6, 1–9, 4–7, with the levels {1}, {4, 5, 6, 9}, {7}.

The six-vertex graph twice: the DFS tree is the path 1, 4, 6, 5, 7, 9; the BFS tree joins 1 to 4, 5, 6, 9 and 4 to 7

* Five tree edges each time for six vertices; the other six edges are back edges in the DFS and cross edges in the BFS. *

DFS. From 1 the smallest neighbour is 4. From 4 (neighbours 1, 6, 7, 9) the edge to 1 is already a discovery edge, so DFS moves on to 6. From 6 (neighbours 1, 4, 5, 7): 1–6 is a back edge, 4–6 is labelled, 5 is new. From 5: 1–5 is a back edge, 7 is new. From 7: 4–7 and 6–7 are back edges, 9 is new. From 9: 1–9 and 4–9 are back edges. Now every vertex is visited, and the calls return one after the other without finding anything new.

BFS. Level 1 is all of 1's neighbours: 4, 5, 6, 9. Processing them in that order, 4 reaches the unvisited 7 (discovery edge 4–7) and finds 6 and 9 already visited (cross edges 4–6 and 4–9); 5, 6 and 9 meet only visited vertices, which gives the cross edges 5–6, 5–7, 6–7 and 7–9. Level 2 is {7}, and level 3 stays empty.

The two trees show the character of the searches: DFS dives along one path to depth 5, BFS stays within two edges of the start. Vertex 9, a neighbour of 1, sits five edges deep in the DFS tree and directly below 1 in the BFS tree.

From Quiz: ADS / Graph Traversals: Depth-First and Breadth-First Search | Updated: Nov 27, 2026