Which data structure is generally used to implement Depth First Search (DFS)?

Options

  • A. Queue
  • B. Stack
  • C. Priority Queue
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

B. Stack

Detailed Explanation

Correct Answer: B. Stack

Explanation: Depth First Search explores a path as deeply as possible before backtracking.

  • DFS can be implemented using an explicit stack.
  • It can also be implemented using recursion, which internally uses the call stack.
  • BFS generally uses a queue.