Max-heap
Max-Heap A max-heap is a binary heap where the value of each node is greater than or equal to the values of its children. It is a complete binary tree in wh...
Max-Heap A max-heap is a binary heap where the value of each node is greater than or equal to the values of its children. It is a complete binary tree in wh...
Max-Heap
A max-heap is a binary heap where the value of each node is greater than or equal to the values of its children. It is a complete binary tree in which the root node is the maximum (or minimum) element.
Key characteristics of a max-heap:
A max-heap is a complete binary tree, meaning that it is fully populated.
The root node of a max-heap contains the maximum (or minimum) element.
The left child of a node is always a smaller (or less) value than the node itself.
The right child of a node is always a larger (or greater) value than the node itself.
Example:
Consider the following binary heap:
5
/ \
2 7
/ \
1 9
This heap satisfies the properties of a max-heap. The root node, 5, is the maximum element, and its children, 2, 7, and 1, follow the heap property