VOOZH about

URL: https://www.geeksforgeeks.org/dsa/given-level-order-traversal-binary-tree-check-tree-min-heap/

⇱ Given level order traversal of a Binary Tree, check if the Tree is a Min-Heap - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Given level order traversal of a Binary Tree, check if the Tree is a Min-Heap

Last Updated : 23 Jul, 2025

Given the level order traversal of a Complete Binary Tree, determine whether the Binary Tree is a valid Min-Heap

Examples:

Input: level = [10, 15, 14, 25, 30]
Output: True
Explanation: The tree of the given level order traversal is

👁 Given-level-order-traversal-of-a-Binary-Tree-check-if-the-Tree-is-a-MinHeap-1
Given Tree is Min-Heap

We see that each parent has a value less than its child, and hence satisfies the min-heap property

Input: level = [30, 56, 22, 49, 30, 51, 2, 67]
Output: False
Explanation: The tree of the given level order traversal is

👁 Given-level-order-traversal-of-a-Binary-Tree-check-if-the-Tree-is-a-MinHeap-2
Given Tree is not min-heap

We observe that at level 0, 30 > 22, and hence min-heap property is not satisfied

To verify the heap property, we ensure that each non-leaf node (parent) is smaller than its children. For every parent at index i, we compare it with its left child at 2*i + 1 and, if present, its right child at 2*i + 2. If a parent has only one child, we check against the left child alone.


Output
True
Comment
Article Tags: