840 likes | 1.39k Views
Quadtrees and Octrees. Dr. Randy M. Kaplan. Introduction. Quadtrees Hierarchical Spacial Based on - Recursive decomposition of space. Quadtree. Representation of 2-dimensional space Space is decomposed using separators Parallel to the coordinate axis Split a region into four(4) regions
E N D
Quadtrees and Octrees • Dr. Randy M. Kaplan
Introduction • Quadtrees • Hierarchical • Spacial • Based on - • Recursive decomposition of space
Quadtree • Representation of 2-dimensional space • Space is decomposed using separators • Parallel to the coordinate axis • Split a region into four(4) regions • Southwest • Northwest • Southeast • Northeast
Quadtree • A node corresponds to the region • The decomposition of the region into four(4) can be resprensented as a subtree whose - • parent is the original region • one(1) child for each decomposed region
Quadtree Region of 2D Space Region of 2D Space Region of 2D Space Region of 2D Space Region of 2D Space
Octree • 3D Analog to Quadtree • Region is split into eight(8) sub-regions • using planes parallel to the coordinate axis • A region node will have 8 children
More Than 3 Dimensions • In the case where more than 3 dimensions need to be represented the term for the data structure is • HYPEROCTREE
Quadtree/Octree • Allow space to be represented at various levels of granularity • Allows quick focusing on regions of interest • Example • Find all points in a dataset that lie within a given distance from a query point
Quadtree/Octree • Find all points in a dataset that lie within a given distance from a query point • AKA Spherical Region Query
Spherical Region Query • In the absence of any data structure • all points in the dataset will need to be analyzed • If a quadtree is available, large regions of points can be eliminated from the search
Quadtree Construction • Start with a square, cubic, or hypercubic region (depending on dimensionality of the dataset) • Decompose the initial region according to one of two strategies
Quadtree Construction • Guide decomposition by input data • Guide decomposition by principal of equal subdivision
Quadtree Construction • Guide decomposition by input data • Resulting tree size will be proportional to input • If all data is available a priori it is possible to make the tree height balanced
Quadtree Construction • Guide decomposition by input data • Although the resulting tree has desirable properties, it also has some disadvantage, i.e., • Difficult to make the data structure dynamic • Deletion of data is difficult
Quadtree Construction • Decomposition based on equal subdivision • Distribution of spacial data determines the characteristics of the resulting tree
Quadtree Construction • Decomposition based on equal subdivision • Tree will be height balanced and size will be linear when the spatial data is distributed uniformly
Quadtree Construction • Decomposition based on equal subdivision • Height and size properties deteriorate as the distribution becomes non-uniform
Termination Criteria • In the subdivision process, when is it time to stop subdividing? • Two criteria can be used in an OR or AND configuration • Resolution Requirement • Condition on Region Requirement
Ubiquity • The quadtree is a ubiquitous data structure much as the binary tree is also a ubiquitous data structure • It can be found applied to many different areas of spatial computing
Ubiquity • Computational Geometry • Computer-aided design • Computer graphics • Databases • Geographic Information Systems • Image processing • Pattern recognition
Quadtrees for Point Data • Set of n points in d dimensional space • Principle application • Organize multidimensional data • Facilitate queries requiring spatial information
Quadtrees for Point Data • Kinds of queries • Range query • Spherical region query • All nearest neighbors query
Range Query • Given a range of values for each dimension, • find all points that lie within the range • Equivalent to finding all points lying within a hyper-rectangular region
Spherical Region Query • Given, point p, radius r • Find all the points that lie within a distance r from p
Nearest Neighbor Query • Given n points, • find the nearest neighbor of each point within the set
Point Quadtrees • Point quadtree is a natural generalization of the binary search tree • We will consider the 2-dimensional case • Begin with a square region containing all of the input points
Point Quadtrees • How to Make a Quadtree • Choose an arbitrary point
Point Quadtrees • The point becomes the root of the tree
Point Quadtrees • Use lines that are parallel to the coordinate axis • Draw these lines to intersect with the chosen point to divide the region
Point Quadtrees • Each of the subregions are recursively divided in a similar way • In this way the point quadtree is produced
Point Quadtrees • When a point is on a boundary it is necessary to adopt some conventions to specify to which region the point belongs • Points lying on the left and bottom edges of a region are considered included in the region
Point Quadtrees • Points lying on the left and bottom edges of a region are considered included in the region • Points lying on the right and top edges of a region are considered not to be part of the region
Point Quadtrees • When all of the points are known in advance, it is possible to construct a balanced tree
Point Quadtrees • A simple way to accomplish this is to sort the points with one of the coordinates as the primary key • Call this primary key x • The other coordinate, y, is the secondary tree • This key is also used to sort the data
Point Quadtrees • The first subdivision point is the median of the sorted data • This insures that none of the children of the root node receives more than half the points
Point Quadtrees • O(n) time will be used to sort the data contained in each of the four subregions • The total work at every level of the tree is bounded by O(n) • At most there will be O(log n) levels in the tree • A height balanced quadtree can be built in O(nlogn) time 40
Point Quadtrees • Search • To search for a point, compare the point at the root with the point to find • If the points are different, then the point to search for is used to determine where to go next
Point Quadtrees • Search • The search continues by recursively calling the search procedure with the subregion’s root as the root of the new tree to search • The search stops if the point is found or if a leaf node is reached
Point Quadtrees • Search • The algorithm for search is O(h) where h is the height of the tree
Point Quadtrees • Insertion • Insertion is accomplished by search for the point in the tree • The search will end at a leaf • The leaf node now is a region that contains two points
Point Quadtrees • Insertion • The leaf node now is a region that contains two points • One point is chosen of the two to subdivide the region • The point becomes the child of the node representing the region where the point belongs
Point Quadtrees • The run time for insertion is bounded by O(h) • In d dimensions the run time is bounded by O(dh)
Point Quadtrees • Deletion • The node is located by search • To delete the node it is necessary to locate another point that will take its place • This is where the complexity of the algorithm for deletion lies
Region Quadtrees • A region quadtree for n points in d dimensions is defined as follows: • Consider that we have a hypercube large enough to enclose all of the points • The region is represented by the root of the d-dimensional quadtree
Region Quadtrees • The region is subdivided into 2d subregions of equal size • A subregion is subdivided by bisecting along each dimension • Each of these regions containing at least one point is represented as a child of the root node
Region Quadtrees • Each of the regions that contain at least one point is represented as the child of the root node • The same procedure is recursively applied to each child of the root node • The process is terminated when a region contains only a single point