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?

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

  1. A.

    Queue

  2. B.

    Stack

  3. C.

    LinkedList

  4. D.

    None of the above

Attempted by 1045 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

Loading lesson…