GATE Computer ScienceVery hardGATE CS (PYQ pattern)
An AVL tree is built by inserting 1, 2, ..., 15 in increasing order (the perfect tree with root 8). Then keys 1, 3, 5, 2, 4 are deleted in that order (a node with two children is replaced by its inorder successor, and rebalancing walks back up to the root, rotating wherever |balance| = 2; a double rotation counts as 2). How many rotations do the five deletions cause, and what is the preorder traversal of the final tree?
- A. 1 rotations; 8 6 7 12 10 9 11 14 13 15
- B. 2 rotations; 8 6 7 12 10 9 11 14 13 15
- C. 0 rotations; 8 6 7 12 10 9 11 14 13 15
- D. 1 rotations; 6 7 8 9 10 11 12 13 14 15
Correct answer: A. 1 rotations; 8 6 7 12 10 9 11 14 13 15
Tracing the deletions with rebalancing at every ancestor gives 1 rotations and the preorder shown (the tree stays height-balanced throughout).
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- Cuckoo hashing uses two tables of size 7: h1(k) = k mod 7 in T1 and h2(k) = floor(k / 7) mod 7 in T2. To insert x, place it in T1[h1(x)]…
- Keys 19, 36, 5, 21, 4, 26, 14, 17, 25, 12, 40, 33 are inserted into a chained hash table with 7 buckets, h(k) = k mod 7, each new key…
- A max-heap is built from [90, 80, 70, 60, 50, 40, 30, 20, 10, 15, 25, 35, 45, 55, 65] by bottom-up heapify. Then the key at index 14 is…
- Two stacks (values and operators) evaluate 12-(3+4(5-2))/53+8/(1+1) with all operators left-associative and integer division truncating…
- How many index pairs i < j satisfy a[i] + a[j] == 10 in the array {3, 8, 5, 2, 7, 4, 6, 1, 9, 5, 3, 7}?
- unsigned x = 0x369; / binary 11 0110 1001 / unsigned s = 0, c = 0; while (x) { unsigned t = x & -x; c++; s += t c; x -= t; } What is s…