He everyone!
My question is quite simple: is there an algorithm that does exactly what's shown on this picture:
I thought about using BFS or IDDFS that "backtrack" after reaching all the leaves of the graph. Is there a better way to compute this algorithm?