Heap Sort using Heapify method

preview_player
Показать описание
The Heapsort algorithm involves preparing the list by first turning it into a max heap. The algorithm then repeatedly swaps the first value of the list with the last value, decreasing the range of values considered in the heap operation by one, and sifting the new first value into its position in the heap. This repeats until the range of considered values is one value in length.

The steps are:

1. Call the buildMaxHeap() function on the list. Also referred to as heapify(), this builds a heap from a list in O(n) operations.

2. Swap the first element of the list with the final element. Decrease the considered range of the list by one.
3. Call the siftDown() function on the list to sift the new first element to its appropriate index in the heap.

4. Go to step (2) unless the considered range of the list is one element.

Ref: Wikipedia
Рекомендации по теме
Комментарии
Автор

Build Max heap mai i=n/2 to n tak chalega na
n/2 to 1 tak kyu??

subhampatar