LOGBOOK

HELP

Quiz Entry - updated: 2026.11.27

What distinguishes a back edge of DFS from a cross edge of BFS?

A back edge (v, w) leads from v to an ancestor w of v in the DFS tree. A cross edge (v, w) joins v to a vertex w on the same level as v or on the next level of the BFS tree. So in an undirected graph DFS never produces an edge between two separate branches, and BFS never produces an edge that skips a level.

The six-vertex graph's DFS tree, a deep branch with back edges up to ancestors, next to its BFS tree in three levels with cross edges within a level or one level down

* The same nine edges: DFS hangs the vertices on one deep branch, BFS on three shallow levels. *

Why a DFS back edge always leads to an ancestor. DFS does not finish a vertex until everything reachable through its unexplored edges is done. Suppose that at v an unexplored edge leads to an already visited vertex w. If w had been finished before, it would have examined all its edges, the edge to v among them, and that edge would already carry a label. So w is not finished: its call is still open, and the open calls are exactly the ancestors of v.

Why a BFS cross edge never skips a level. When v in $L_i$ is processed, each of its neighbours is either already in a level up to $L_{i+1}$ or is put into $L_{i+1}$ now. So the two ends of any edge lie in levels that differ by at most one, which is what makes the levels distances.

The levels also give a quick test of whether a graph is bipartite, meaning its vertices split into two groups with every edge running between the groups: colour the even levels one way and the odd levels the other. Discovery edges and cross edges between adjacent levels respect the colouring; only a cross edge inside one level breaks it, and such an edge closes a cycle of odd length, so then the graph is not bipartite.

Go deeper:

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