notice that we can compute the parent of any node by using simple integer division the parent of the current node can be computed by dividing the index of the current node by def perc_up(selfi)while / if self heap_list[iself heap_list[ / ]tmp self heap_list[ / self heap_list[ / self heap_list[iself heap_list[itmp / we are now ready to write the insert method most of the work in the insert method is really done by perc_up once new item is appended to the treeperc_up takes over and positions the new item properly def insert(selfk)self heap_list append(kself current_size self current_size self perc_up(self current_sizewith the insert method properly definedwe can now look at the del_min method since the heap property requires that the root of the tree be the smallest item in the treefinding the minimum item is easy the hard part of del_min is restoring full compliance with the heap structure and heap order properties after the root has been removed we can restore our heap in two steps firstwe will restore the root item by taking the last item in the list and moving it to the root position moving the last item maintains our heap structure property howeverwe have probably destroyed the heap order property of our binary heap secondwe will restore the heap order property by pushing the new root node down the tree to its proper position figure shows the series of swaps needed to move the new root node to its proper position in the heap in order to maintain the heap order propertyall we need to do is swap the root with its smallest child less than the root after the initial swapwe may repeat the swapping process with node and its children until the node is swapped into position on the tree where it is already less than both children the code for percolating node down the tree is found in the perc_down and min_child methods def perc_down(selfi)while ( <self current_sizemc self min_child(iif self heap_list[iself heap_list[mc]tmp self heap_list[iself heap_list[iself heap_list[mcself heap_list[mctmp mc def min_child(selfi)if self current_sizereturn trees and tree algorithms