After the transfer of the root to the sorted part of the heap, its place is given to the last
element of the unsorted heap (the element at the last position of the initial). Its size
has been decreased by one element (the element that has just been swapped). Now,
the heap property has been violated because a descendant has been placed in the root
position. In order to restore the heap, we have to perform O(log n) necessary
operations (swaps and comparisons) until the property is restored by calling heapify.
However, we do not do it immediately. We “forget”, for the time being, the existence
of the root. As a result, we have two independent heaps now, its subtrees. We select
the minimum root of these two at the cost of one comparison and we swap it with the
last element of the heap. So far, two elements have been transferred in the sorted part
of the heap. Now, we have to rebuild the initial heap in order to repeat the same
process for the rest of the elements.