Below is the IntTree class we discussed in week 3 and that you worked on in HW3. We are in the middle of implementing a new recursive method called leafCount that should return the number of leaves in the tree. What code should replace the comment /* recursive case */ so that the leafCount method works correctly? return tempL + 1; return tempL + tempR + 1; return tempL + tempR; return tempR + 1;
Below is the IntTree class we discussed in week 3 and that you worked on in HW3. We are in the middle of implementing a new recursive method called leafCount that should return the number of leaves in the tree. What code should replace the comment /* recursive case */ so that the leafCount method works correctly? return tempL + 1; return tempL + tempR + 1; return tempL + tempR; return tempR + 1;
Related questions
Question
Below is the IntTree class we discussed in week 3 and that you worked on in HW3. We are in the middle of implementing a new recursive method called leafCount that should return the number of leaves in the tree. What code should replace the comment /* recursive case */ so that the leafCount method works correctly?
return tempL + 1; |
|
|
return tempL + tempR + 1; |
|
return tempL + tempR; |
|
return tempR + 1; |
![public class IntTree {
private Node root;
}
private static class Node {
public int key;
public Node left, right;
}
}
public Node(int key) {
this.key = key;
public int leafCount() {
return leafCountH(root);
}
}
private int leafCountH (Node n) {
if (n == null) {
/* base case 1 */;
} else if (n.left == null & n.right
/* base case 2 */;
} else {
int templ =
leafCountH(n.left);
int tempR leafCountH(n.right);
/* recursive case */;
== null) {](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F9fc22b82-ea82-45e5-a986-0e1813508f8a%2F8cbb2de1-b85b-4a58-8408-4cddea5602df%2Fw2uxysc_processed.png&w=3840&q=75)
Transcribed Image Text:public class IntTree {
private Node root;
}
private static class Node {
public int key;
public Node left, right;
}
}
public Node(int key) {
this.key = key;
public int leafCount() {
return leafCountH(root);
}
}
private int leafCountH (Node n) {
if (n == null) {
/* base case 1 */;
} else if (n.left == null & n.right
/* base case 2 */;
} else {
int templ =
leafCountH(n.left);
int tempR leafCountH(n.right);
/* recursive case */;
== null) {
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 3 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)