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 node) {

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!