← Questions
Depth-first traversal visiting smaller neighbors first
0
I was asked this
No reports yet. Sign in to say where you were asked it.
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.
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
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
