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 ASE value is defined (Wiener and Pinson) as the Average Search 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)
}
ASE = sum / n

When the average search effort (i.e. the ASE 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 MinASE as the minimum value of ASE and MaxASE as the maximum value of ASE. MinASE value for a BST with n nodes, corresponds to the ASE value calculated for a BST of height floor(log n) + 1 which has all levels completely full, except for the last level. For a balanced BST, its ASE value equals MinASE. MaxASE value for a BST with n nodes represents the ASE value calculated for a BST which degenerates into a linear linked list with n nodes.

Part 1

For the BST class (Liang, Listing 27.5), design and implement the methods indicated below and integrate them into the existing class. Compile the BST class with the new added methods.

  • calculateASE, calculates the ASE value according to the above algorithm;
  • calculateMinASE, calculates the minimum value of the ASE;
  • calculateMaxASE, calculates the maximum value of the ASE;
  • calculateTreeHeight, calculates tree height;
  • needsBalancing, evaluates whether this BST needs to be balanced or not. We consider that a BST needs to be balanced when its ASE value is less than K * MinASE where K = 1.25;
  • balanceBST, executes the balance operation on this BST;

Part 2

Design and implement a driver program TestBST.java 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 key values taken from an input file. In the input file, the key 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) post-order tree traversal, (3) calculateASE, (4) calculateMinASE, (5) calculateMaxASE, (6) calculateTreeHeight, (7) needsBalancing, (8) balanceBST, (9) insert new 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 key values of the tree nodes should be shown to the console or, as a result of executing the calculateASE method, the ASE value should be displayed to the console).

Notes.

  • Additional (housekeeping) methods such as calculating the number of nodes at a certain level in the tree may be necessary to be defined.
  • If an operation requires additional information, the user will be prompted to enter it.
  • You may assume that there are no errors in the input file structure.
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.