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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Sec. 13.3 Sp<strong>at</strong>ial <strong>D<strong>at</strong>a</strong> <strong>Structures</strong> 447CADBEFFigure 13.14 Searching in the k-d treeof Figure 13.11. (a) The k-d tree decompositionfor a 128 × 128-unit region containing seven d<strong>at</strong>a points. (b) The k-d treefor the region of (a).priv<strong>at</strong>e void rshelp(KDNode rt, int[] point,int radius, int lev) {if (rt == null) return;int[] rtkey = rt.key();if (InCircle(point, radius, rtkey))System.out.println(rt.element());if (rtkey[lev] > (point[lev] - radius))rshelp(rt.left(), point, radius, (lev+1)%D);if (rtkey[lev] < (point[lev] + radius))rshelp(rt.right(), point, radius, (lev+1)%D);}Figure 13.15 The k-d tree region search method.Figure 13.15 shows an implement<strong>at</strong>ion for the region search method. Whena node is visited, function InCircle is used to check the Euclidean distancebetween the node’s record <strong>and</strong> the query point. It is not enough to simply checkth<strong>at</strong> the differences between the x- <strong>and</strong> y-coordin<strong>at</strong>es are each less than the querydistances because the the record could still be outside the search circle, as illustr<strong>at</strong>edby Figure 13.13.13.3.2 The PR quadtreeIn the Point-Region Quadtree (hereafter referred to as the PR quadtree) each nodeeither has exactly four children or is a leaf. Th<strong>at</strong> is, the PR quadtree is a full fourwaybranching (4-ary) tree in shape. The PR quadtree represents a collection ofd<strong>at</strong>a points in two dimensions by decomposing the region containing the d<strong>at</strong>a pointsinto four equal quadrants, subquadrants, <strong>and</strong> so on, until no leaf node contains morethan a single point. In other words, if a region contains zero or one d<strong>at</strong>a points, then

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

Saved successfully!

Ooh no, something went wrong!