Write the recursive function count; it is passed balanced binary (any binary tree, not necessarily a binary search tree) and a value as arguments. It returns the number of times the values is in the tree. In the binary tree below, count(tree,1) returns 1, count(tree,2) returns 2, count(tree,3) returns 4.

Respuesta :

Answer:

Python code:

def max_depth_util(root, val, level):

if root is None:

return 0;

if root.data == val:

return level

if root.left is not None or root.right is not None:

return max_depth_util(root.left, val, level + 1) + max_depth_util(root.right, val, level + 1)

return 0;

def max_depth(root,val):

return max_depth_util(root,val, 1)

Explanation: