CS3240: Data Structures and Algorithms

Questions: Heaps

 

1) What is the running time in terms of O notation for Heap-Insert?

 

2) Create the pseudo code to implement the function Extract-Max procedure given you can use the function Heapify.

suppose we have the heap

now we extract the node (root) which represents the maximum value and now we get

We now have to make this back into a heap. We can almost run the heapify procedure on the whole thing, except that we have two complete binary trees, not one.

 

Hint:

to make the 2 trees back into a single tree, move one of the nodes from one of the trees to the root. But, which one could you move and then call heapify on the result to get back a single heap?

A

© Lynne Grewe