Recitation 12

Introduction

In this recitation, you will practice conceptual questions regarding binary trees and binary search trees.

Questions

  1. For the three questions below, consider these keys (in this order):
    1. Show the results of adding the search keys to an initially empty binary search tree
    2. What ordering of the search keys above would result in the most balanced tree if they were added to an initially empty binary search tree?
    3. Give four orderings of the search keys above that would result in the least balanced tree if they were added to an initially empty binary search tree.
  2. Consider the full binary tree pictured below. Now imagine that you traverse the tree and save its data in a file. If you then read the file and add the data to an initially empty binary search tree, what tree will you get if the traversal was each of the three tree traversal methods?
  3. Imagine that you traverse a binary search tree and save its data in a file. If you then read the file and add the data to an initially empty binary search tree, what traversal should you use when writing the file so that the new tree is (a) as tall as possible or (b) identical to the original tree?
  4. Draw the unique binary tree that has the following preorder and inorder traversals:
  5. Draw the unique binary tree that has the following postorder and inorder traversals:
  6. Give an example of two different binary trees with the same preorder and postorder traversals.
  7. What is the height of the shortest binary tree that contains 21 nodes? Is the tree full?

Submission and Grading

This is for your practice. You should be able to complete some of the functions by the end of recitation. If you complete a function, call the TA over to look over your function to make sure it is correct. If you do not have time to complete the programs before the end of recitation, you have the option of uploading it to CourseWeb once you are finished to receive feedback on it from the TA. If you upload it after Monday, December 7, please email the TA so he knows to look at it.