Data Structures & AlgorithmsModerateTCS NQT · Accenture

Problem: For the same rooted tree as the previous question (root 1: children 2, 3; 2: children 4, 5, 6; 3: child 7; 5: child 8; 7: child 9), what is the height of the tree (the largest depth of any node, with the root at depth 0)?

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

Correct answer: B. 3

Height is the maximum depth over all nodes, found with one traversal that carries depth. Counting the number of leaves or the root's degree is a different measure.

More Coding Interview Problems questions

Exams that ask this topic