← Questions

Depth-first traversal visiting smaller neighbors first

0
WaymoCodingLast asked Sep 2026

You get a directed graph as adjacency lists whose neighbors are in no particular order, and a start vertex. Run a depth-first search from the start and return the vertices in the order they are first visited, always going to the smallest-numbered unvisited neighbor first. Visit each reachable vertex once and leave out the unreachable ones. Be ready to write it iteratively with an explicit stack.

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding