Generate 10 random values between 0 and 8000 add these


Compare the performance of two binary search trees as more objects are added to them. Initially, one tree is balanced and the other is not.

First modify BinarySearchTreeInterface and BinarySearchTree so that the add method returns the number of comparisons used. Then write a program that uses the new version of BinarySearchTree, as follows. Create two empty binary search trees. Associate two variables with each tree. One variable sums the number of comparisons used in adding values to a tree, and the other sums the heights of a tree at certain times following the insertion of several values. Name these variables comparisonSum1, comparisonSum2, heightSum1, and heightSum2.
In a loop that executes 100 times, do the following:

• Add the values 1000, 2000, 3000, 4000, 5000, 6000, and 7000 to both trees. In the first tree, add them in increasing order. In the second, add them in an order that forms a complete tree. Your first tree will be unbalanced, while the second tree will be balanced.

• Generate 10 random values between 0 and 8000. Add these values to each tree in the same order. After each of these additions, update each tree's comparisonSum variable by the number of comparisons performed for the insertion.

• Add each tree's height to its heightSum variable.

• Clear the two trees.

After the loop ends, compute the average number of comparisons needed to insert values into each tree. (For each tree, divide its comparisonSum by 1000. Note that 1000 is 100-the number of iterations-multiplied by 10-the number of values inserted in one iteration.) Also compute the average height of each tree after the insertions. (Divide each heightSum variable by 100.) Display and record your results. Run the program a second time, but instead add 100 random values between 0 and 8000 during each iteration of the loop. Run it a third time, but instead add 1000 random values. Discuss your results and draw a conclusion.

Request for Solution File

Ask an Expert for Answer!!
Basic Computer Science: Generate 10 random values between 0 and 8000 add these
Reference No:- TGS02196162

Expected delivery within 24 Hours