Subtopic 7.1
Heap with an Array
5lessons33 min0done
A heap is a complete binary tree, so it fits into an array with no gaps: the node at index i has its children at 2i+1 and 2i+2 and its parent at (i-1)/2. That is why heaps are usually coded with an array.
Each operation is its own lesson: the heap rule, inserting with sift up, removing the minimum with sift down, building a heap from an array in O(n) time, and heap sort. The next subtopic repeats the same operations with linked nodes.