binary trees :: exercises

  1. For the binary tree shown above, identify each of the following:
    1. the root of the tree
    2. the leaves of the tree
    3. the nodes of the left subtree
    4. the children of the root of the right subtree
    5. a pair of siblings
    6. the nodes of the left subtree of the right subtree of the root
    7. a node with no parent
    8. the left child of the root of the left subtree

  2. In what order would the nodes of the following tree be visited using:
    1. an inorder traversal
    2. a postorder traversal
    3. a preorder traversal

  3. The diagram shows an expression tree with operands at the leaves and operators at the other nodes
    1. The value of a non-empty expression tree is obtained by applying the operator at the root to the value of the left subtree and the value of the right subtree. Find the value of the given expression tree.
    2. In what order would the nodes of the tree be visited using:
      1. preorder traversal
      2. inorder traversal
      3. postorder traversal

  4. An expression tree visited in postorder, gives the following expression:
  5. 2 3 + 5 4 2 - + *
    1. Draw the expression tree and find its value
For answers click here