Write a method int numberLeaves(Node tree) that returns the number of leaves in the binary tree whose root is 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 numberLeaves(Node tree)
{
if (tree == null) return 0;
if (tree.left == null && tree.right == null)
return 1;
else
return numberLeaves(tree.left) + numberLeaves(tree.right);
}
```
You might also like to view...
What is the alias symbol for the jQuery namespace?
a. / b. $ c. ? d. #
Evaluate the below conditional expressions in a step-by-step manner as shown in the examples when x = 1 and y = 2.
Note: In the solutions below, indicate the current logical expression being evaluated according to the rules of precedence. ``` NOT (x = 1 AND y —2 = 0) ``` Evaluates as False
Sheet 1 and Sheet 2 are grouped. If you enter a formula in B3 of Sheet 1, what happens in Sheet 2?
A. No change happens. B. Sheet 2 B3 has the same formula. C. A warning appears, warning you not to make changes in grouped sheets. D. Formatting will change on Sheet 2, but not formulas.
Bell Telephone Laboratories invented the ________, which replaced the vacuum tube.
Fill in the blank(s) with the appropriate word(s).