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.
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.
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).