The function:
MAX-HEIGHT(node)
if(node == NIL)
return -1;
else
return max(MAX-HEIGHT(node.leftChild), MAX-HEIGHT(node.rightChild)) + 1;
Suppose that we have N nodes and we call the function with MAX-HEIGHT(root).
I think that the complexity of this function is O(N) because we need to visit each node. However, I am not sure and I can not prove it rigorously. Please give me a good explanation why it is O(N), if it is O(N), and why not if it is not O(N).
So, what is the complexity?
Thank you.