Question: We discussed min-Heaps and the insert and delete operations, where the delete would remove and return the root element. Suppose we stored our heap in

 We discussed min-Heaps and the insert and delete operations, where the

We discussed min-Heaps and the insert and delete operations, where the delete would remove and return the root element. Suppose we stored our heap in an array as usual, and wanted to support a new heap operation: deleteNode (K) which deletes from the heap the node with key K (assume all keys in the heap are unique and key K is in the heap). Consider the following algorithm for deleteNode: 1. scan the array to find key K 2. delete key K 3. place the last node in the array, call it X, in K 's old position 4. restructure the heap so that heap order is satisfied. What is the worst-case Big-O runtime of the above algorithm in terms of n, the number of nodes in the heap? O(1) O(logn) O(n) O(nlogn)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!