You must mean a Min Heap. When we are dealing with any tree structure the children of a Node are most commonly initialized as None. One of the reasons is that we can easily escape the recursion as such:
def find_node(node, data):
if root is None:
return
if root.data == data:
print "Node found"
find_node(node.left, data)
find_node(node.right, data)
class Node(object):
def __init__(self, data):
self.left = None
self.right = None
self.data = data
In your case you want to check if a tree is min heap by traversing it. You would do something like that
def is_min_heap(root):
#.....check here and then do
return is_min_heap(root.left) and is_min_heap(root.right)
But it depends how you want to handle it. Any one node with no children is a min-heap or a max-heap but it has no meaning. If you want to call
is_min_heap(None)
then you are free to do so but it is up to you if you want to say that is True or not.