YCP Logo Assignment 4: Dictionary Implementation

Due: Monday, Apr 4th by 11:59 PM

Getting Started

Download CS350_Assign4.zip. Import it into your Eclipse workspace (File->Import...->General->Existing projects into workspace->Archive File). You will see a project called CS350_Assign4 in the Package Explorer.

Your Task

You have two tasks:

  1. Implement several dictionary classes using varying underlying concrete data structures.
  2. Benchmark the performance of the various dictionary implementations.

Implementation

Your task is to implement the HashDictionary, LinkedListDictionary, SkipListDictionary, and (optionally) AATreeDictionary classes.

Your implementations should be asymptotically efficient. Specifically, for the put, get, and remove operations,

  • HashDictionary should have O(1) average case running time,
  • SkipListDictionary should have O(log N) average case running time, and
  • AATreeDictionary should have O(log N) worst case running time

Note that the LinkedListDictionary class will have O(N^2) worst and average case running times for its operations.

You can use the provided JUnit tests to test your implementations of these classes.

You may use your linked list class from Lab 1 as a basis for your implementation of LinkedListDictionary. You may use your work on Lab 3 and Lab 4 as a starting point for SkipListDictionary and HashDictionary.

Benchmarking

Write a benchmark that tests the amount of time required, for each dictionary class except LinkedListDictionary, to insert increasing numbers of keys into a dictionary and then verify that all keys were added successfully. Plot a series for each dictionary class. (Note: you can omit AATreeDictionary if you did not implement it.)

You can use the System.currentTimeMillis() method to record timestamps.

Use enough keys that you can see clear trends. (I used 40,000 to 400,000 keys.)

The resulting plot should look something like this:

figures/dictBench.png

Note that my data doesn't prove that AA-trees are faster than skip lists --- it just shows that my implementation of AA-trees is faster than my implementation of skip lists.

Approach

You can get an 80/100 on this assignment by implementing just the put and get operations for LinkedListDictionary, SkipListDictionary, and HashDictionary, and benchmarking these classes. Focus on doing these tasks first.

Implementing the remove method for the above classes will allow you to get a grade of up to 95/100.

If you are feeling ambitious, try implementing AATreeDictionary (for a grade of up to 115/100.)

Hints

The SkipListDictionary and AATreeDictionary classes require that the key type K implements the Comparable interface. So, you can use the compareTo method to compare keys.

Unlike the skip list implementation in Lab 3, the SkipListDictionary class uses a type parameter K for the key data type rather than int. So, you will not be able to hard-code the NIL_KEY value as the maximum possible key. One possibility is to have the skip list class's constructor take the nil key value as a parameter. If you do this, you will need to modify the create method in the SkipListDictionaryTest and SkipListDictionaryRemoveTest test classes.

Also, the skip list implementation in Lab 3 did not have values associated with its keys. You will need to change the node type to store keys as well as values. Here is one possible implementation:

public class YSkipListNode<K,V> {
        public K key;
        public V value;
        public Node<K,V>[] forward;

        public (K key, V value, int level) {
                this.key = key;
                this.value = value;
                this.forward = (YSkipListNode<K,V>[]) new YSkipListNode[level + 1];
        }
}

You will need to modify the YSkipList class to use this new node type, and to change the methods to use K as the key type and to return values of type V as the result of the put, get, and remove operations.

Restrictions

Do not use java.util data structure implementations

In this course, you are required to implement all data structures from scratch. Do not use any of the data structure implementation classes in the java.util package, such as LinkedList, Stack, HashMap, etc.

You may use the other classes and interfaces in java.util. For example StringTokenizer is fine to use, as are the exception classes (such as NoSuchElementException.)

Please see me if you have any questions about which classes are OK to use.

Do not copy code from textbook or other sources

Some assignments in this course may involve data structures which are implemented by source code in the textbook. And, of course, lots of code is available from web sites and other sources.

I expect you to implement all data structures and algorithms from scratch, using your knowledge of how they work. Do not copy code from any source, including the textbook.

Grading Criteria

  • LinkedListDictionary put and get: 20%
  • HashDictionary put and get: 20%
  • SkipListDictionary put and get: 20%
  • LinkedListDictionary remove: 5%
  • HashDictionary remove: 5%
  • SkipListDictionary remove: 5%
  • Benchmark: 20%
  • AATreeDictionary put, get, and remove: 20%

Submitting

Export your finished project to a zip file (right-click on the project, then Export...->Archive File). Upload the zip file to the marmoset server as project assign4. The server URL is

https://camel.ycp.edu:8443/

IMPORTANT: after uploading, you should download a copy of your submission and double-check it to make sure that it contains the correct files. You are responsible for making sure your submission is correct. You may receive a grade of 0 for an incorrectly submitted assignment.