Heap Sort
Algorithm
First establish a heap tree from a list, by starting with the first element in the list and then appending the elements from the list as leaves. Each time when a node is added, make sure to perform the necessary swaps so that nodes with higher values trickle to the top of the heap.
Write the numbers back to the list starting from the top-most node and going from left to right.
Exchange the root of the tree with the lower right-most leaf (or left leaf, if the right-most leaf does not exist), performing the same swap in the list, and delete it from the tree. After that, make sure to let the higher value leaves trickle up. Repeat the same process until all the leaves have been removed.
Worst case:
Best case:
Average case:
Space complexity:
total or
auxiliary
fuss/algorithms/sorting/heapsort.txt ยท Last modified: 2022/04/19 08:28 by 127.0.0.1