heaps def __siftupfrom(selfchildindex)'''childindex is the index of node in the heap this method sifts that node up as far as necessary to ensure that the path to the root satisfies the heap condition ''the sequence of values passed to the buildfrom method will be copied into the heap theneach subsequent value in the list will be sifted up into its final location in the heap consider the list of values [ we'll trace this through showing the resulting heap at each stage to begin the list is copied into the heap object in the order given here then siftupfrom is called on each subsequent element to beginsiftupfrom is called on the second elementthe in this case calling siftupfrom on the root of the heap would have no effect normallythe parent index of the node is computed the parent will already be greater than the other child (if there is oneif the value at the current child index is greater than the value at the parent indexthen the two are swapped and the process repeats this process repeats as many times as are necessaryeither until the root node is reached ( index of the listor until the new node is in the proper location to maintain the heap property the first time some movement occurs is when is added to the heap the is swapped with the to arrive at its final location resulting in the heap in fig the first four elements of the list now make up heap butthe is not in its final position we need to sift it up in the heap to get it to its final position looking at the conceptual view of the heap ( the tree)you can see that is child of the node containing clearlythat violates the heap property so and are swapped to sift the up as shown in fig without looking at the conceptual model you can still compute the parent of the node containing in part one of fig when was at index in the listthe parent index was computered as follows parentindex ( )// sothe is compared to the at index in part one above thenthe swap is made because is greater than in part two howeverthe is still not in the fig building heap part one this copy belongs to 'acha