CMSI 281
Homework #6

Read [Gray], Chapters 10-12. Consider the "Checkpoint" questions as part of your reading assignment: answer them but don't turn in your answers. You are encouraged to do all of these because many of the quiz and final exam questions will be based on these.

Please provide professionally crafted solutions to the following:

  1. For the following tree

    anotherexampletree.png

    1. What are the leaves?
    2. What are the children of D?
    3. What is the depth of G?
    4. What is the degree of G?
    5. What are the ancestors of G?
    6. What are the descendants of G?
    7. What are the nodes on level 3?
    8. What is the height of the tree?
    9. What is the width of the tree?
    10. What is the degree of the tree?
    11. Enumerate the nodes in breadth-first order.
    12. Enumerate the nodes in depth-first order.
  2. What is the height of a complete k-ary tree of n nodes?
  3. Draw all 14 binary trees of size 4. Circle the ones that are complete trees.
  4. Prove or disprove: "If every proper subtree of a binary tree is perfect, then the tree itself must be perfect."
  5. Add a toString method to the LinkedBinaryTreeNode class from the course notes.
  6. Write a BinaryTreeUtils class with the following methods:

    Important: The "tree" operated on by these operations should be of type BinaryTreeNode from the course notes.

  7. Show the binary search tree that results from inserting, in order (into an initially empty tree), the integers 20 6 4 8 15 22 11 13 14. Repeat for an AVL tree, a red-black tree, a splay tree, a (2,3)-tree, and a (2,4)-tree.
  8. For each of the following, say whether the statment is true or false, and prove (YES, I SAID PROVE) your answer.
    1. Every subtree of a BST is another BST
    2. Every subtree of an AVL tree is another AVL tree
    3. Every subtree of a red-black tree is another red-black tree
    4. If both the left and right subtrees of a binary tree T are BSTs, then T must be a BST.
    5. If the same keys are inserted in a different order to build a BST, then the resulting BST will be the same
    6. It T is a BST, and both the left and right subtrees of T are AVL trees, then T must be an AVL tree
  9. Construct your own map interface and hashtable-based implementation from scratch. Call the interface Dictionary and the implementation HashDictionary so as not to get confused with the standard Java classes. Details to follow.

Organize your work in your CVS repository. The following is the suggested structure:

homework
  cmsi281
    src
      main
        docs
          hw6.tex
          <diagram source files>, if any
          <images>, if any
        java
          edu
            lmu
              cs
                collections
                  LinkedBinaryTreeNode.java (implements BinaryTreeNode)
                  BinaryTreeUtils.java
                  BinaryTreeNode.java (from course notes)
                  Dictionary.java (interface)
                  HashDictionary.java (class)
      test
        java
          edu
            lmu
              cs
                collections
                  ListUtilsTest.java
                  BinaryTreeUtilsTest.java
                  HashDictionaryTest.java

Your LaTeX file will contain solutions to each problem, numbered, and in order. You may embed source code in the document, or give the answer as "See <filename>" and submit the sources for these answers at the end of the document. Generate a pdf from the LaTeX file and hand in a printed copy. Only turn in printed copies of your own files; do not waste trees by printing the sources for the code I gave you.

Notes