




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Carnegie Mellon University. 1. 95-771 Data Structures and Algorithms Project 2. Due: Tuesday, February 15, 2022, 11:59:59 PM.
Typology: Lecture notes
1 / 8
This page cannot be seen from the preview
Don't miss anything!





The objective of this assignment is to introduce the student to binary search trees and related algorithms by building a geometric application. This application will be based on 2d trees. Our primary source of information on 2d trees is from an excellent video by Robert Sedgewick found at the following link. All that you need to know about 2d trees for this assignment is contained in this video. https://www.youtube.com/watch?v=1OoM0phlO_U The primary input to your application is a comma delimited text file containing crime records from the Pittsburgh area. These data were compiled during the 1990’s (an exceptionally high crime decade in Pittsburgh). The file is named CrimeLatLonXY.csv and is found on the course schedule. For each crime record, the file contains (X, Y) coordinate pairs in the state plane coordinate system. These (X, Y) coordinates are useful for calculating the distance between points (using the Pythagorean theorem). Each record also contains latitude and longitude coordinates. These coordinates are useful for displaying locations in GIS tools such as Google Earth. The other fields are not so important for our purposes. However, all of the data contained in the file will be represented in your tree. The data structure that you will implement is a type of space- partitioning tree called a 2d Tree. We will use this data structure to store the crime records – you will store one crime record per node in the tree. Be sure to view the video mentioned above. You will write several algorithms to manipulate the tree. These algorithms will be methods found in your TwoDTree class. The TwoDTree class will be found in a file name TwoDTree.java.
Required methods of the TwoDTree class:
Note: The details involved in writing this method are found on the Sedgewick video. We will stay true to this video. In other words, alternative implementations are not allowed. Note: The ListOfCrimes class must be written by you. It will be found in a file named ListOfCrimes.java. It will provide methods for adding crimes to the list and retrieving crimes from the list. It will be built using a singly linked list with a single head pointer. It will have a toString() method to return the list as a String and a toKML() method to return a KML representation of the list. You will use the KML representation to view the crimes in Google Earth. An example KML file, containing a single crime, is shown here. You might want to load this text file into Google Earth to see how it is displayed. In your KML file, many crimes may be present. This is done by adding additional elements to the KML.
ROBBERY 5000 FORBES AV #style1
79.94295871,40.44471042,0.000000
8 ) public Neighbor nearestNeighbor(double x1, double y1) pre-condition: the 2d tree has been constructed. The (x1,y1) pair represents a point in space near Pittsburgh and in the state plane coordinate system. post-condition: the distance in feet to the nearest node is returned in Neighbor. In addition, the Neighbor object contains a reference to the nearest neighbor in the tree. Note: The details involved in writing this method are found on the Sedgewick video. We will stay true to this video. In other words, alternative implementations are not allowed. Note: The Neighbor class must be written by you. It will be found in a file named Neighbor.java. Objects of class Neighbor will contain a distance field and a pointer into the 2-d tree. Another class, TwoDTreeDriver is required. It will be contained within a separate file named TwoDTreeDriver.java. It will have a main method. When the main method is run it will load the crime data file into the 2d tree. It will interact with the user as shown below. You need not validate user input but you are required to fully implement each menu option. Only a subset of options is shown below. Output from the program is shown in blue. My comments on the execution are in parenthesis.
The crime data has been written to PGHCrimes.KML. It is viewable in Google Earth Pro. (The KML file will be named PGHCrimes.kml and will be viewable in Google Earth Pro.) What would you like to do? 1: inorder 2: preorder 3 : levelorder 4 : postorder 5: reverseLevelOrder 6: search for points within rectangle 7: search for nearest neighbor 8: quit > Enter a point to find nearest crime. Separate with a space. > 1359951.000 410726. (Again, you may assume the user enters the data correctly.) Looked at 2 7 nodes in tree. Found the nearest crime at: 1359951.481,410726.1273,32874,320 SCHENLEY RD,ROBBERY,1/1/90,140100,40.44013011,-79.
What would you like to do? 1: inorder 2: preorder 3 : levelorder 4 : postorder 5: reverseLevelOrder 6: search for points within rectangle 7: search for nearest neighbor 8: quit > Thank you for exploring Pittsburgh crimes in the 1990’s. Submission Guidelines