Heap Sort | C++ | Heaps | Sorting Techniques [ Algorithm + Code explanation]

Krishna Teaches
Krishna Teaches
8.1 هزار بار بازدید - 4 سال پیش - This video contains a detailed
This video contains a detailed explanation of Heap Sort, along with code in C++.

Heapsort is a comparison based sorting technique based on Binary Heap data structure. It is similar to selection sort where we first find the maximum element and place the maximum element at the end. We repeat the same process for the remaining elements.

Why array-based representation for Binary Heap?
Since a Binary Heap is a Complete Binary Tree, it can be easily represented as an array and the array-based representation is space-efficient. If the parent node is stored at index I, the left child can be calculated by 2 * I + 1 and right child by 2 * I + 2 (assuming the indexing starts at 0)

Time Complexity: O(nlogn)
Space Complexity: O(1)

Complete Code:
https://github.com/krishna-gavas/Comp...

Intro Music :
Video
4 سال پیش در تاریخ 1399/07/26 منتشر شده است.
8,178 بـار بازدید شده
... بیشتر