Problem

A point quadtree is a 4-way tree used to represent points on a plane (Samet 2006). A node...

A point quadtree is a 4-way tree used to represent points on a plane (Samet 2006). A node contains a pair of coordinates (latitude,longitude) and pointers to four children that represent four quadrants: NW, NE, SW, and SE. These quadrants are generated by the intersection of the vertical and horizontal lines passing through point (lat,lon) of the plane. Write a program that accepts the names of cities and their geographical locations (lat,lon) and inserts them into the quadtree. Then, the program should give the names of all cities located within distance r from a location (lat,lon) or, alternatively, within distance r from a city C.

Figure 1 contains an example. Locations on the map in Figure 1a are inserted into the quadtree in Figure 1b in the order indicated by the encircled numbers shown next to the city names. For instance, when inserting Pittsburgh into the quadtree, we check in which direction it is with respect to the root. The root stores the coordinates of Louisville, and Pittsburgh is NE from it; that is, it belongs to the second child of the root. But this child already stores a city, Washington. Therefore, we ask the same question concerning Pittsburgh with respect to the current node, the second child of the root: in which direction with respect to this city is Pittsburgh? This time the answer is NW. Therefore, we go to the first child of the current node. The child is a null node, and therefore, the Pittsburgh node can be inserted here.

The problem is to not have do an exhaustive search of the quadtree. So, if we are after cities within a radius r from a city C, then, for a particular node nd you find the distance between C and the city represented by nd. If the distance is within r, you have to continue to all four descendants of nd. If not, you continue to the descendants indicated by the relative positions. To measure a distance between cities with coordinates (lat1, lon1) and (lat2, lon2), the great circle distance formula can be used:s assuming that the earth radius R = 3,956 miles and latitudes and longitudes are expressed in radians (to convert decimal degrees to radians, multiply the number of degrees by π/180 = 0.017453293 radians/degree). Also, for the directions west and south, negative angles should be used.

d = R arccos(sin(lat1) · sin(lat2) + cos(lat1) · cos(lat2) · cos(lon2lon1))

For example, to find cities within the distance of 200 miles from Pittsburgh, begin with the root and d((38,85),(40,79)) = 350, so Louisville does not qualify, but now you need to continue only in the SE and NE descendants of Louisville after comparing the coordinates of Louisville and Pittsburgh. Then you try Washington, which qualifies (d = 175), so, from Washington you go to Pittsburgh and then to both Pittsburgh’s descendants. But when you get to the NE node from Washington, you see that New York does not qualify (d = 264), and from New York you would have to continue in SW and NW descendants, but they are null, so you stop right there. Also, Atlanta needs to be checked.

Figure 1 A map indicating (a) coordinates of some cities and (b) a quadtree containing the same cities.

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 7
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT