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...

Like a linked list, an array list can grow when necessary.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

Write a JavaFX application that displays a picture of a pine tree formed by drawing a triangle on top of a small rectangle that makes up the visible trunk. The tree should be green and have a gray trunk.

This project is a short application program that draws a pine tree. It uses four arrays of int values. One array holds the x-coordinates of the branches, the second holds the y-coordinates of the branches, and the last two hold the x- and y-coordinates of the trunk.

Computer Science & Information Technology

All functions begin with a plus sign

Indicate whether the statement is true or false

Computer Science & Information Technology

Regarding table options, the position of your cursor is important since the option menu impacts the entire table

Indicate whether the statement is true or false

Computer Science & Information Technology