heap sort heap sort is comparison based sorting technique based on binary heap data structure it is similar to selection sort where we first find the maximum element and place the maximum element at the end we repeat the same process for remaining element what is binary heaplet us first define complete binary tree complete binary tree is binary tree in which every levelexcept possibly the lastis completely filledand all nodes are as far left as possible binary heap is complete binary tree where items are stored in special order such that value in parent node is greater(or smallerthan the values in its two children nodes the former is called as max heap and the latter is called min heap the heap can be represented by binary tree or array why array based representation for binary heapsince binary heap is complete binary treeit can be easily represented as array and array based representation is space efficient if the parent node is stored at index ithe left child can be calculated by and right child by (assuming the indexing starts at heap sort algorithm for sorting in increasing order build max heap from the input data at this pointthe largest item is stored at the root of the heap replace it with the last item of the heap followed by reducing the size of heap by finallyheapify the root of tree repeat above steps while size of heap is greater than how to build the heapheapify procedure can be applied to node only if its children nodes are heapified so the heapification must be performed in the bottom up order lets understand with the help of an exampleinput data ( ( ( ( ( the numbers in bracket represent the indices in the array representation of data