As indicated in another answer, moving your graph using DFS will visit the vertices in the same way regardless of the actual DFS implementation using iteration or recursion. See Pseudocode in the Wikipedia article .
You have an additional requirement, which is to visit neighboring peaks in alphabetical order. This means that the stack needs to be sorted when things are clicked on it (in the iterative version), or it means that you have to overwrite adjacent vertices in sorted order (in the recursive version). Both implementations will behave the same.
Given the limitation in alphabetical order, the result A, C, D, E, F is the only possible DFS bypass of your graph.
user1019830
source share