CSci 160 Lab 6: A Tale of Two Trees (and one Hash Table)
Objectives
The goal behind this lab is to do some
experiments to see first-hand some differences in the
performance of binary search trees, AVL trees, and closed
hash tables.
Exercises
- Start by downloading the following files:
Put them all in the same BlueJ project.
- In each of these classes, add an instance variable for "counting
the number of steps for an insertion." This means different things for
the different structures:
- For the ordinary binary search tree, it is simply the number
of recursive calls to the private insert() method. This is
the same as the number of comparisons that are made. Just an
increment at the beginning of the private insert() method does
the trick.
- For the AVL tree, to be fair to the other structures, we should also
count rotations, in addition to the comparisons we count
for unbalanced BSTs.
- For the hash table, it's the number of probes. You need to
put an increment in the appropriate loop in the method findPos().
Also add a public method for returning the number of steps (call it
"getSteps()") in each of the above classes. The purpose of the method is to
return the number of steps taken just after an insertion has been performed.
- Note that the main methods do a whole lot of insertions and removals. Let's make
it simpler: They should just do a whole bunch of insertions (determined
by the constant NUMS). Delete/modify the existing code accordingly.
Also add code to the main methods so that after all the insertions are made,
the total number of steps (in all the insertions) is printed
out. Finally, make it so that NUMS acquires its value via a command-line
argument, so you can try out different values each time you run
the code.
- Let's put these search structures through their paces.
Run all the programs on
10-15 values of NUMS. Start at (say) 10000 and working your
way up to 100000 (in steps of 10000), or skip some steps and get up to
larger NUMS such as 180000 or 200000.
- Observe (and record) the numbers that come out. Graph the numbers
as a function of NUMS (that value we usually call "N"!). How would
you interpret these graphs? Are they consistent with what we know
about these data structures?
Hand in: Electronic copies of the modified programs, with changes clearly indicated with comments.
Also hand in written answers to the above questions, and clearly annotated graphs of the points (on the same graph for comparison).
Last modified: 10/25/10 by Frederic Green.