Deleting any node apart from root node inside a heap

why didn’t we just swap the element to be deleted with the last element and then popped it and then down heapified the last element till the bottom like we did for the deletion of the root node?

We can not delete directly because it may loose the balanced structure of the heap. For example lets say a series of deletion operation are performed on in the same branch of binary heap then by this logic the one part of the binary heap will be totally empty and heap will have a skewed tree like structure. That is the reason we only define deletion from the root node only.

2 Likes