Data Structures & AlgorithmsVery hardProduct-company MCQ pattern
Build a binary min-heap in place from the array [2, 63, 36, 74, 23, 20, 15, 22] using bottom-up heapify (sift-down from the last internal node to the root). What is the resulting array?
- A. 2, 22, 15, 63, 23, 20, 36, 74
- B. 22, 15, 20, 23, 74, 36, 63, 2
- C. 2, 15, 20, 22, 23, 36, 63, 74
- D. 74, 63, 36, 22, 23, 20, 15, 2
Correct answer: A. 2, 22, 15, 63, 23, 20, 36, 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 [2, 22, 15, 63, 23, 20, 36, 74]. Simply sorting the array, [2, 15, 20, 22, 23, 36, 63, 74], 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 [47, 72, 84, 82, 36, 61, 51, 7, 2] using bottom-up heapify (sift-down from the last…
- Undirected graph edges: E–C, C–A, B–E, B–C, A–B, A–E, C–D. Using a BFS 2-colouring, is this graph bipartite?
- A trie is built from the words {cat, card, dot, den, deed, dog}. Using the trie (walk the prefix's characters, then count all words in the…
- An undirected graph has adjacency lists (neighbours visited in alphabetical order) A: [B, C, G]; B: [A, E, G]; C: [A, G]; D: [F, G]; E…
- A disjoint-set (union-find with union by rank and path compression) over 7 elements (0 to 6), each initially its own component, runs this…
- Keys 55, 65, 75 are inserted in this order into an empty AVL tree. After AVL rebalancing (a single rotation resolves the imbalance here)…