Practice mode Data Structures

The minimum is removed from the min-heap by moving the last element to the root and sifting it down. What is the resulting array?

Correct answer B. [3, 4, 7, 10, 8]

Explanation

Remove 1 and move the last element, 7, to the root: [7, 4, 3, 10, 8]. Sift down by swapping with the smaller child: 3 is smaller than 4, so swap to get [3, 4, 7, 10, 8]. At index 2, 7 has no children, so it stops. Swapping with the larger child would break the heap property.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.