Data Structures & AlgorithmsVery hardProduct-company placement

Keys 85, 62, 86, 26, 40, 54, 92, 17, 18, 67 are inserted into an empty AVL tree (giving preorder 62, 40, 18, 17, 26, 54, 86, 85, 67, 92). Then 92 and 40 are deleted in that order (a two-child node takes its inorder successor) with AVL rebalancing. What is the final preorder?

  1. A. 62, 54, 18, 17, 26, 86, 85, 67
  2. B. 62, 26, 18, 17, 54, 86, 85, 67
  3. C. 62, 18, 17, 54, 26, 85, 67, 86
  4. D. 54, 18, 17, 26, 85, 62, 67, 86

Correct answer: C. 62, 18, 17, 54, 26, 85, 67, 86

After each deletion walk back up and rotate at any node whose balance becomes ±2 (LL at 86, LL at 54). Skipping the rotation, or rebuilding the AVL tree from the remaining keys, gives a different tree.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic