Data Structures & AlgorithmsHardProduct-company placement
Build a binary min-heap in place from the array [4, 37, 81, 88, 64, 1, 84, 86] using bottom-up heapify (sift-down from the last internal node to the root). What is the resulting array?
- A. 88, 86, 84, 37, 64, 1, 81, 4
- B. 86, 84, 1, 64, 88, 81, 37, 4
- C. 1, 4, 37, 64, 81, 84, 86, 88
- D. 1, 37, 4, 86, 64, 81, 84, 88
Correct answer: D. 1, 37, 4, 86, 64, 81, 84, 88
Bottom-up heapify sifts down every internal node starting from index ⌊n/2⌋ − 1 up to the root, swapping a node with its smaller child until the min-heap property holds; this gives [1, 37, 4, 86, 64, 81, 84, 88]. Simply sorting the array, [1, 4, 37, 64, 81, 84, 86, 88], is not what heapify produces — a heap is only partially ordered.
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
- An undirected graph has adjacency lists (neighbours visited in alphabetical order) A: [D, F]; B: [C, F]; C: [B, E]; D: [A, E]; E: [C, D]…
- Keys 93, 67, 60, 15, 3, 58, 52, 13, 92 are inserted via separate chaining (h(k) = k mod 7, new keys appended to the end of the chain) into…
- Build a binary min-heap in place from the array [35, 63, 89, 24, 71, 8, 16, 88, 2, 79] using bottom-up heapify (sift-down from the last…
- A binary tree has preorder traversal [52, 25, 42, 27, 64, 92, 78] and inorder traversal [25, 27, 42, 52, 64, 78, 92]. Reconstructing the…
- Keys 45, 55, 65 are inserted in this order into an empty AVL tree. After AVL rebalancing (a single rotation resolves the imbalance here)…
- 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…