Heapify(A,i) (1) l = Left(i) (2) r = Right(i) (3) if l <= heap_size[A] and A[l] < A[i] (4) then smallest = l (5) else smallest = i (6) if r <= heapsize[A] and A[r] < A[smallest] (7) then smallest = r (8) if smallest != i (9) then swap(A[i],A[smallest]) (10) Heapify(A,smallest)
Build_Heap(A) (1) heapsize[A] = lenght[A] (2) for i = floor(length[A]/2) downto 1 (3) Heapify(A,i)
Heapsort(A) (1) BuildHeap(A) (2) for i = length[A] downto 2 (3) exchange A[1] A[i] (4) heapsize[A] = heapsize[A] - 1 (5) Heapify(A,1)
Sort4 took 1 ticks, and 7853646 moves Sort7 took 3 ticks, and 38095906 moves Ratio: 4.85073 Sort4 took 1 ticks, and 7904994 moves Sort7 took 3 ticks, and 38096806 moves Ratio: 4.81933 Sort4 took 1 ticks, and 7903690 moves Sort7 took 3 ticks, and 38095760 moves Ratio: 4.82