HashMaps
Chapter: HashMaps
This part of the lab is almost identical to the last. It should take
next to no time. Do it, nevertheless.
Read the Java API documentation about Maps, especially HashMap.
Start a new Eclipse project with the name "countHashMap". Load the same files
that you found in "countHashVector" 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
HashMap. (In the previous exercise you replaced the Vector with a TreeMap.) 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 HashMap. In your lab notebook write some conclusions about
the performance of HashMap instead of the Vector.
rhyspj@gwu.edu