Data Structures & AlgorithmsEasyWipro · Accenture pattern

Keys 50, 30, 70, 20, 40, 60, 80 are inserted in that order into an empty BST. How many leaves does the tree have, and what is its height (edges on the longest root-to-leaf path)?

  1. A. 4 leaves, height 3
  2. B. 7 leaves, height 2
  3. C. 3 leaves, height 2
  4. D. 4 leaves, height 2

Correct answer: D. 4 leaves, height 2

50 is the root with children 30 and 70, which get 20, 40 and 60, 80 as children: a perfect tree with 4 leaves and height 2 in edges. Height 3 counts levels (nodes) instead of edges.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic