CPSC 220 HW2: Trees

  1. Draw a tree whose preorder traversal is a b c d e and whose inorder traversal is b a d c e.

  2. Draw a tree whose inorder traversal is f a g b h d i c j e and whose postorder traversal is f g a h i d j e c b.

  3. Give an example of a binary tree with more than one node whose inorder and postorder traversals yield the same list of nodes.

  4. Find two different trees that have the same list of nodes under a preorder traversal.

  5. For your BinaryTree class from prog1, write a recursive method int height() that returns the height of the tree.

  6. For your BinaryTree class from prog1, write a recursive method int numNodes() that returns the number of nodes in the tree.