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:
- For the following tree

- What are the leaves?
- What are the children of D?
- What is the depth of G?
- What is the degree of G?
- What are the ancestors of G?
- What are the descendants of G?
- What are the nodes on level 3?
- What is the height of the tree?
- What is the width of the tree?
- What is the degree of the tree?
- Enumerate the nodes in breadth-first order.
- Enumerate the nodes in depth-first order.
- What is the height of a complete k-ary tree of n nodes?
- Draw all 14 binary trees of size 4. Circle the ones that are
complete trees.
- Prove or disprove: "If every proper subtree of a binary tree is perfect,
then the tree itself must be perfect."
- Add a
toString method to the LinkedBinaryTreeNode class
from the course
notes.
- Write a BinaryTreeUtils class with the following methods:
- size(tree) — the number of nodes in the tree
- width(tree) — the width of the tree
- leaves(tree) — the set of objects in the leaves of the tree
- mirror(tree) — the mirror image of the tree
- height(tree) — the height of the tree
Important: The "tree" operated on by these operations
should be of type BinaryTreeNode from the course notes.
- 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.
- For each of the following, say whether the statment is true
or false, and prove (YES, I SAID PROVE) your answer.
- Every subtree of a BST is another BST
- Every subtree of an AVL tree is another AVL tree
- Every subtree of a red-black tree is another red-black tree
- If both the left and right subtrees of a binary tree T are BSTs,
then T must be a BST.
- If the same keys are inserted in a different order to
build a BST, then the resulting BST will be the same
- It T is a BST, and both the left and right subtrees of
T are AVL trees, then T must be an AVL tree
- 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
- You are encouraged to enter your old work from
previous homework assignments into your repository as well.
This way you can build up a repository of all of your
coursework at LMU.)
- Submissions that are not exactly in the form above will be
downgraded heavily. The directory structure must be exactly
as shown above, and all files must be named exactly as shown
above, etc.
- Code that does not compile will get a zero.