TreeMaps
Chapter: TreeMaps
Read the Java API documentation about Maps, especially TreeMap.
Start a new Eclipse project with the name "countTreeMap". Load the same files
that you found in "countTreeVector" into that new project. You will see that in
the TestTree class there are a number of lines where I have added comments
beginning "// You need to change this..." Those are the lines you will need
to change so that, instead of augmenting the Binary Search Tree with a crude Vector of StringCountPairs, you will augment it with a Map. The key field will be String, and the value field will be Integer. Replace the Vector with a
TreeMap. (In the next exercise you will replace the Vector with a HashMap.) Remember
you need to specify the type parameters for these with String for K and
Integer for V. When you have made the indicated changes, the program
should work as before (but a lot faster). It will also be possible for you
to delete the StringCountPair class from the project.
Now for some math or some simulation -- your choice. You should find your code in the exercise you just completed runs a whole lot faster than my original Vector code.
By trying out the code with files of various sizes, estimate (or, by doing the math, derive and prove) the big Oh
running times of - read a file
- search
using the TreeMap. In your lab notebook write some conclusions about
the performance of TreeMap instead of the Vector.
rhyspj@gwu.edu