GATE Computer ScienceHardGATE CS (PYQ pattern)
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 (single) rotations occurred in total?
- A. key 8, 17 rotations
- B. key 9, 15 rotations
- C. key 8, 15 rotations
- D. key 4, 14 rotations
Correct answer: C. key 8, 15 rotations
Ascending insertion only ever needs left (RR) rotations, and the tree keeps re-balancing towards a complete shape. Simulating the 20 insertions gives root 8 and 15 rotations.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- 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?
- A hash table of size 11 uses linear probing with h(k) = k mod 11. Keys 43, 22, 33, 54, 65, 76, 87, 14, 25 are inserted in this order (no…