another time explaining: heap sort is another version of selection sort but also similar to pancake sort,if pancake sort swaps directly...what is not true. like pancake sort we search the maximum value using a max heap, what means that the tree node's children is less than node to siftdown(when we extract the max value the heap is breaked) we begin root i and compute left_child = i * 2 right_child = i * 2 + 1 we simply swap the bigger child and set i the child index repeat the process once you meet a leaf node to construct the heap begin a index in right and go to left doing a siftdown with root index to go to left you subtract 1 of index and finally you swap maximum reconstruct the heap swap maximum and then the array is sorted