Algorithms_in_C++ 1.0.0
Set of algorithms implemented in C++.
|
Heap Sort Algorithm (heap sort) implementation More...
#include <algorithm>
#include <cassert>
#include <iostream>
Functions | |
template<typename T > | |
void | printArray (T *arr, int sz) |
template<typename T > | |
void | heapify (T *arr, int n, int i) |
template<typename T > | |
void | heapSort (T *arr, int n) |
void | test () |
int | main () |
Heap Sort Algorithm (heap sort) implementation
Heap-sort is a comparison-based sorting algorithm. Heap-sort can be thought of as an improved selection sort: like selection sort, heap sort divides its input into a sorted and an unsorted region, and it iteratively shrinks the unsorted region by extracting the largest element from it and inserting it into the sorted region. Unlike selection sort, heap sort does not waste time with a linear-time scan of the unsorted region; rather, heap sort maintains the unsorted region in a heap data structure to more quickly find the largest element in each step.
Time Complexity - \(O(n \log(n))\)
int main | ( | void | ) |
void printArray | ( | T * | arr, |
int | sz ) |
void test | ( | ) |
Test cases to test the program