Write a function $\texttt{deepest(A, E)}$ that returns the deepest level of the element E in the binary tree A or 0 if E $\notin$ A. We assume that the root of the tree is at level 1, and that the tree is dynamically implemented.
Running example: let A be the following BT; $\texttt{deepest(A,2)}=3$, $\texttt{deepest(A,3)}=0$.

Difficulty level

This exercise is mostly suitable for students
int deepest_h(Btree B, element1 e, int level)
{
int x ;
if(!B) return 0;
x=max(deepest_h(B->left,e,level+1) ,deepest_h(B->right,e,level+1));
if(B->data==e) return max(level,x );
return x;
}
int deepest(Btree B, element1 e)
{
return deepest_h(B,e,1);
}
Back to the list of exercises
Looking for a more challenging exercise, try this one !!
