All mock tests are FREE till 31 December — register to save your progress
Unit 7 · Data Structures and Algorithms Paper 2 CS · September 2022

How many rotations are required during the construction of an AVL tree if the elements 35, 50, 40, 25, 30, 60, 78, 20, 28 are added in this sequence?

Pick an option to check yourself, or open the answer below.

Show answer & explanation

Correct answer: C. 3 left rotations, 2 right rotations

Explanation

Inserting 40 needs an RL double rotation (1 right + 1 left); 30 needs an LR double rotation (1 left + 1 right); 78 needs an RR single left rotation. 20 and 28 need none. Total: 3 left and 2 right rotations.

More Data Structures and Algorithms questions