Data Structures & AlgorithmsEasyIBM · Deloitte pattern

Depth-first search is naturally implemented with which of the following?

  1. A. A queue
  2. B. A stack (or recursion)
  3. C. A priority queue
  4. D. A circular buffer

Correct answer: B. A stack (or recursion)

DFS goes as deep as possible before backtracking, which is LIFO behaviour: an explicit stack or the recursion call stack. A queue would make it BFS.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic