Data Structures & AlgorithmsVery hardTCS NQT · Infosys pattern
Keys 45, 55, 65 are inserted in this order into an empty AVL tree. After AVL rebalancing (a single rotation resolves the imbalance here), what is the resulting root and its two children (left, right)?
- A. root 55, left 45, right 65
- B. root 45, left 55, right 65
- C. root 65, left 45, right 55
- D. root 55, left 65, right 45
Correct answer: A. root 55, left 45, right 65
Inserting three keys in strictly increasing order creates a RR-shaped imbalance at the first-inserted node, fixed by a single rotation that makes the middle-valued key (55) the new root, with the smallest key as its left child and the largest as its right child. Without rebalancing, the tree would stay a straight chain rooted at 45.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- Keys 56, 48, 53, 36, 81, 29, 64 are inserted via separate chaining (h(k) = k mod 7, new keys appended to the end of the chain) into a…
- A binary tree has preorder traversal [72, 40, 18, 19, 54, 47, 92, 81] and inorder traversal [18, 19, 40, 47, 54, 72, 81, 92]…
- Build a binary min-heap in place from the array [37, 10, 58, 45, 19, 47, 86, 41] using bottom-up heapify (sift-down from the last internal…
- Build a binary min-heap in place from the array [34, 57, 50, 49, 69, 76, 15, 74] using bottom-up heapify (sift-down from the last internal…
- A disjoint-set (union-find with union by rank and path compression) over 9 elements (0 to 8), each initially its own component, runs this…
- An undirected graph has adjacency lists A:BCDG B:AEF C:A D:AE E:BD F:B G:A. Neighbours are always explored in alphabetical order. Which is…