In: Computer Science
One way to remove an object from a binary min heap is to decrease its priority value by 1 and then call deleteMin. An alternative is to remove it from the heap, thus creating a hole, and then repair the heap.
Write pseudocode for an algorithm that performs the remove operation using the alternative approach described above. Your pseudocode should implement the method call remove (int index), where index is the index into the heap array for the object to be removed. Your pseudocode can call the following methods described in lecture: insert, deleteMin, percolateUp, and percolateDown. Like in lecture, you may assume that objects are just priority integers (no other data).
What is the worst-case complexity of the algorithm you wrote?
Pseudocode for Remove operation in heap (min-heap) :
Time Analysis of Remove operation in heap :
Feel free to ask any doubt you may have. Happy to help.