Write a method int depth(Node tree) that returns the length of the longest path that begins at the node tree and ends at any leaf of the binary tree.
What will be an ideal response?
Assuming a Node class
```
class Node
{
int element;
Node left, right;
Node(int el, Node left, Node right)
{
element = el;
this.left = left;
this.right = right;
}
}
```
```
int depth(Node tree)
{
if (tree == null)
return -1;
else
return 1 + Math.max(depth(tree.left) + depth(tree.right));
}
```
Computer Science & Information Technology
You might also like to view...
What compatibility issues exist between Access 2003 and Access 2013? What differences are there between Access 2007 and Access 2013?
What will be an ideal response?
Computer Science & Information Technology
The If Then Else control structure tests if a condition is true
Indicate whether the statement is true or false
Computer Science & Information Technology