CSci2110 - Assignment 2
Due: Thursday February 7th by 11:55 pm (REVISED)
Revisions History:
- Created Jan. 19th,2013
Assignment Goals:
In class we are spending a lot of time considering data structures that take a single key and support insert and search operations. What happens if you have more than one key?
Consider the problem of storing n 2 dimensional points where for each point p, p.x is an integer in the range 1...2k, and p.y is an integer in the range 1...2k. We want to support the following operations:
We could simply create a list all n points and search the whole list for each query or count operations. This would give us an O(1) insert and O(n) query and count operations. But we can do better!
A quadtree is a recursive data structure for storing 2D points that is based on recursively subdividing a region into 4 equal sized quadrants. Each sub-quadrant is further divided until each point sits in its own quadrant.

A quadtree contains tree types of nodes: an internal node with four children, a node representing a quadrant containing a single point, and a node representing an empty quadrant.

One might represent a quadtree in Java as follows:

The query operation can be implemented as follows (Note: you can use an Arraylist instead of a Vector):

The insert operation can be implemented as follows:

For this assignment you are to do the following:
a) Create a Java interface called TwoDimDictionary that specifies insert, query, count and display operations.
b) Implement a simple TwoDimDictionary based on a Java Arraylist. You should create helper classes for representing points and query rectangles.
c) Implement a TwoDimDictionary based quadtrees as described above. Use the helper classes for points and query rectangles created for part b).
d) Create a testing and evaluation class which generates random points and query rectangles and evaluates your two implementations of TwoDimDictionary.
e) Perform a careful experimental evaluation of your TwoDimDictionary implementations graphing the results. You will need to use a timing method like for example:
long startTime = System.nanoTime(); methodToTime(); long endTime = System.nanoTime(); long duration = endTime - startTime;
Analysis the performance of the methods and make recommendations as to when one is preferable over the other.
Be sure follow all of the code craft requirements carefully! Be sure to do sufficient testing! You are to use only code that you have developed yourself for this assignment.
Bonus Questions:Note: No late assignments will be accepted.