Which data structure is used, explicitly or through recursion, to implement depth-first search (DFS)?
Correct answer C. Stack
Explanation
DFS follows one path as deep as possible before backtracking to the most recently visited vertex that still has unexplored neighbours. Backtracking to the latest vertex is LIFO behaviour, so DFS uses a stack, either an explicit one or the call stack of a recursive implementation. A queue would produce breadth-first order instead.
Answer checked How we write and check questions
Discussion