What is a Heap?
A heap is a special kind of binary tree with specific properties:
1. Parent-Child Relationship: Each parent node’s value is greater than (or equal to) the
values of its child nodes.
2. Complete Tree: It is either fully filled or nearly complete, meaning the last level is filled
from left to right.
Max-Heap: The parent node is larger than its children.
Min-Heap: The parent node is smaller than its children.
Unless stated otherwise, a "heap" usually refers to a max-heap.
Key Features:
1. Root Node: In a max-heap, the largest value is at the root. In a min-heap, the smallest
value is at the root.
2. Subtrees: The left and right branches of any node follow the same rules, but the child
nodes' order (left or right) does not matter.
3. Array Implementation: Instead of linked nodes, heaps are often stored in arrays.
o The position of a node's children can be calculated efficiently.
o This makes processing fast and memory-efficient.