Geeksforgeeks

X

DAYS

:

HOUR

:

MINS

:

SEC

Error

Copied to Clipboard

Given a binary tree. The task is to check whether the given tree follows the **max heap** property or not.

**Note: **Properties of a tree to be a max heap - Completeness and Value of node greater than or equal to its child.

**Example 1:**

**Input:
** 5
/ \
2 3
**Output: **1
**Explanation:** The given tree follows **max-heap** property since 5,
is root and it is greater than both its children.

**Example 2:**

**Input:
** 10
/ \
20 30
/ \
40 60
**Output:** 0

**Your Task:**

You don't need to read input or print anything. Your task is to complete the function **isHeap()** which takes the root of Binary Tree as parameter returns **True** if the given binary tree is a **heap** else returns **False**.

**Expected Time Complexity: **O(N)

**Expected Space Complexity: **O(N)

**Constraints:**

1 ≤ Number of nodes ≤ 100

1 ≤ Data of a node ≤ 1000

We are replacing the old Disqus forum with the new Discussions section given below.

Click here to view old Disqus comments.

Click here to view old Disqus comments.

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

YesLoading...

Is Binary Tree Heap

...