3. HeapSortWe can use a heap to sort an array.Here we use a max-heap instead of a min-heap.The main idea:•Build a heap from an array.•With a max-heap, we can extract the root to get the largest value, and put it aside (put it as the last element of the array by swapping the root and the last element.)•Then we continue to extract the next root (the second largest value, and put it as the second last element of the array. •After doing this for n-1 times (where n is the number of elements in the initial heap), we will have a sorted (ascending order) array. To have a descending order array, we can use a min-heap.Since sorting an array means to sort any array, first we need to build a heap before we start extracting the roots.