Data Structures & AlgorithmsVery hardGATE CS · TCS NQT · Product Company SDE

An AVL tree node has left subtree height 4 and right subtree height 1. What must happen after this imbalance is detected?

  1. A. Nothing; AVL trees allow any difference
  2. B. A rotation (single or double) must restore the balance factor to within {-1, 0, 1}
  3. C. The whole tree must be rebuilt from scratch
  4. D. The node must be deleted

Correct answer: B. A rotation (single or double) must restore the balance factor to within {-1, 0, 1}

AVL trees require every node's balance factor (height of left minus height of right) to stay in {-1, 0, 1}; a difference of 3 triggers a rotation to restore that invariant.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic