here follows an implementation of what we have just describeddef float(selfk)we are going to loop until we have reached the root node so that we can keep floating the element up as high as it needs to go since we are using integer divisionas soon as we get below the loop will break outwhile / compare parent and child if the parent is greater than the childswap the two valuesif self heap[kself heap[ // ]self heap[ ]self heap[ // self heap[ // ]self heap[kfinallylet' not forget to move up the treek // this method ensures that the elements are ordered properly now we just need to call this from our insert methoddef insert(selfitem)self heap append(itemself size + self float(self sizenotice the last line in insert calls the float(method to reorganize the heap as necessary pop just like insertpop(is by itself simple operation we remove the root node and decrement the size of the heap by one howeveronce the root has been popped offwe need new root node to make this as simple as possiblewe just take the last item in the list and make it the new root that iswe move it to the beginning of the list but now we might not have the lowest element at the top of the heapso we perform the opposite of the float operationwe let the new root node sink down as required