Data Structures & AlgorithmsVery hardProduct-company placement
Build a binary min-heap in place from the array [73, 61, 88, 9, 29, 24, 58, 42] using bottom-up heapify (sift-down from the last internal node to the root). What is the resulting array?
- A. 88, 61, 73, 42, 29, 24, 58, 9
- B. 42, 58, 24, 29, 9, 88, 61, 73
- C. 9, 24, 29, 42, 58, 61, 73, 88
- D. 9, 29, 24, 42, 73, 88, 58, 61
Correct answer: D. 9, 29, 24, 42, 73, 88, 58, 61
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 [9, 29, 24, 42, 73, 88, 58, 61]. Simply sorting the array, [9, 24, 29, 42, 58, 61, 73, 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
- A directed graph has edges D→B, C→D, A→B, D→C. Using 3-colour DFS (white/grey/black, a grey-to-grey back edge means a cycle), does this…
- 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…
- A disjoint-set (union-find with union by rank and path compression) over 8 elements (0 to 7), each initially its own component, runs this…
- A directed graph has edges B→E, E→A, E→C, B→A, E→D, D→C. Using 3-colour DFS (white/grey/black, a grey-to-grey back edge means a cycle)…
- What are the time complexities of P and Q? c int P(int n) { if (n <= 1) return 1; return return P(n/2) + n; } int Q(int n) { if (n <= 1)…
- A directed graph has edges E→A, D→A, D→E, B→D, D→C. Using 3-colour DFS (white/grey/black, a grey-to-grey back edge means a cycle), does…