Question: // 10 points /* * Returns true if for every node in the tree has the same number of nodes to * its left as

// 10 points

/*

* Returns true if for every node in the tree has the same number of nodes to

* its left as to its right. For example, the BST with level order traversal 50

* 25 100 12 37 150 127 is NOT perfectly balanced. Although most of the nodes

* (including the root) have the same number of nodes to the left as to the

* right, the nodes with 100 and 150 do not and so the tree is not perfeclty

* balanced.

*

* HINT: In the helper function, change the return type to int and return -1 if

* the tree is not perfectly balanced otherwise return the size of the tree. If

* a recursive call returns the size of the subtree, this will help you when you

* need to determine if the tree at the current node is balanced.

*/

public boolean isPerfectlyBalanced() {

// TODO

throw new RuntimeException("Not implemented");

}

/*

* Mutator functions HINT: This is easier to write if the helper function

* returns Node, rather than void similar to recursive mutator methods on lists.

*/

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 Programming Questions!