Data Structures & AlgorithmsModerateTCS NQT · Infosys

Problem: Tree with root 1 and children 1: [2, 3], 2: [4, 5], 4: [6]. What is the number of nodes in the subtree of node 2 (node 2 counts itself)?

  1. A. 5
  2. B. 3
  3. C. 4
  4. D. 6

Correct answer: C. 4

The subtree of node 2 contains 2, 4, 5 and 6, which is four nodes. Counting only the leaves under node 2 gives two.

More Coding Interview Problems questions

Exams that ask this topic