We call the heapify function in order to restore the heap property to the heap from
which the second element was extracted. This heap has depth d’ = d - 1, where d’ is
its depth and d = log n is the depth of the initial heap. Thus, the heapify function runs
in O(d’) = O(d – 1) time. The merging of the two heaps into the initial one can be
performed by calling the heapify function to the “forgotten” root of the initial heap.
We repeat the same process until two or fewer elements have been remained. The
sorting of two elements is trivial.