GATE Computer ScienceHardGATE CS (PYQ pattern)
Keys 30, 10, 20, 50, 40, 60, 45 are inserted into an initially empty AVL tree in this order. What are the root and the total number of rotations (a double rotation counts as 2)?
- A. root 40, 6 rotations
- B. root 30, 5 rotations
- C. root 40, 4 rotations
- D. root 40, 5 rotations
Correct answer: D. root 40, 5 rotations
Insert 30, 10, 20: left-right double rotation gives root 20. Then 50, 40, 60 and 45 cause further imbalance; simulating gives root 40 and 5 rotations in all.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- Which one of the following is NOT a possible pop sequence when 1, 2, 3, 4, 5 are pushed in order (pops interleaved arbitrarily)? P: 2 1 4…
- 125 keys are hashed uniformly and independently into 50 chains of a hash table. What are the expected number of keys examined in an…
- The preorder and inorder traversals of a binary tree are 7 3 1 2 5 4 6 and 1 3 2 7 4 5 6 respectively. What is its postorder traversal?
- int a[] = {2, 4, 6, 8, 10}; int p = a + 1, q = a + 4; printf("%d %d %d", p + q, (q - 2), q - p); What is printed?
- int f(void) { static int c = 0; return ++c; } int main() { int x = f() || f(); int y = f() && f() > 3 ? f() : -f(); printf("%d %d %d", x…
- In a min-heap stored 1-indexed in an array with children of i at 2i and 2i+1, a node at index 77 is replaced by a smaller key and sifted…