Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions