6 Comments Already

commenter
OJ Said,
July 23rd, 2008 @7:14 pm  

How flexible is this question? More specifically, are we supposed to iterate through the tree given just the root tree node? or are we able to be creative in the construction of the tree (so long as it remains a binary tree)?

commenter
Aaron Said,
July 23rd, 2008 @7:44 pm  

@OJ — I’ve tweaked the question a bit to hopefully answer your questions. I always try to leave a little wiggle room for some creativity … but within limits. :)

commenter
OJ Said,
July 23rd, 2008 @8:41 pm  

Much better ;) There was too much room to move if we had control over constructing the tree ourselves.

So we can assume that all we have is a reference to a root node of the tree. And the structure for the node would be simply:

struct TreeNode { TreeNode* left; TreeNode* right; T value; }

commenter
Aaron Said,
July 23rd, 2008 @9:42 pm  

That’s the hard part about doing these on paper like this – there’s less of an opportunity to “tune” the questions. Thanks for asking ….! :)

commenter
Aaron Said,
July 23rd, 2008 @9:43 pm  

(And yes, you’re right about the basic structure of the tree node).

commenter
OJ Said,
July 24th, 2008 @5:03 pm  

I guess we’ll have to resort to the tried-and-true stack-based approach then ;)

Related Post

Please Leave Your Comments Below

Please Note: All comments are moderated, so it may take some time before your comment appears.