Data Structures & AlgorithmsModerateTCS NQT · Infosys

Problem: Starting from the tree with root 1 and children 1: [2, 3], 2: [4], 3: [5, 6], 5: [7], a DFS visits children in increasing order. Which node is last to be finished (post-order last visited)?

  1. A. 2
  2. B. 0
  3. C. 1
  4. D. 3

Correct answer: C. 1

In post-order the root is always last. The question asks about the last node finished under the given order, which is the root in any post-order traversal, so the trap is answering with the last leaf instead.

More Coding Interview Problems questions

Exams that ask this topic