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