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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started