#Day1 #100DaysOfCode
heap is a data structure. it is a complete binary tree (please refer to complete binary tree for more properties on its own).
A binary heap: node in parent greater or less than children nodes. Maximum children a parent can have is two.
left child is calculated by 2i+1, right child is 2i+2 where i is the index of the root node.
to find whether an element belongs to which parent, use the formula (i-1)/2
heapify process starts from i = (n/2) -1 going backwards
It is an in-place algo, doesn't require extra storage.
Time complexity: O(nlogn) for best, average, and worst
https://github.com/qbaocaca/data_structure_and_algorithm/blob/main/heap_sort.cpp
heap is a data structure. it is a complete binary tree (please refer to complete binary tree for more properties on its own).
A binary heap: node in parent greater or less than children nodes. Maximum children a parent can have is two.
left child is calculated by 2i+1, right child is 2i+2 where i is the index of the root node.
to find whether an element belongs to which parent, use the formula (i-1)/2
heapify process starts from i = (n/2) -1 going backwards
It is an in-place algo, doesn't require extra storage.
Time complexity: O(nlogn) for best, average, and worst
https://github.com/qbaocaca/data_structure_and_algorithm/blob/main/heap_sort.cpp