In computer science, a heap is a specialized tree-based data structure
which is essentially an almost complete[1] tree that satisfies the heap
property: in a max heap, for any given node C,
if P is a parent node of C, then the key (the value)
of P is greater than or equal to the key of C. In a min heap,
the key of P is less than or equal to the key of C.[2]
The node at the "top" of the heap (with no parents) is
called the root node.
- parent > i the Left Child is 2i +1 and Right Child is 2i + 2
- child > i the parent is i/2 -1
- Heap is a complete binary tree (Or almost complete) and stored in array
- Max array size (2^h+1) - 1 for a perfect tree (all nodes have 2 Child nodes )
- Max nodeas at height = h = 2^h ex: Height 0 1 node, Height 1 2 Nodes, Height 2 4 nodes
- Max nodes in entienr tree of Height is h=(2 ^(h+1)) -1) ex: 2 ^ 3+1) -1 = 7 for a Perfect Binary Tree (PBT)
- range of leaves n/2 + 1 to N
- range of internal nodes > 1 to n/2