PR quadtree. public class prquadtree< T extends Compare2D<? super T> > {

Similar documents
CS 3114 Data Structures and Algorithms DRAFT Minor Project 3: PR Quadtree

CS 3114 Data Structures and Algorithms DRAFT Project 2: BST Generic

PR Quadtree Implementation

Solution READ THIS NOW! CS 3114 Data Structures and Algorithms

CS 3114 Data Structures and Algorithms READ THIS NOW!

CS 1044 Program 6 Summer I dimension ??????

struct _Rational { int64_t Top; // numerator int64_t Bottom; // denominator }; typedef struct _Rational Rational;

For storage efficiency, longitude and latitude values are often represented in DMS format. For McBryde Hall:

CS 2604 Minor Project 1 DRAFT Fall 2000

Each line will contain a string ("even" or "odd"), followed by one or more spaces, followed by a nonnegative integer.

gcc o driver std=c99 -Wall driver.c bigmesa.c

CS 3114 Data Structures and Algorithms Test 1 READ THIS NOW!

Organizing Spatial Data

gcc o driver std=c99 -Wall driver.c everynth.c

// Initially NULL, points to the dynamically allocated array of bytes. uint8_t *data;

CS3114 (Fall 2013) PROGRAMMING ASSIGNMENT #2 Due Tuesday, October 11:00 PM for 100 points Due Monday, October 11:00 PM for 10 point bonus

You will provide an implementation for a test driver and for a C function that satisfies the conditions stated in the header comment:

Given that much information about two such rectangles, it is possible to determine whether they intersect.

Decision Logic: if, if else, switch, Boolean conditions and variables

CS 2604 Minor Project 1 Summer 2000

A rectangle in the xy-plane, whose sides are parallel to the coordinate axes can be fully specified by giving the coordinates of two opposite corners:

Both parts center on the concept of a "mesa", and make use of the following data type:

Creating a String Data Type in C

The assignment requires solving a matrix access problem using only pointers to access the array elements, and introduces the use of struct data types.

For this assignment, you will implement a collection of C functions to support a classic data encoding scheme.

Pointer Casts and Data Accesses

Here is a C function that will print a selected block of bytes from such a memory block, using an array-based view of the necessary logic:

CS 2704 Project 1 Spring 2001

A Capacity: 10 Usage: 4 Data:

Generic BST Interface

Pointer Accesses to Memory and Bitwise Manipulation

File Navigation and Text Parsing in Java

CS 2604 Minor Project 3 Movie Recommender System Fall Braveheart Braveheart. The Patriot

Pointer Accesses to Memory and Bitwise Manipulation

Programming Standards: You must conform to good programming/documentation standards. Some specifics:

CS 2704 Project 3 Spring 2000

Pointer Accesses to Memory and Bitwise Manipulation

CS 1044 Project 2 Spring 2003

File Navigation and Text Parsing in Java

CS ) PROGRAMMING ASSIGNMENT 11:00 PM 11:00 PM

Here is a C function that will print a selected block of bytes from such a memory block, using an array-based view of the necessary logic:

CS2304 Spring 2014 Project 3

Geographic Information System version 1.0

Computational Geometry

The Program Specification:

CS 1044 Program 2 Spring 2002

CS 1044 Project 1 Fall 2011

Fundamental Concepts: array of structures, string objects, searching and sorting. Static Inventory Maintenance Program

Geographic Information System

CS 3114 Data Structures and Algorithms READ THIS NOW!

Writeup for first project of CMSC 420: Data Structures Section 0102, Summer Theme: Threaded AVL Trees

Simple C Dynamic Data Structure

CS61B Lecture #21: Tree Searching. Last modified: Wed Oct 12 19:23: CS61B: Lecture #21 1

3. When you process a largest recent earthquake query, you should print out:

CS 2604 Minor Project 3 DRAFT Summer 2000

Data Structures and Algorithms

Solution printed. Do not start the test until instructed to do so! CS 2604 Data Structures Midterm Spring Instructions:

Module 8: Range-Searching in Dictionaries for Points

Maps and Trees. CS310: Program 2. 1 Overview. 2 Requirements. Instructor Provided Files. Late Work: Up to 72 hours Penalty: 10% per 24

B-Trees. Based on materials by D. Frey and T. Anastasio

Data Structure and Algorithm Homework #3 Due: 2:20pm, Tuesday, April 9, 2013 TA === Homework submission instructions ===

a f b e c d Figure 1 Figure 2 Figure 3

BST Implementation. Data Structures. Lecture 4 Binary search trees (BST) Dr. Mahmoud Attia Sakr University of Ain Shams

ASSIGNMENT 4 Classes and Objects

CIS 121 Data Structures and Algorithms with Java Spring 2018

Data Structures and Algorithms

CSE 143 Final Part 1, August 18, 2011 Sample Solution

Augmenting Data Structures. General approach Dynamic order statistics Interval trees

Advanced Java Concepts Unit 5: Trees. Notes and Exercises

CS 342 Software Design Fall 2018 Term Project Part II Addition of Artifacts and Data File Processing

CMPSCI 187 / Spring 2015 Sorting Kata

We assume uniform hashing (UH):

Solution printed. Do not start the test until instructed to do so! CS 2604 Data Structures Midterm Summer I Instructions:

AP Computer Science A

Advanced Algorithm Design and Analysis (Lecture 12) SW5 fall 2005 Simonas Šaltenis E1-215b


Assignment 4. Aggregate Objects, Command-Line Arguments, ArrayLists. COMP-202B, Winter 2011, All Sections. Due: Tuesday, March 22, 2011 (13:00)

Programming Languages and Techniques (CIS120)

Do not start the test until instructed to do so!

CS210 Project 5 (Kd-Trees) Swami Iyer

Comp Intermediate Programming EXAM #2 March 30, 2005 Rice University - Instructors: Cox & Nguyen

Inheritance and Interfaces

Assignment3 CS206 Intro to Data Structures Fall Part 1 (50 pts) due: October 13, :59pm Part 2 (150 pts) due: October 20, :59pm

Project 1. due date Sunday July 8, 2018, 12:00 noon

Accessing Data in Memory

Notes on Project 1. version September 01, 2014

CS61B Lecture #20. Today: Trees. Readings for Today: Data Structures, Chapter 5. Readings for Next Topic: Data Structures, Chapter 6

Prelim 2. CS 2110, November 20, 2014, 7:30 PM Extra Total Question True/False Short Answer

Prelim 2, CS :30 PM, 25 April Total Question Name Short Search/ Collections Trees Graphs

University of Illinois at Urbana-Champaign Department of Computer Science. Second Examination

Geometric Algorithms. Geometric search: overview. 1D Range Search. 1D Range Search Implementations

CMPSCI 187 / Spring 2015 Hangman

TREES Lecture 12 CS2110 Fall 2016

Algorithms GEOMETRIC APPLICATIONS OF BSTS. 1d range search line segment intersection kd trees interval search trees rectangle intersection

If you took your exam home last time, I will still regrade it if you want.

Computer Science 385 Design and Analysis of Algorithms Siena College Spring Lab 8: Search Trees Due: Start of your next lab session

CMPSCI 187 / Spring 2015 Implementing Sets Using Linked Lists

CSE 143, Winter 2010 Final Exam Thursday, March 18, 2010

CS 2505 Computer Organization I Test 2. Do not start the test until instructed to do so! printed

Homework Assignment #3

Transcription:

PR quadtree This assignment involves implementing a point-region quadtree (specifically the PR quadtree as described in section 3.2 of Samet s paper) as a Java generic. Because this assignment will be auto-graded using a test harness we will provide, your implementation must conform to the public interface below, and include at least all of the public and private members that are shown: The test harness will belong to the following package; the quadtree implementation must belong to it as well. In addition, the quadtree implementation must specify package access for the node types and tree members so that the test harness may have access to it. package Minor.P3.DS; public class prquadtree< T extends Compare2D<? super T> > { abstract class prquadnode {... class prquadleaf extends prquadnode { ArrayList<T> Elements; class prquadinternal extends prquadnode { prquadnode NW, NE, SE, SW; prquadnode root; long xmin, xmax, ymin, ymax;... Initialize quadtree to empty state, representing the specified region. Pre: xmin < xmax and ymin < ymax public prquadtree(long xmin, long xmax, long ymin, long ymax) {... Pre: elem!= null Post: If elem lies within the tree's region, and elem is not already present in the tree, elem has been inserted into the tree. Return true iff elem is inserted into the tree. public boolean insert(t elem) {... Pre: elem!= null Returns reference to an element x within the tree such that elem.equals(x)is true, provided such a matching element occurs within the tree; returns null otherwise. public T find(t Elem) {... Pre: elem!= null Post: If elem lies in the tree's region, and a matching element occurs in the tree, then that element has been removed. Returns true iff a matching element has been removed from the tree. public boolean delete(t Elem) {... Pre: xlo < xhi and ylo < yhi Returns a collection of (references to) all elements x such that x is in the tree and x lies at coordinates within the defined rectangular region, including the boundary of the region. public ArrayList<T> find(long xlo, long xhi, long ylo, long yhi) {... Version 3.01 This is a purely individual assignment! 1

You may safely add features to the given interface, but if you omit or modify members of the given public interface you will be likely to face compilation errors when you submit your implementation for testing. You must implement tree traversals recursively, not iteratively. You will certainly need to add a number of private recursive helper functions that are not shown above. Since those will never be called directly by the test code, the interfaces are up to you. For this assignment, the bucket size is 1; that is, each leaf node will store exactly one data object. That said, you must still use an ArrayList object to store the single data element in the leaf node; that will help you later when you convert this implementation to a fully bucketed approach. Note that the test harness for this assignment is shallower than the one for the BST project. That is, aside from checking the root pointer, it does not attempt to examine the internal structure of your quadtree at all. Instead, tree displays, written by the test driver, are compared to determine whether your tree has the correct structure. Therefore, the restrictions on the node types are extremely flexible. On the other hand, your implementation must be designed to work with data objects that implement the following interface: package Minor.P3.DS; The interface Compare2D is intended to supply facilities that are useful in supporting the use of a generic 2D spatial structure with a user- defined data type. As a consequence, the interface contains a number of redundant features; it is unlikely that any particular PR quadtree implementation would make use of every feature shown here. public interface Compare2D<T> { Returns the x-coordinate field of the user data object. public long getx(); Returns the y-coordinate field of the user data object. public long gety(); Returns indicator of the direction to the user data object from the location (X, Y) specified by the parameters. The indicators are defined in the enumeration Direction, and are used as follows: NE: vector from (X, Y) to user data object has a direction in the range [0, 90) degrees (relative to the positive horizontal axis NW: same as above, but direction is in the range [90, 180) SW: same as above, but direction is in the range [180, 270) SE: same as above, but direction is in the range [270, 360) NOQUADRANT: location of user data object is equal to (X, Y) public Direction directionfrom(long X, long Y); Returns indicator of which quadrant of the rectangle specified by the parameters that user data object lies in. The indicators are defined in the enumeration Direction, and are used as follows, relative to the center of the rectangle: NE: user data object lies in NE quadrant, including non-negative x-axis, but not the positive y-axis NW: user data object lies in the NW quadrant, including the positive y-axis, but not the negative x-axis SW: user data object lies in the SW quadrant, including the Version 3.01 This is a purely individual assignment! 2

negative x-axis, but not the negative y-axis SE: user data object lies in the SE quadrant, including the negative y-axis, but not the positive x-axis NOQUADRANT: user data object lies outside the specified rectangle public Direction inquadrant(double xlo, double xhi, double ylo, double yhi); Returns true iff the user data object lies within or on the boundaries of the rectangle specified by the parameters. public boolean inbox(double xlo, double xhi, double ylo, double yhi); The interface is intended to allow your implementation to either take coordinates from the data object (via getx() and gety()) and use those values to make directional decisions, or to use the directionfrom() method supplied by the data object for the same purpose. The only restriction is that if you take the first approach you must make sure that your logic follows the following pattern when partitioning the world space: Positive y-axis belongs to the NW quadrant Center point belongs to the NE quadrant Positive x-axis belongs to the NE quadrant Negative x-axis belongs to the SW quadrant Negative y-axis belongs to the SE quadrant The actual test data will be created so that (ideally) no data points will ever lie on a region boundary. However, you should conform to the guideline above just to be safe. One more note, we specifically require that the equals() and directionfrom() methods are consistent, in the sense that equals() returns true if and only if directionfrom() returns NOQUADRANT. We are specific about this because the Java language specification does, in fact, allow an inconsistency between equals() and compareto(). The Compare2D interface depends upon the following enumerated type: package Minor.P3.DS; public enum Direction {NW, SW, SE, NE, NOQUADRANT; The use of an enumerated type allows us to use descriptive labels at critical points in the implementation. If you have not made use of this Java feature before, this is a good place to learn about it. Version 3.01 This is a purely individual assignment! 3

During our testing of your implementation, we will use the following data object type; a more complete version is posted on the course website. package Minor.P3.Client; import Minor.P3.DS.Compare2D; import Minor.P3.DS.Direction; public class Point implements Compare2D<Point> { private long xcoord; private long ycoord; public Point() { xcoord = 0; ycoord = 0; public Point(long x, long y) { xcoord = x; ycoord = y; public long getx() { return xcoord; public long gety() { return ycoord; public Direction directionfrom(long X, long Y) {... public Direction inquadrant(double xlo, double xhi, double ylo, double yhi) {... public boolean inbox(double xlo, double xhi, double ylo, double yhi) {... public String tostring() {... public boolean equals(object o) {... Additional methods as needed...... Note that if you use calls to directionfrom()or inquadrant() or inbox()in your quadtree you must implement those methods to be consistent with the directional guidelines given on the previous page. BTW, I put the class Point in the package Minor.P3.Client because, on the one hand, it needs to be in a package so my test class can import it, and, on the other hand, it doesn't seem to make sense to put a user data type into a package intended for data structures. Version 3.01 This is a purely individual assignment! 4

Design and implementation requirements There are some explicit requirements, in addition to those on the Programming Standards page of the course website: You must implement the PR quadtree to conform to the specification. The insertion logic must not allow duplicate (according to equals()) records to be inserted. The insertion logic must not allow the insertion of records that lie outside the world boundaries. Under no circumstances should any of the PR quadtree member functions write output, except for a display() method and its helper, if you choose to implement that (the test harness will never call such a method). When carrying out a region search, you must determine whether the search region overlaps with the region corresponding to a subtree node before descending into that subtree. The Java libraries include a Rectangle class which could be (too) useful. You may not make use of the Rectangle class from the Java library, but it is acceptable to make use of those methods during development of a solution to this assignment. When carrying out a region search, the order in which you add elements to the vector does not matter, since the testing code will sort the elements before considering them. Naturally, your implementation of region search should be efficient; therefore, it must not look at subtrees that could not possibly contain elements that fall in to the specified region. This will be checked by the course TAs. Testing and Evaluation We will be testing your implementation with a stand-alone test harness. A version of that harness is posted as a Linux tar file: grade.sh prquadgenerator.jar LogComparator.jar testdriver.java Minor/P3/Client/Point.java Minor/P3/DS/Compare2D.java Minor/P3/DS/Direction.java Minor/P3/DS/prQuadTree.java Minor/P3/DS/Lewis.class shell script to drive testing process test case generator tool for comparing and scoring test output main Java file for test harness data type for insertion into PR quadtree during testing* type bound for PR quadtree generic parameter enumerated type used in Compare2D PR Quadtree implementation* test methods * shell files that you must complete in order to run the testing code After unpacking the test harness, you must implement the Point type and the PR quadtree in order to perform testing. Specifically, you must implement the parts of the Point type related to the elements of the Compare2D interface that your PR quadtree makes use of. You can restrict which methods in the PR quadtree are tested by commenting out sections of the main test driver file, testdriver.java. You can run the test harness with the command: grade.sh [-repeat] Run the script first without the optional repeat switch; use that switch if you want to reuse randomized test cases created by an earlier testing run. Examine the various log files for the details of the scoring. There is no guarantee that any particular run of the test harness will create every possible logical case. It is your responsibility to perform testing of your implementation before submitting it. For that purpose, you may share test code (but absolutely no tree code!!) via the class Forum. Be sure you test all of the interface elements thoroughly, both in isolation and in interleaved fashion. Do not include any testing code in your submission, including calls to JUnit elements. You should document your implementation in accordance with the Programming Standards page on the course website. It is possible that your implementation will be evaluated for documentation and design, as well as for correctness of results. If so, your final submission will be evaluated by one of the TAs, who will assess a deduction (ideally zero) against your score from the testing harness. Version 3.01 This is a purely individual assignment! 5

What to turn in and how This assignment will be auto-graded using a stand-alone test harness, running on a CentOS 7 system, using Java version 1.8.0u25 or later. Submit a single.java file (not zipped) containing your PR quadtree generic to the Curator System. Submit nothing else. Your solution should not write anything to standard output. Instructions, and the appropriate link, for submitting to the Curator are given in the Student Guide at the Curator website: http:www.cs.vt.edu/curator/. You will be allowed to submit your solution multiple times; the highest score will be counted. Pledge Each of your program submissions must be pledged to conform to the Honor Code requirements for this course. Specifically, you must include the following pledge statement at the beginning of the file that contains main(): On my honor: - I have not discussed the Java language code in my program with anyone other than my instructor or the teaching assistants assigned to this course. - I have not used Java language code obtained from another student, or any other unauthorized source, either modified or unmodified. - If any Java language code or documentation used in my program was obtained from another source, such as a text book or course notes, that has been clearly noted with a proper citation in the comments of my program. - I have not designed this program in such a way as to defeat or interfere with the normal operation of the grading code. <Student's Name> We reserve the option of assigning a score of zero to any submission that does not contain this statement. Change Log Relative to Version 3.00 If changes are made to the specification, details will be noted below, the version number will be updated, and an announcement will be made on the course Forum board. 3.00 Base document. Posted on February 7. 3.01 Updated instructions for using the posted testing harness. Version 3.01 This is a purely individual assignment! 6