Could someone illustrate Heapsort using an actual example I

Could someone illustrate Heapsort using an actual example? I can understand MAX-HEAPIFY in isolation, but how does it work with BUILD-MAX-HEAP? Again could an actual example help me see this better?

Here is the algorithm :

Input : array A[1..n]

Heapsort (A,n)

BUILD-MAX-HEAP(A,n)

for i=n downto 2

exchange A[1] with A[i]

MAX-HEAPIFY(A,1,i-1)

Solution

First heap is a tree based data structure which consist of some heap properties like shape property which means all levels of tree are filled and heap property where all nodes are either equal, greater than or less than to each children and the condition where parent nodes are greater than chilren than its called maxheap and if smaller than min heap. First whenever we get a unsorted list then we either create max heap or min heap and once its created either the parent element would be largest or smallest, hence we put first element in array and then keep repeating the same and puttind the elemnet into array.
Now we will see that in algorithm ,where build heap is called to first create the heap structure and now when we do it using build- max heap which means it will create max heap where parent is greater than its children.
We can use the procedure \'Heapify\' in a bottom-up fashion to convert an array A[1 . . n] into a heap.Here the max-heapify function is the subarray which is kind of iterative call to create aray of sorted list

Could someone illustrate Heapsort using an actual example? I can understand MAX-HEAPIFY in isolation, but how does it work with BUILD-MAX-HEAP? Again could an a

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site