Question: Use the statement counting approach to show that the worst-case time complexity of the heap inser- tion and deletion algorithms given are O (log n

Use the statement counting approach to show that the worst-case time complexity of the heap inser- tion and deletion algorithms given are O(log n).

Algoirthm insert(H, e) Inserts the element e into the heap H.

Insert e into H normally , as in ArrayedBinaryTreeWithCursors280

// (put it in the left-most open position at the bottom level of the tree)

while e is larger than its parent and is not at the root: swap e with its parent

Algorithm deleteItem(H) Removes the largest element from the heap H.

// Since the largest element in a heap is always at the root...

Remove the root from H normally , as in ArrayedBinaryTreeWithCursors280

// (copy the right-most element in the bottom level, e, into the root, // remove the original copy of e.)

while e is smaller than its largest child swap e with its largest child

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!