Question: Project Closest Value in a Binary Search Tree (BST) Without using an iterator, create a new method called closestValue) that takes an Object value and

 Project Closest Value in a Binary Search Tree (BST) Without using

Project Closest Value in a Binary Search Tree (BST) Without using an iterator, create a new method called closestValue) that takes an Object value and then locates a value in the tree that is closest to this Object. If the root of the tree is NULL, your method should throw an InvalidTreeArgument exception. The prototype for this method should be the following object BST::closestvalue(object value); For example, suppose you have the following BST 32 24 41 21 28 36 47 14 25 31 39 closestValuel 10) should return 14. closestValue (20) should return 21 closestValuel 42 ) should return 41. HINT: The answer returned will come from the nodes found on the path followed as if the Object parameter is getting inserted into the tree. HINT: Use recursion and pass additional parameters that keep track of the closest value you have seen so far. Pass this closest value by reference so that future recursive calls can update this parameter as additional nodes are encountered Create a test driver program that exercises each of these methods, prints the tree and the results of each operation

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!