Data Structures & AlgorithmsVery hardGATE CS · ICPC regional · Product Company SDE
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 node to the root). What is the resulting array?
- A. 10, 19, 47, 41, 37, 58, 86, 45
- B. 41, 86, 47, 19, 45, 58, 10, 37
- C. 10, 19, 37, 41, 45, 47, 58, 86
- D. 86, 45, 58, 41, 19, 47, 37, 10
Correct answer: A. 10, 19, 47, 41, 37, 58, 86, 45
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 [10, 19, 47, 41, 37, 58, 86, 45]. Simply sorting the array, [10, 19, 37, 41, 45, 47, 58, 86], 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
- 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…
- Edges A-E, D-E, B-E, A-C, A-B are added one by one to an initially empty graph on vertices {A, B, C, D, E}, using Union-Find (with path…
- In the undirected graph with edges A–B:14, B–C:2, A–D:11, D–E:8, A–F:14, B–G:11, A–G:3, what is the shortest-path distance from A to B?
- Keys 37, 28, 13, 54, 24, 77, 95, 49, 68 are inserted in this order into an empty BST. What is the preorder traversal?