GATE Computer ScienceVery hardGATE CSE · ISRO

Keys 40, 20, 60, 10, 30, 50, 70, 5, 15, 25, 35, 45, 55, 65, 80, 3, 12, 23, 27, 90 are inserted into an empty BST. How many nodes have a left subtree that is strictly taller than their right subtree (an empty subtree has height 0, a single node has height 1)?

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

Correct answer: C. 3

Computing subtree heights bottom-up and comparing left versus right at each of the 20 nodes gives 3 such nodes.

More Programming and Data Structures (GATE) questions

Exams that ask this topic