GATE Computer ScienceHardGATE CS (PYQ pattern)
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 minimum n. At the root, the left subtree is taller than the right. Which key is at the root?
- A. 13
- B. 21
- C. 17
- D. 20
Correct answer: B. 21
Minimum sizes satisfy N(h) = N(h-1) + N(h-2) + 1 from N(0) = 1, N(1) = 2: 1, 2, 4, 7, 12, 20, 33. So n = 33, and the root's subtrees must be minimum trees of heights 5 and 4, holding 20 and 12 keys. With the taller side on the left, the 20 smallest keys sit to the left of the root, which is key 21 in inorder (key 13 if the right side were taller).
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- 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…
- A table of size 11 uses quadratic probing h(k, i) = (k mod 11 + i^2) mod 11. Keys 23, 34, 45, 56, 67, 78, 89 (all congruent to 1 mod 11)…