removeMin We must take the value from the root node and return it to the user. Then we must remove the node. Easy array implementation: –Take the last element in the heap and put it in root –Then call heapify!
heapify Heapify is called on a node. It checks that the heap property is being maintained. If not, it fixes it i 2i 2i i 2i 2i+1 If a fix was made heapify calls itself recursively on the swapped child i 2i 2i+1 Details such as checking to make sure elements 2i and 2i+1 are in the heap are omitted Details such as checking to make sure elements 2i and 2i+1 are in the heap are omitted
removeMin size = 27 69
removeMin size = ReturnValue: 2
Consider … Remove 10…. Which element becomes a root now? Try 20 to preserve the order property (r<=c)… Is this acceptable? Not complete tree. Therefore …… Let’s try to preserve the structure property….
removeMin size = ReturnValue: 2 Decrement the size
removeMin size = 26 ReturnValue: 2
removeMin size = 26 ReturnValue: 2 Heapify
removeMin size = 26 ReturnValue: 2 Heapify
removeMin size = 26 ReturnValue: 2 Heapify
removeMin size = 26 ReturnValue: 2 Heapify
removeMin size = 26 ReturnValue: 2 Heapify
removeMin size = 26 ReturnValue: 2 Heapify
removeMin size = 26 ReturnValue: 2 Heapify
removeMin size = 26 ReturnValue: 2 Heapify
removeMin size = 26 ReturnValue: 2
removeMin size = 26 Questions?