Reference no: EM132158997
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 <I>
// (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 <I>
// (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