why do we take that element to peek and then swap it with last element? Why can we not swap it directly with last element and do down heapify for only that region of array?
Deleting any element from heap
we can only delete from top of the heap, we do this so that the tree remains a ‘balanced’ complete binary tree
if we delete from the middle, there is a high chance to have a further branch without completely filling the previous one, it could also become a skewed tree in one branch if we do that, and then the overall operation of the heap would get effected, to avoid this we follow the protocol of only deleting from the top