The whole idea of heap algorithm is that at all times you maintain a complete tree of elements (represented by an array). If you removed something from the root of the tree, you have to put something else in there instead. In an array the most efficient way to achieve that is to move the last element there.
Your concern seems to be based on the assumption that the last element in the array (leaf element in the tree) is the smallest element. That is not correct. Heap array is not fully sorted. Heap has a "vertical" ordering in each subtree, but it has no "horizontal" ordering between the subtrees. The last element in the array will certainly be the smallest in the unique path from the root to that leaf, but in general case it will not be the smallest in the entire heap.
When you look at any leaf element of a heap of size N
, you can certainly say that it is not one of the log N
greatest elements in the entire heap. But that's all you can say. For example, if your tree has 256 elements in it, then the last element in the array (or any other leaf element) will rank somewhere between 9th to 256th. See? It could be the 9th out of 256! Referring to such element as "smallest" is simply ridiculous. On average not only it is not the smallest, it is not even close to being the smallest.
Again, the last element is chosen specifically because it is the cheapest way to maintain a continuous array. If you implemented heap in some other way, say, through a linked tree instead of an array, then the optimal way of restoring the heap after the root removal might be different.