Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please make sure to follow all the instructions! The file IntBalancedSet2.java is provided at the bottom. Complete the following methods. a. Complete the constructor for

Please make sure to follow all the instructions!

The file IntBalancedSet2.java is provided at the bottom. Complete the following methods.

a. Complete the constructor for creating a leaf node that receives an array of data. Throw IllegalArgumentException if the array is an invalid length (less than MINIMUM or greater than MAXIMUM). Otherwise, set data, dataCount, and childCount appropriately.

b. Complete the constructor for creating a parent (non-leaf) node that receives an array of data and an array of child node references (for subset). Throw IllegalArgumentException if the array is an invalid length (less than MINIMUM or greater than MAXIMUM) or if the lengths of the data and subset arrays are in conflict. Otherwise, set data, subset, dataCount, and childCount appropriately.

c. Complete the main() method to use the above constructors to manually construct a B-tree with at least 3 levels using the constructors above. Note that you are manually arranging the values; and you are not programming an insertion algorithm. Then use the provided print method to print the tree (note that the indent argument controls the desired spacing). Below is an example using a tree:

image text in transcribed

d. Complete the isValid() method so that it returns true if a node satisfies B-tree rule #5 from the textbook and returns false otherwise. B-tree rule #5 states: For any non-leaf node: (1) An element at index i is greater than all the elements in subtree number i of the node, and (2) an element at index i is less than all the elements in subtree number of the node. Assume the tree already satisfies all of the other rules. Demonstrate the isValid() method using the root node of your tree in part (c) above by printing Valid or Not valid. OPTIONAL: You may wish to simplify your code by designing lessThan and greaterThan methods (stubs are provided for you) that receive a parent key value and return true or false if a child nodes values are all less or greater than the parent key, respectively, and a node is valid.

IntBalancedSet2.java:

public class IntBalancedSet2 { private final int MINIMUM = 1; private final int MAXIMUM = 2*MINIMUM; int dataCount; int[ ] data = new int[MAXIMUM + 1]; int childCount; IntBalancedSet2[ ] subset = new IntBalancedSet2[MAXIMUM + 2]; // Constructor for leaf node (no children) public IntBalancedSet2(int[] setData) { // Complete this method for Part (a) } // Constructor for non-leaf node (has children) public IntBalancedSet2(int[] setData, IntBalancedSet2[ ] setSubset) { // Complete this method for Part (b) } public static void main(String[ ] args) { // Complete this method for Part (c) } public boolean isValid() { // Complete this method for Part (d) } public boolean lessThan(int parentKey) { // OPTIONAL: Complete this method for Part (d) } public boolean greaterThan(int parentKey) { // OPTIONAL: Complete this method for Part (d) } // Print a representation of this set's B-tree, useful during debugging. public void print(int indent) { final int EXTRA_INDENTATION = 4; int i; int space; // Print the indentation and the data from this node for (space = 0; space   135 71 4 2 9 6  135 71 4 2 9 6

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 Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

12th edition

133544613, 978-0133544619

More Books

Students also viewed these Databases questions