GATE Computer ScienceVery hardGATE CS (PYQ pattern)
Keys 40, 20, 10, 25, 30, 22, 50, 5, 3, 35, 45, 60 are inserted in this order into an initially empty AVL tree (a double rotation counts as 2 rotations). What is the total number of rotations performed and the preorder traversal of the final tree?
- A. 6 rotations; 25 20 5 3 10 22 40 30 35 50 45 60
- B. 7 rotations; 25 20 5 3 10 22 40 30 35 50 45 60
- C. 7 rotations; 25 20 5 3 10 22 40 30 35 50 45
- D. 8 rotations; 3 5 10 20 22 25 30 35 40 45 50 60
Correct answer: B. 7 rotations; 25 20 5 3 10 22 40 30 35 50 45 60
Simulating each insertion with the usual LL, RR, LR and RL cases gives 7 rotations in all and the final preorder shown.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- Keys 1, 2, 3, ..., 20 are inserted in increasing order into an initially empty AVL tree. What is the key at the root, and how many…
- An AVL tree of height 6 (a single node has height 0) has the minimum possible number of nodes, and its keys are 1, 2, ..., n for that…
- The array [4, 10, 3, 5, 1, 8, 7, 2, 9, 6, 11, 12] is converted into a max-heap by Floyd's bottom-up build (sift-down from the last…
- The keys 20, 15, 30, 10, 5, 25, 3, 18, 1 are inserted one by one into an initially empty min-heap (array form, each insert sifts up). How…
- A max-heap is built from [50, 30, 40, 10, 20, 35, 25, 5, 8, 15, 12] by bottom-up heapify. Two delete-max operations are then performed…
- How many different max-heaps (valid arrays) can be formed using the 10 distinct keys 1 to 10?