Consider a binary max-heap implemented using an array.
What is the content of the array after two delete operations on
View worked solution
Answer: D
A binary max-heap deletion is performed by replacing the root element with the last element of the heap, reducing the heap size by 1, and then performing a max-heapify operation from the root downwards.
Initial Max-Heap:
First Delete Operation:
- Remove the root element and replace it with the last element .
- Heapify down from the root ():
- Compare with its children and . Since is the larger child, swap with .
- Now, is at index 2. Its only child is . Since , the heap property holds.
Second Delete Operation:
- Remove the root element and replace it with the last element .
- Heapify down from the root ():
- Compare with its children and . Since is the larger child, swap with .
- Now, is at index 1. Its children are and . Since is the larger child, swap with .
Thus, the final content of the array is .
Free practice · Your answers on this page are not saved.
