elseif self heap_list[ self heap_list[ ]return elsereturn the code for the del_min operation is below note that once again the hard work is handled by helper functionin this case perc_down def del_min(self)ret_val self heap_list[ self heap_list[ self heap_list[self current_sizeself current_size self current_size self heap_list pop(self perc_down( return ret_val to finish our discussion of binary heapswe will look at method to build an entire heap from list of keys the first method you might think of may be like the following given list of keysyou could easily build heap by inserting each key one at time since you are starting with list of one itemthe list is sorted and you could use binary search to find the right position to insert the next key at cost of approximately (log noperations howeverremember that inserting an item in the middle of the list may require (noperations to shift the rest of the list over to make room for the new key thereforeto insert keys into the heap would require total of ( log noperations howeverif we start with an entire list then we can build the whole heap in (noperations the build_heap function shows the code to build the entire heap def build_heap(selfa_list) len(a_list/ self current_size len(a_listself heap_list [ a_list[:while ( )self perc_down(ii figure shows the swaps that the build_heap method makes as it moves the nodes in an initial tree of [ into their proper positions although we start out in the middle of the tree and work our way back toward the rootthe perc_down method ensures that the largest child is always moved down the tree because the heap is complete binary treeany nodes past the halfway point will be leaves and therefore have no children notice that when we are percolating down from the root of the treeso this may require multiple swaps as you can see in the rightmost two trees of figure first the is moved out of the root positionbut after is moved down one level in the treeperc_down ensures that we check the next set of children farther down in the tree to ensure that it is pushed as low as it can go in this case it results in second swap with now that has been moved to the lowest level of the treeno further swapping can be done it is useful to compare the list representation of this series of swaps as shown in figure with the tree representation trees and tree algorithms