Which data structure is used to implement depth-first search (DFS) of a graph?

2025

Which data structure is used to implement depth-first search (DFS) of a graph?

  1. A.

    Queue

  2. B.

    Stack

  3. C.

    LinkedList

  4. D.

    None of the above

Attempted by 622 students.

Show answer & explanation

Correct answer: B

Depth-first search (DFS) is implemented using a Stack. DFS visits the nodes by going as deep as possible along each path before backtracking.

Explore the full course: Cocubes Preparation