Assignment 5: k-d Tree

Objectives

Introduction

wavyleaf basketgrass Sirex woodwasp
Images from 1) Wikipedia user keisotyo, licensed under CC BY-SA 3.0 and 2) David R. Lance, USDA APHIS PPQ, Bugwood.org

Imagine an invasive species tracking app that allows users to submit the geographic coordinates of the locations of invasive species. Environmental organizations could then use the data to organize eradication efforts. To best allocate resources, the organizations may wish to send eradication teams to the most heavily infested areas. It would be helpful to know, for a set of candidate areas to treat, which areas have the most reports of infestation.

an aerial photo with markers indicating 21 reports
	      of wavyleaf basketgrass; 3 rectangles are shown
	      as examples of ranges, with 4, 5, and 6 markers
	      inside each rectangle respectively
A set of 21 reported locations of infestations by invasive species, and three possible ranges to send response teams to. The middle range has more reports of infestation than the others.

A kd-tree is a data structure that allows for efficient range queries over a set of points: given the coordinates of the edge of a (spherical) rectangular region, determine (or simply count) which points in the set are within the region. A kd-tree is a binary search tree that rotates which coordinate it compares at each level of the tree. So for 2-dimensional data, the root might compare on x-coordinate and then the children of the root would compare on y-coordinate, then grandchildren of the root on x-coordinate again, and so on.

Overview

Complete the implementation of the functions described in kdtree.h from the /c/cs223/hw5/Required/ directory. The functions define a set-of-points ADT with the ability to create a set from an array of points, add, find, and remove points, and to find points that are with a certain range.

The functions should run in the following worst-case time bounds.

Where $n$ is the number of points in the set, and the bounds apply only then the tree is balanced, and apply as expected time bounds when the tree is approximately balanced. Otherwise the bounds are $O(n)$ (except for kdtree_create, which must always run in $O(n \log n)$ time). All time bounds assume that malloc and free run in $O(1)$ time.

Your implementation should work with the main function in kdtree_unit.c also found in /c/cs223/hw5/Required/ along the location module. There is no other executable required for this assignment.

Details

Suggestions

Submissions

Submit your makefile, log file, and source code necessary to build the Unit executable. Note that since there is no other main exectuable to create for this assignment, the name of the executable used for testit is Unit. Your makefile should assume that the files from /c/cs223/hw5/Required have been copied into the current directory but not that they are still in their original locations, and you should not submit those files.