The keys 10, 4, 7, 1, 8, 3 are inserted one at a time into an empty binary min-heap stored in an array. What is the final array?
Correct answer B. [1, 4, 3, 10, 8, 7]
Explanation
Each key is appended and then sifted up while smaller than its parent. 4 swaps above 10; 7 stays; 1 rises past 10 and 4 to the root; 8 stays under 4; 3 swaps with its parent 7. The result is [1, 4, 3, 10, 8, 7]. A heap only orders parents against children, so the array need not be fully sorted.
Answer checked How we write and check questions
Discussion