DFS explores as deep as possible before backtracking. Internally it behaves like a stack
(or recursion). Click a node to set source.
V 6 · E 7Source 0Step 0
Legend: orange = current node (top of stack), purple = discovered (in stack), green = finished (popped).
Blue/orange edge = the neighbor being checked. When a node has no more unvisited neighbors, DFS backtracks.
Stackbottom → top
Traversal depth-first + backtrackingTime O(V + E)
When DFS discovers v from u, we set parent[v] = u. These parent pointers form the DFS tree.