Hi,
Question 2 in HW assignment 5 had a "find closest key" method (binary tree).
I got all the points for it but I feel that there must be a shorter way (code wise) to implement the solution. The main problem is that in our version of the binary tree class there is no way to access the parent node. In order to find the closest key one must keep in mind that once we do reach the bottom of the tree to the supposed closest leaf the number on whom we are implementing the method may be a successor or a predecessor of a closer node up the tree (rather than the leaf on the bottom). We cant travel back up to check that, therefore that entails using very hefty extra code (in an envelope recursion) to keep in mind the node our current position is a predecessor or a successor of.
I was wondering if the course staff or anyone else has a relatively short correct implementation of this method..Or, does the way this class is built in this case mean that the only way is in fact to use an envelope recursion (not talking about a short one) and keep the closest key along the way in order to compare it to that final leaf.
Thanks
Question regarding Binary Trees