CSCI 151 - Data Structures and Object-Oriented Development
Spring 2015
Lab 14: Word Counts, part 3: Tries
- For this lab, we will reimplement the WordCounter interface using
tries.
- Download the provided code.
- The code for these labs will be incorporated into the editor.wordcount package.
- The code includes the following files:
-
editor.wordcount
package
- Trie.java: An implementation of WordCounter using a trie.
- This is one of two files you will modify.
- Within the file, modify the following methods:
- Implement
get()
to perform a retrieval from the trie. Return 0 if the word is not present.
- Implement
bump()
to try to find the word in the trie. If the word is present, increase its count. If the word is not present, you will need to add it to the trie, adding one node per character that is not already there.
- Implement
dock()
to try to find the word in the trie, and decrease its count if it is there. Otherwise, do nothing.
- You will also need to implement the
Iter
class, which represents a trie iterator. You'll want to use a stack to keep track of which Trie object is the next to be visited by the iterator.
- TrieListSorted.java: An implementation of a sorted list of Trie objects.
- This is one of two files you will modify.
- It is used in the Trie class to represent a list of children of
the current node.
- This list is sorted based on the
getChar()
value for
each Trie
object.
- Within the file, modify the following methods:
- Implement
insert()
to insert a Trie into the list.
This should maintain the sorted ordering, based on getChar()
.
- Implement
get()
to retrieve a Trie from the list. This should use binary search.
- TrieTest.java: Unit tests for Trie.java.
- TrieTestRevised.java: Revised unit tests for Trie.java.
- TimeTest.java: Program that compares the running times of different
WordCounter implementations using Moby Dick. This version includes a
test for our hash table implementation, so as to compare it to the others.
- Once your solution is working, run
TimeTest
to compare its
performance with the sorted-array version from Lab 10
and the hash table from Lab 11.
Grading
For an A+, pass all unit tests from TrieTestRevised.java. Also, provide the timing information gleaned
from TimeTest via Moodle when submitting. The performance of the trie
array should be drastically superior to that of the array implementation,
and should be fairly close to the performance of the hash table.
Without this, the grade is as follows:
Number of Unit Tests Passed | Grade |
15 | B |
7 | C |
2 | D |