Grammar corrections (#32486)
This commit is contained in:
committed by
The Coding Aviator
parent
781a166878
commit
534a484003
@ -5,7 +5,7 @@ title: Heapsort
|
||||
|
||||
Heapsort is an efficient sorting algorithm based on the use of max/min heaps. A heap is a tree-based data structure that satisfies the heap property -- that is for a max heap, the key of any node is less than or equal to the key of its parent (if it has a parent). This property can be leveraged to access the maximum element in the heap in O(logn) time using the maxHeapify method. We perform this operation n times, each time moving the maximum element in the heap to the top of the heap and extracting it from the heap and into a sorted array. Thus, after n iterations we will have a sorted version of the input array. The algorithm is not an in-place algorithm and would require a heap data structure to be constructed first. The algorithm is also unstable, which means when comparing objects with same key, the original ordering would not be preserved. This algorithm runs in O(nlogn) time and O(1) additional space [O(n) including the space required to store the input data] since all operations are performed entirely in-place.
|
||||
|
||||
The best worst and average case time complecity of Heapsort is O(nlogn). Although heapsort has a better worse-case complexity than quicksort, a well-implemented quicksort runs faster in practice. This is a comparison-based algorithm so it can be used for nonnumerical data sets insofar as some relation (heap property) can be defined over the elements.
|
||||
The best, worst and average case time complexity of Heapsort is O(nlogn). Although heapsort has a better worse-case complexity than quicksort, a well-implemented quicksort runs faster in practice. This is a comparison-based algorithm so it can be used for non-numerical data sets insofar as some relation (heap property) can be defined over the elements.
|
||||
|
||||
An implementation in Java is as shown below :
|
||||
|
||||
@ -63,7 +63,7 @@ public class Heapsort {
|
||||
}
|
||||
}
|
||||
```
|
||||
implementation in C++
|
||||
Implementation in C++
|
||||
```C++
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
Reference in New Issue
Block a user