Question: Write a Java program called CompareBSTandAVL to determine and print the number of comparisons performed when inserting a set of keys into an AVL tree

Write a Java program called CompareBSTandAVL to determine and print the number of comparisons performed when inserting a set of keys into an AVL tree and into a BST. To do this, modify the versions of the BST and AVL classes found below. Edit them so that each contains an instance variable for counting how often a comparison is performed (that is, every time the compareTo method is called for a key). You will also need to add an accessor method to retrieve that count.

The program itself should:

Create a BST and an AVL tree for keys of type String and values of type Long.

Fill each of those trees with counts of the words in the text file data/tale.txt.

Print for each tree how many comparisons were performed in filling it.

Next, fill an array list with integer values read from data/8kints.txt.

Create new trees for keys of type Integer and values of type Boolean.

Fill those trees with the integer values read in the array list.

Print the comparison counts.

Finally, sort the array list and repeat the previous three steps.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!