Which of the following is the correct traversal order for a depth-first search…
2025
Which of the following is the correct traversal order for a depth-first search (DFS) in a graph?
- A.
Preorder, Inorder, Postorder
- B.
Level Order
- C.
Push, Visit, Pop
- D.
Visit, Push, Pop
Attempted by 12 students.
Show answer & explanation
Correct answer: A
Depth-first search (DFS) and breadth-first search (BFS) are named by how they explore nodes, and each has its own vocabulary of traversal orders. The DFS family is named Preorder, Inorder, and Postorder — terms rooted in tree traversal that differ only in when the current node is visited relative to its children — while BFS's traversal order is named Level Order, since BFS uses a queue to explore nodes level by level.
The question asks which of the offered choices names the correct traversal order for a DFS. Among the four options, only Preorder, Inorder, Postorder actually names a traversal-order family, and it is specifically the DFS-associated family — as opposed to Level Order, which names the BFS family — so it is the option that answers the question.
Level Order names the BFS (queue-based, level-by-level) traversal family, not the DFS family.
Push, Visit, Pop describes generic stack operations used while implementing a traversal, not the name of any traversal order.
Visit, Push, Pop likewise names implementation-level stack operations rather than a recognised traversal-order term; changing the sequence of the same three operations does not create a valid traversal-order name.
Hence, among the offered choices, Preorder, Inorder, Postorder is the traversal-order family associated with depth-first search.