Quiz Entry - updated: 2026.11.27
Run DFS from A on the graph with edges A–B, A–C, A–D, A–E, B–C, C–D, C–E, taking each vertex's edges in alphabetical order of the far vertex. Which edges become discovery edges, and which back edges?
Discovery edges: A–B, B–C, C–D, C–E, with the vertices visited in the order A, B, C, D, E. Back edges: C–A, D–A and E–A.
* Every back edge points from a vertex to an ancestor on its path from A. *
The trace, call by call:
- DFS(A): the first edge, A–B, leads to the unexplored B, so A–B becomes a discovery edge.
- DFS(B): A–B is already labelled and skipped; B–C leads to the unexplored C: discovery edge.
- DFS(C): C–A leads to A, already visited: back edge. C–B is labelled. C–D leads to D: discovery edge.
- DFS(D): D–A leads to A: back edge. D–C is labelled. D has no edges left, so the call returns to C.
- DFS(C) continues: C–E leads to E: discovery edge. DFS(E): E–A is a back edge, E–C is labelled, return.
- Back in B and then in A, the remaining edges A–C, A–D and A–E are all labelled already, and the search ends.
The counts check out: 4 discovery edges for 5 vertices, exactly what a spanning tree needs, plus 3 back edges, 7 edges in all. Another start vertex or another order of the incident edges would give another tree, which is why the order is fixed in the question.
Go deeper:
VisuAlgo: graph traversal — draw a graph or pick an example and step through DFS and BFS; its graphs are directed, so draw an undirected edge as two opposite edges.