计算二叉树高度的题目,求助
Consider the task of computing the height of a binary tree. ( We define the height of a leaf node to be 0), Suppose each node contains ponters LCHILD(left child) and RCHILD(right child).
a.write a pseudo code
c. Analyze the time complexity of the algorithm in terms of the number of nodes n and the height of the tree h.
我是这样写的
int height( pter r)
{ if r=NULL) return -1
if (height (r->LCHILD)>height(r->RCHILD))
return( 1+height(r->LCHILD))
else return (1+height(r->RCHILD));
}
感觉不是很高效啊,希望高人指点