Question
The Heap Sort is an in-place, logarithmic sorting algorithm that uses the features of heap data structure. Suppose an array A with N elements is
The Heap Sort is an in-place, logarithmic sorting algorithm that uses the features of heap data structure.
Suppose an array A with N elements is given. The heap-sort algorithm to sort A consists of the two following phases: Phase 1: Build a heap H out of the elements of A.
Phase
2: Repeatedly delete the root element of H.
For example consider the following array of 6 elements: 15 19 10 7 17 16
0 1 2 3 4 5->array index
After building a heap from these elements, the array will look like this: 19 17 16 7 15 10
0 1 2 3 4 5->array index
Now, delete the root and place it at the last position of the array. Heapify the remaining array: 17 15 16 7 10 19
0 1 2 3 4 5->array index
Now we have a heap of 5 elements. Repeat this process until the heap is empty.
use c++ language
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started