Heap Sort
Last updated
Was this helpful?
Last updated
Was this helpful?
Based on a typical data structure, Heap Sort is an in-place, not stable comparison-baed sorting algorithm and can be thought of as a improved version of algorithm.
Initially, a is called upon a randomly distributed inputs to setup a . Now that the topmost root key must be the largest among the heap, extract that key to a sorted array and restore the heap property using operation. Repeat the procedures of extraction and adjustment till the heap is empty, the sorted array is formed.
In each heap restoration process, instead of method of locating the maximum or minimum key within the inputs in linear time, Heap Sort uses operation to reduce time complexity to logarithmic bound.
The following code transforms a randomly distributed array into an ascending entry array.
Given a n-size inputs, there is a Ο(n) estimate on operation; And for each input entry, a is expected to perform and thus costs Ο(n ⋅ log(n)) in total.
Since the is also a comparison-based sorting that has proven with a lower bound Ω(n ⋅ log(n)), the more tighter bound for Heap Sort will be Θ(n ⋅ log(n)).
Why is Heap Sort used?