Question: JAVA QUESTION - COMPLETE CODE REQUIRED. Design and implement a method leafCount for BinarySearchTree that returns the number of leaves in the tree and a.
JAVA QUESTION - COMPLETE CODE REQUIRED.
Design and implement a method leafCount for BinarySearchTree that returns the number of leaves in the tree and
a. uses recursion
Hints:
private int recLeafCount(BSTNode
// base case 1 - node is empty
// base case 2 - node does not have left and right children
// general case - call itself with left subtree + right subtree
}
public int leafCount() { return recLeafCount(root);}
b. does not use recursion
Hints: Traverse all the nodes in the tree. Then,
if ((currNode.getLeft()== null) && (currNode.getRight()== null)) count++;
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
