Data Structures & AlgorithmsVery hardHCLTech · Wipro pattern
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 node to the root). What is the resulting array?
- A. 15, 34, 49, 50, 57, 69, 74, 76
- B. 74, 15, 76, 69, 49, 50, 57, 34
- C. 15, 49, 34, 57, 69, 76, 50, 74
- D. 76, 74, 50, 57, 69, 34, 15, 49
Correct answer: C. 15, 49, 34, 57, 69, 76, 50, 74
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 [15, 49, 34, 57, 69, 76, 50, 74]. Simply sorting the array, [15, 34, 49, 50, 57, 69, 74, 76], 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
- 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?
- A min-heap is built by inserting 69, 20, 19, 35, 32, 87, 52, 58 one by one (sift-up on each insert). After one extract-min (move the last…