Practice mode Data Structures

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.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.