[The following talks about "three projects." Only the first two of the three are assigned projects to be turned in. The third (one left-leaning red-black trees) is recommended for practice, but does not need to be turned in.]
The goal of these next three projects (AVL trees, traditional red-black trees, and left-learning red-black trees) Is to understand how these three balanced binary search tree strategies work by implementing them. The three projects will use the same code base, and in some ways can be seen as a single, big project. Splitting them up into three projects, however, will help you spread out the work on them; for example, you are encouraged to start work on the AVL tree project (described here) after we learn AVL trees rather than waiting until we learn all the varieties of trees.
This project appears in the book as Project 5.1 on page 372 and Project 5.2 on page 385 (we're combining these into two for the purposes of how we're organizing things in the course).
As mentioned before, the code base is the same for all three
projects,
and this section will give an overview of the whole code.
Copy the given code from ~tvandrun/Public/cs345/bst
and make an Eclipse project for it.
As usual, you will find adt
, impl
,
and test
packages;
additionally there are packages
except
containing exception classes
and exper
containing and experiment.
(These projects don't require you to do anything with the experiment,
but it's included in case you want to play around with it for
your own learning.)
As seen page 233 in the book for a UML diagram of the relevant classes and interfaces for this series of projects.
Your tasks will be to finish the "Balancer" classes that fixup trees after put operations based on either the AVL, Traditional-Red-Black, or Left-Leaning-Red-Black approach.
Implement the methods rotateLeft()
and
rotateRight()
in class impl.BSTMap
,
as is described in Section 5.2 and Project 5.1.
Project 5.1 refers to a test.RotateTest
JUnit
test class, but unfortunately I haven't written that yet.
The correctness of your rotations will be tested
implicitly by the tests in the next part.
putFixup()
for AVL treesWrite the body of AVLBalancer.putFixup()
,
as described in Project 5.2.
Test using AVLBSTMTest
.
(Note that this test case will test your rebalancing on both
put and remove operations.
The subsequent projects (as assigned) will not
require you to implement fixups after removes, but
for AVL trees fixup after remove is identical to fixup after put.)
AVLBSTMTest
has two exceptions that it
throws when a tree doesn't conform to AVL specifications.
ImbalanceException
is thrown when a node
has a balance less than -1 or greater than 1.
IgnorantNodeException
is thrown when
the "info" for a node is incorrect for the structure of the
subtree rooted at that node.
Copy the files you modified (BSTMap.java
and AVLBalancer.java
)
to your turn-in folder /cslab/class/cs345/(your id)/avl
.
To keep up with the course, this should be finished by March 18.