example build max heap from the given set of numbers and also draw the memory representation of the heap solution (step (step (step (step (step (step (step (step (step (step (step (step (step figure the memory representation of can be given as shown in fig heap[ heap[ heap[ heap[ heap[ heap[ heap[ heap[ heap[ heap[ figure memory representation of binary heap after discussing the concept behind inserting new value in the heaplet us now look at the algorithm to do so as shown in fig we assume that with elements is stored in array heap val has to be inserted in heap the location of val as it rises in the heap is given by posand par denotes step [add the new value and set its posset pos the location of the parent of val step set heap[nval note that this algorithm inserts single value in step [find appropriate location of valthe heap in order to build heapuse this algorithm repeat steps and while pos step set par pos/ in loop for exampleto build heap with step if heap[pos<heap[par]elementsuse for loop that executes times and then goto step in each passa single value is inserted else swap heap[pos]heap[parthe complexity of this algorithm in the average pos par case is ( this is because binary heap has [end of ifo(log nheight since approximately of the [end of loopelements are leaves and are in the bottom two step return levelsthe new element to be inserted will only move figure algorithm to insert an element in max heap few levels upwards to maintain the heap