separately by whatever algorithm calls it inserting node takes at most (log nstepsbecause the maximum number of times we may have to 'bubble upthe new element is the height of the tree which is log deleting heap tree node to use binary heap tree as priority queuewe will regularly need to delete the rooti remove the node with the highest priority we will then be left with something which is not binary tree at all howeverwe can easily make it into complete binary tree again by taking the node at the 'lastposition and using that to fill the new vacancy at the root howeveras with insertion of new itemthe heap tree (priority orderingproperty might be violated in that casewe will need to 'bubble downthe new root by comparing it with both its children and exchanging it with the largest this process is then repeated until the new root element has found valid place thusa suitable algorithm isdeleteroot(array heapint nif error('node does not exist'else heap[ heap[nbubbledown( ,heap, - similar process can also be applied if we need to delete any other node from the heap treebut in that case we may need to 'bubble upthe shifted last node rather than bubble it down since the original heap tree is ordereditems will only ever need to be bubbled up or downnever bothso we can simply call bothbecause neither procedure changes anything if it is not required thusan algorithm which deletes any node from heap tree isdelete(int iarray heapint nif error('node does not exist'else heap[iheap[nbubbleup( ,heap, - bubbledown( ,heap, - the bubble down process is more difficult to implement than bubble upbecause node may have noneone or two childrenand those three cases have to be handled differently in the case of two childrenit is crucial that when both children have higher priority than the given nodeit is the highest priority one that is swapped upor their priority ordering will be violated thus we have