11.07.2015 Views

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Sec. 13.3 Sp<strong>at</strong>ial <strong>D<strong>at</strong>a</strong> <strong>Structures</strong> 449ACABB(a)(b)Figure 13.17 PR quadtree insertion example. (a) The initial PR quadtree containingtwo d<strong>at</strong>a points. (b) The result of inserting point C. The block containing Amust be decomposed into four sub-blocks. Points A <strong>and</strong> C would still be in thesame block if only one subdivision takes place, so a second decomposition is requiredto separ<strong>at</strong>e them.whose y value falls in the range 0 to 63. If the root’s child is a leaf node, then th<strong>at</strong>child is checked to see if Q has been found. If the child is another internal node, thesearch process continues through the tree until a leaf node is found. If this leaf nodestores a record whose position m<strong>at</strong>ches Q then the query is successful; otherwise Qis not in the tree.Inserting record P into the PR quadtree is performed by first loc<strong>at</strong>ing the leafnode th<strong>at</strong> contains the loc<strong>at</strong>ion of P. If this leaf node is empty, then P is stored<strong>at</strong> this leaf. If the leaf already contains P (or a record with P’s coordin<strong>at</strong>es), thena duplic<strong>at</strong>e record should be reported. If the leaf node already contains anotherrecord, then the node must be repe<strong>at</strong>edly decomposed until the existing record <strong>and</strong>P fall into different leaf nodes. Figure 13.17 shows an example of such an insertion.Deleting a record P is performed by first loc<strong>at</strong>ing the node N of the PR quadtreeth<strong>at</strong> contains P. Node N is then changed to be empty. The next step is to look <strong>at</strong> N’sthree siblings. N <strong>and</strong> its siblings must be merged together to form a single node N ′if only one point is contained among them. This merging process continues untilsome level is reached <strong>at</strong> which <strong>at</strong> least two points are contained in the subtrees representedby node N ′ <strong>and</strong> its siblings. For example, if point C is to be deleted fromthe PR quadtree representing Figure 13.17(b), the resulting node must be mergedwith its siblings, <strong>and</strong> th<strong>at</strong> larger node again merged with its siblings to restore thePR quadtree to the decomposition of Figure 13.17(a).Region search is easily performed with the PR quadtree. To loc<strong>at</strong>e all pointswithin radius r of query point Q, begin <strong>at</strong> the root. If the root is an empty leaf node,then no d<strong>at</strong>a points are found. If the root is a leaf containing a d<strong>at</strong>a record, then the

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!