GATE Computer ScienceHardGATE CS (PYQ pattern)

In the BST obtained by inserting 40, 20, 60, 10, 30, 50, 5, 15, 3, 1, 25, 55, 57, 56 in order, how many nodes have a balance factor (height of left subtree minus height of right subtree, empty = -1) whose absolute value exceeds 1?

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

Correct answer: C. 6

Compute each node's subtree heights; the nodes with |bf| >= 2 are counted: 6 (the tree is not AVL).

More Programming and Data Structures (GATE) questions

Exams that ask this topic