I am writing a function to determine whether a given binary tree is a max heap. If the binary tree had only one node (the root), would it be considered a valid max heap?
Asked
Active
Viewed 340 times
1 Answers
0
To be considered a valid max-heap, a binary tree must satisfy two properties:
- Shape property. The tree must be a complete binary tree. That is, every level except the last must be full. If the last is not full, it is left-filled.
- Heap property. Every child node must be less than or equal to its parent.
A tree with a single node satisfies both properties, so it is a valid max-heap.

Jim Mischel
- 131,090
- 20
- 188
- 351