• + 0 comments

    This problem description needs a bit of work - I do appreciate the examples and their clarity as I was able to deduce the actual index recording rules from them. That said, the provided instructions for recording the index values of a tree were wrong.

    From the instructions:

     - it is the first node visited, the first time visited
     - it is a leaf, should only be visited once
     - all of its subtrees have been explored, should only be visited once while this is true
     - it is the root of the tree, the first time visited
    

    This is not correct (doesn't match their provided solutions). This implies we record the first node visited, which will always be the left or right child of the root node. This also implies that if a node has a left and right child, we record the value of the node only after exploring both the left and right sub-trees. The examples make it clear that this is not the case.

    The actual logic for printing values seems to be: "record an index whenever arriving at a node and its left subtree is fully explored (true if there is no left sub-tree)". Note that this handles leaf nodes since they have no left subtree.

    i.e. the traversal logic to get the indices in the order they want is: traverse tree in an in-order, depth first way. Record the index for a node when arriving at that node AND that node's left subtree has been fully explored - happens when: - arriving at a node and it has no left sub-tree - arriving at a node from its left sub-tree

    I spent most of my time on this problem figuring that part out, which was frustrating