






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
Material Type: Assignment; Professor: Samet; Class: Data Structures; Subject: Computer Science; University: University of Maryland; Term: Unknown 1989;
Typology: Assignments
1 / 12
This page cannot be seen from the preview
Don't miss anything!







Programming Assignment 1: A Data Structure For Game Programming Applications^1
Abstract Designing interactive games is a challenging task that requires good understanding of spatial data structures. In this assignment you are required to handle data similar to that used in game programming. In such an environment the primary entities are small rectangles and the problem in which we are interested is how to manage a large collection of them. In the following we trace the development of a variant of the quadtree data structure that can be used for such a problem. Your task is to implement this data structure in such a way that a number of operations can be efficiently handled. An example JAVA applet for the data structure can be found on the home page of the class. This assignment is divided into four parts. PASCAL is the preferred programming language although you may use C or C++. For the first two parts, you must read the attached description of the problem and data structure. A detailed explanation of the assignment including the specification of the operations which you are to implement is found at the end of the description. After you have done this, you are to turn in a proposed implementation of the data structure using PASCAL’s (or C or C++) record (structure) definition facility. One week later you must turn in a PASCAL (or C or C++) program for the command decoder (i.e., scanner for the commands corresponding to the operations which are to be performed on the data structure). For the third part, you are to write a PASCAL (or C or C++) program to implement the data structure and operations (1)-(8). For the fourth part, you are to implement operations (9)-(13). Operations (14)-(16) are optional and you will get extra credit if you turn them in with part four.
(^1) Copyright c 2005 by Hanan Samet. No part of this document may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the express prior permission of the author.
The quadtree is a member of a class of hierarchical data structures that are based on the principle of recursive decomposition. As an example, consider the point quadtree of Finkel and Bentley [1] which should be familiar to you as it is simply a multidimensional generalization of a binary search tree. In two dimensions each node has four subtrees corresponding to the directions , , , and . Each subtree is commonly referred to as a quadrant or subquadrant. For example, see Figure 1.6^2 where a point quadtree of 8 nodes is presented. In our presentation we shall only discuss two- dimensional quadtrees although it should be clear that what we say can be easily generalized to more than two dimensions. For the point quadtree the points of decomposition are the data points themselves (i.e., in Figure 1.6, Chicago at location (35,40) subdivides the two dimensional space into four rectangular regions). Requiring the regions to be of equal size leads to the region quadtree of Klinger [4,5,6]. This data structure was developed for representing homogeneous spatial data and is used in computer graphics, image processing, geographical information systems, pattern recognition, and other applications. For a history and review of the quadtree representation, see pp. 1-16 in [5].
As an example of the region quadtree, consider the region shown in Figure 1.1a which is rep- resented by a 2^3 23 binary array in Figure 1.1b. Observe that 1’s correspond to picture elements (termed pixels) which are in the region and 0’s correspond to picture elements that are outside the region. The region quadtree representation is based on the successive subdivision of the array into four equal-size quadrants. If the array does not consist entirely of 1’s or 0’s (i.e., the region does not cover the entire array), then we subdivide it into quadrants, subquadrants, ... until we obtain blocks (possibly single pixels) that consist entirely of 1’s or entirely of 0’s. For example, the result- ing blocks for the region of Figure 1.1b are shown in Figure 1.1c. This process is represented by a quadtree in which the root node corresponds to the entire array, the four sons of the root node repre- sent the quadrants, and the leaf nodes correspond to those blocks for which no further subdivision is necessary. Leaf nodes are said to be BLACK or WHITE depending on whether their corresponding blocks are entirely within or outside of the region respectively. All non-leaf nodes are said to be GRAY. The region quadtree for Figure 1.1c is shown in Figure 1.1d.
There are a number of ways of adapting the region quadtree to represent point data. If the domain of data points is discrete, then we can treat data points as if they are BLACK pixels in a region quadtree. If this is not the case, then the data points cannot be represented since the minimum separation between the data points is unknown. This leads us to an adaptation of the region quadtree to point data which associates data points (that need not be discrete) with quadrants. In order to avoid confusion with the point and region quadtrees we call the resulting data structure a PR quadtree (P for point and R for region).
The PR quadtree is organized in the same way as the region quadtree. The difference is that leaf nodes are either empty (i.e., WHITE) or contain a data point (i.e., BLACK) and the values of its coordinates. A quadrant contains at most one data point. For example, Figure 2.32 is the PR quadtree corresponding to the data of Figure 1.6. Note that, unlike the region quadtree, when a non-terminal node has four BLACK sons, they are not merged. This is natural since a merger of
(^2) All numbered figures of the form X.YY and page numbers refer to [5] while all numbered figures of the form ZZ are found in this document.
A
J
I
H^ G
F
B
C
E
D