Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

/ Complete the four exercises below. For each EXERCISE comment, add code immediately below the comment. //You MUST NOT edit the IDEA/SBT configuration/tests. Altering it

/ Complete the four exercises below. For each "EXERCISE" comment, add code immediately below the comment. //You MUST NOT edit the IDEA/SBT configuration/tests. Altering it in your submission will result in 0 points for this assignment. // // This class represents operations on simple Binary Search Trees (BST) with integer keys and no values, i.e., a set of integers. // // DO NOT change the name or type of any function (the first line of the function)

// All of the methods in this class are static (and mostly recursive). // These methods could naturally appear inside Node.java also. // // This code is not representative of the object-oriented style of programming, but is concise and allows null to be used to represent leaf nodes.

//////////////////////////////////////////////////////////////////////////////////////

// EXERCISE 1: A tree is size-perfect if for every node, size of left == size of

right. public boolean isPerfectlyBalancedS () { // TODO: Complete this method. return false; }

//////////////////////////////////////////////////////////////////////////////////////

// EXERCISE 2: A tree is height-perfect if for every node, height of left == height

of right. public boolean isPerfectlyBalancedH () { // TODO: Complete this method. return false; }

//////////////////////////////////////////////////////////////////////////////////////

// EXERCISE 3: A tree is semi-perfect if every node is semi-perfect. // A node with 0 children is semi-perfect. // A node with 1 child is NOT semi-perfect. // A node with 2 children is semi-perfect if (size-of-larger-child <= size-of-smaller-child * 3)

public boolean isSemiBalanced (){ // TODO: Complete this method. return false; }

//////////////////////////////////////////////////////////////////////////////////////

// EXERCISE 4:

// tree is odd-perfect if for every node, #odd descendant on left == # odd descendants on right

// A node is odd if it has an odd key

// hint: in the helper, return -1 if the tree is not odd-perfect, otherwise return the odd size

public boolean isOddBalanced() {

// TODO: Complete this method.

return false;

}

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

Datacasting How To Stream Databases Over The Internet

Authors: Jessica Keyes

1st Edition

007034678X, 978-0070346789

More Books

Students also viewed these Databases questions