Data Structures & AlgorithmsHardTCS NQT · Infosys pattern

Keys 38, 48, 58 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 48, left 38, right 58
  2. B. root 38, left 48, right 58
  3. C. root 48, left 58, right 38
  4. D. root 58, left 38, right 48

Correct answer: A. root 48, left 38, right 58

Inserting three keys in strictly increasing order creates a RR-shaped imbalance at the first-inserted node, fixed by a single rotation that makes the middle-valued key (48) 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 38.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic