Coding Challenge #15

Coding Challenge Series / Technical Interview Series

Create a structure which represents a binary tree. Iterate through all of the elements of the tree in any order, without using recursion.

Update: Your function is only provided the root of the constructed tree. A tree node should contain no more than the child node pointers and the data.


  1. 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)?

  2. @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. :)

  3. 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; }

  4. 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 ….! :)

Comments are closed.