Heap Data Structure


A heap is a tree data structure where child nodes are always bigger than their parent (min heap) or larger than their parent (max heap). In a min heap, the smallest-valued node is at the root and each of the child nodes are bigger than the parent. This holds true for all subtrees. In a max heap, the largest-valued node is at the root and each of the child nodes are smaller than the parent. This also holds true for all subtrees.


A valid min heap: