Data Structures & AlgorithmsModerateInfosys · Accenture pattern

Keys 15, 10, 20, 8, 12, 25, 6, 11, 13, 9 are inserted into an empty BST. What is the height of the tree (edges on the longest root-to-leaf path)?

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

Correct answer: D. 3

15 → 10 → 8 → 6 or 9, and 15 → 10 → 12 → 11 or 13: the longest paths have 3 edges (e.g. 15–10–8–9). 9 is a leaf at depth 3 (right child of 8). Counting nodes instead of edges gives 4.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic