Balancing binary search trees

Assignment Help JAVA Programming
Reference no: EM13673949

Balancing Binary Search Trees
1. Project Specification
The search effort for locating a node in a Binary Search Tree (BST) depends on the tree shape (topology). For a BST with n nodes the ACE value is defined (Wiener and Pinson) as the Average Comparison Effort for locating a node in a tree by summing all comparison operations for all tree nodes and dividing the result by the total number of tree nodes:
    for (int level = 0, sum = 0; level < treeHeight; level++ ) {
        sum += numberOfNodesAtLevel(level) * (level + 1)
    }
    ACE = sum / n
When the average comparison effort (i.e. the ACE value) gets over a certain threshold or after a certain number of tree insert/delete operations, for optimizing the search process, a tree balance operation should be executed resulting a tree whose height equals |_ log n _| + 1 (or floor(log n) + 1), thus requiring at most  |_ log n _| + 1 (or floor(log n) + 1) comparison operations to identify any tree node. 
For a given BST with n nodes we define MinACE as the minimum value of ACE and MaxACE as the maximum value of ACE. MinACE value for a BST with n nodes, corresponds to the ACE value calculated for a BST of height floor(log n) + 1 which has all levels completely full, except for the last level. ACE value of a balanced BST equals MinACE. MaxACE value for a BST with n nodes corresponds to the ACE value calculated for a BST which degenerates into a linear linked list with n nodes.
Part 1 
Consider the file BST.java (a link to this file is provided below for downloading purposes) which defines a generic Binary Search Tree class. 
Enhance the BST class with the following methods for doing experiments of balancing binary search trees.
treeHeight, calculates tree height;
nodeBalanceLevel calculates the balance level of a given node as the difference between the height of its left subtree and the height of its right subtree;
numberOfNodesAtLevel calculates the number of nodes at the specified level;
calculateACE, calculates the ACE value according to the above algorithm;
calculateMinACE, calculates the minimum value of the ACE;
calculateMaxACE, calculates the maximum value of the ACE;
needsBalancing, evaluates whether this BST needs to be balanced or not. We consider that a BST needs to be balanced when its ACE value is greater than K * MinASE where K = 1.25;
balanceBST, executes the balance operation on this BST;
Additional methods may be added if necessary. 
The enhanced BST class should compile without errors.
Part 2
Design and implement a driver program TestBST and the test cases for testing the methods implemented in Part 1. The driver program should build an initial BST whose nodes contain positive integer values taken from an input file. In the input file, the values should be separated by the semicolon character. After building the BST, in a loop, the program should invite the user to select for execution one of the following operations: (1) in-order tree traversal, (2) pre-order tree traversal, (3) calculateACE, (4) calculateMinACE, (5) calculateMaxACE, (6) numberOfNodesAllLevels (this operation displays the number of nodes at each  level of the tree), (7) treeHeight, (8) nodeBalanceLevel (9) needsBalancing, (10) balanceBST, (11) insert value, and (0) exit the loop and the program. As a result of each operation execution, relevant information will be displayed to the user. For example, as a result of executing the in-order traversal, the values of the tree nodes should be shown to the console or, as a result of executing the calculateACE operation, the ACE value should be displayed to the console.
Notes. 
1. If an operation requires additional information, the user will be prompted to enter it.
2. The input file (a simple .txt file) should be generated by the students using a simple text editor such as Notepad.
3. You may assume that there are no errors in the input file structure.
4. Tree root is considered as located at level 0. Tree height will be considered by counting the nodes, starting with the root, along the longest path.
2. Submission Requirements
Submit the following before the due date listed in the Calendar:
1. All .java source files and the input file.2. A document file including relevant screenshots showing program execution as a result of test cases. 

Reference no: EM13673949

Questions Cloud

Modify the pseudocode design : Modify the pseudocode design
The executive summary is a brief synopsis of the paper : Completed only after the rest of the paper has been completed, the Executive Summary is a brief synopsis of the paper with a solid conclusion. Describe the central problem that will be addressed and why it was chosen. Explain the objectives and wh..
Tough face a manufacturer of rock climbing gear : Tough face a manufacturer of rock climbing gear
Display all the columns from the orders table : Display all the columns from the Orders table that were paid with a Visa Card and have been shipped to the customer (hint: not a null). Order results by the Item Price in descending order.
Balancing binary search trees : Balancing Binary Search Trees,  Consider the file BST.java (a link to this file is provided below for downloading purposes) which defines a generic Binary Search Tree class.
Calculate the quantity of energy released to a person : When 1 mol of glucose is burned, 2802.5 KJ of energy is released. Calculate the quantity of energy released to a person by eating 5.00g of glucose in a candy
Cost of flying listed below are costs : Cost of flying listed below are costs
The probability that a given bird house : The probability that a given bird house will be returned for a refund is 0.04. Suppose that 30 bird houses are sold on a particular day. Find the probability that exactly 2 of those bird houses will be returned for a refund.
An average mouse weight below that weight : if mouse weights are normally distributed with a mean weight of 23 and SD of 4. With 10 mice per box, what weight should they use so that no more than 8% of the boxes will have an average mouse weight below that weight?

Reviews

Write a Review

JAVA Programming Questions & Answers

  What is the paintcomponent method how is it used in java

q1. what is the paintcomponent method? how is it used in java graphics? how does a program intentionally cause the

  Create an array of date objects

Create an array of Date objects of size 4. Initialize the array by using a loop. In the loop, use the Scanner.nextLine() method to input a date as a string, convert it to a date by using the toDate() method, and assign the result to an element in ..

  Write a class encapsulating a pc-based game

Write a class encapsulating a PC-based game, which inherits from Game. A PC-bases game has the following additional attributes: the minimum megabytes of RAM needed to play the fame, the number of megabytes needed on the hard drive to install the fame..

  Class to initialize values

Create a constructor that allows a user of the class to initialize values. Also create a method named SetJustSold()(Hint ++) that increments the number of hot dogs the stand has sold by one and should also increase the TotalSold by one

  Variable of type string that has been assigned

Assume that word is a variable of type string that has been assigned a value. Write an expression whose value is a string consisting of the last three characters of the value word. So if if the value if word were "biggest" the expression's value w..

  Method to store the product of the two arrays in third array

Write a method to store the product of the two arrays in the third array

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Write a string expression that parenthesizes the value

Given a string varible word, write a string expression that parenthesizes the value of word. So if the word contains "sadly" the value of the expression would be the string "(sadly)".

  On any given execution your program

On any given execution your program will produce just one version of the figure. However, you should refer to the class constant throughout your code, so that by simply changing your constant's value and recompiling, your program would produce a f..

  Personalize the time zone application of section 24.3

Personalize the time zone application of Section 24.3. Prompt the user to log in and specify a city to be stored in a profile. The next time the user logs in, the time of their favorite city is displayed automatically.

  Write java program which will permit user to input data

Write the Java Program which will permit the user to input data. The data will be validated using a loop that requires the user to input the data until it is correct or in the correct range. T

  Java program that reads an input

Create a java program that reads an input of n lines with the first line being the number of people in the contest and the remaining lines a numeric 9 digit code for each person that gets a vote

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd