A binary tree of numbers is called a heap (or, it is said to satisfy the heap property) if, for every non-leaf node in the tree, the number stored at that node is less than or equal to the number stored at each of its children. For example, the following tree satisfies the heap property, because 3 ≤ 5, 5 ≤ 8 and 5 ≤ 7.
tree(empty,3,tree(tree(empty,8,empty),5,tree(empty,7,empty)))
On the other hand, the following tree does not satisfy the heap property, because 6 is not less than or equal to 5.
tree(tree(tree(empty,4,empty),
3,tree(empty,5,empty)),6,tree(tree(empty,9,empty),7,empty))
Example :
?- is_heap(tree(tree(tree(empty,4,empty),
3,tree(empty,5,empty)),6,tree(tree(empty,9,empty),7,empty))).
false.
?- is_heap(tree(empty,3,tree(tree(empty,8,empty),5,tree(empty,7,empty)))).
true
Any help will be appriciated.