Binary Tree Traversals Exercises

  1. Given the following tree, write the values of the nodes in the order that they are traversed.

    Preorder Traversal:




    Inorder Traversal:




    Postorder Traversal:




  2. Given the following (or this code in a visualizer): write driver code to create a BT object that stores the following binary tree:
  3. Complete the {pre,in,post}OrderTraverse methods in the BT class by adding recursive methods. Each of these recursive methods should be based off of the traverse method by adding the call "visit( root );" (and changing the name of the recursive method calls):
    public void traverse( BinNode<E> root ){
        if( root == null ){
            return;
        }
    
        traverse( root.left() );
        traverse( root.right() );
    }
    Add calls to the {pre,in,post}OrderTraverse methods in your driver code and make sure that it matches what you came up with in the first part.

Last Modified: