Data Structures & AlgorithmsVery hardIBM · Deloitte pattern

Keys 49, 39, 29 are inserted in this order into an empty AVL tree. After AVL rebalancing (a single rotation resolves the imbalance here), what is the resulting root and its two children (left, right)?

  1. A. root 49, left 29, right 39
  2. B. root 39, left 29, right 49
  3. C. root 39, left 49, right 29
  4. D. root 29, left 29, right 39

Correct answer: B. root 39, left 29, right 49

Inserting three keys in strictly decreasing order creates a LL-shaped imbalance at the first-inserted node, fixed by a single rotation that makes the middle-valued key (39) the new root, with the smallest key as its left child and the largest as its right child. Without rebalancing, the tree would stay a straight chain rooted at 49.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic