Similar questions 1 more →
Heaps & Priority Queues

Answer & solution
Official answer: B
Replace the deleted element with the last heap element, reduce the heap size, then sift up if the parent order is violated or otherwise sift down. At most one root-to-leaf path is traversed, length≤d. Some deletions require movement throughΘ(d) levels, so the worst-case bound is O(d) and not O(1), B.
Replacing the deleted slot with the last array element preserves the complete-tree shape and avoids shifting an entire subtree. For a min-heap, compare the replacement with its parent: if it is too small, move it upward; otherwise any violation can only be below it, so move it downward by choosing the smaller child. The max-heap case reverses inequalities. There are at most d edges on the chosen path, with constant work at each, and worst-case inputs require traversal to the root or deepest leaf.