The "simple" answer is correct in this case: the exercise is solved by first converting the trees into lists (in fact, ordered lists because we're doing inorder traversal of the trees), then using ordered-set procedures, and finally converting the resulting sets back into trees. Why is this correct? because the procedure described achieves the required O(n)
complexity using already-existing procedures - no need to reinvent the wheel!
Although a "direct" answer can be written by manipulating trees, it's too much of a hassle, and it'll be very tricky (if not impossible!) to implement in O(n)
without using mutation operations - and up to this point in the book, we have not yet used set!
, set-car!
or set-cdr!
.