Algorithm I -- Range-Searchinging in Dictionary for Points

Table of contents:

Go back previous page

Quadtrees

Consider we have n points $S = \{(x_0,y_0), (x_1,y_1), \cdots , (x_{n-1}, y_{n-1}) \}$ in the plane.

Assume: All points are within a square R

How to build the quadtree on S:

Quadtree Dictionary Operations:

Quadtree Range Search

kd-trees

Constructing kd-trees

Build kd-tree with initial split by x on points S:

Analysis

kd-tree height

Assume first that the points are in general position(no two points have the same x/y-coordinate)

kd-tree Dictionary Operations

kd-tree Range Search

    kd-Tree RangeSearch(T,R,A) T: The root of a kd-tree, R: region associated with T, A: query rectangle
  1. $\quad$ if ($R\subset A$) then report all points in T; return
  2. $\quad$ if ($R\cap A$ is empty) then return
  3. $\quad$ if (T sotres a single point p) then
  4. $\qquad$ if p is in A return p
  5. $\qquad$ else return
  6. $\quad$ if T stores split "is x < X"
  7. $\qquad R_{l} = R \cup \{(x,y) : x < X\}$
  8. $\qquad R_{r} = R \cup \{(x,y) : x \ge X\}$
  9. $\qquad$ kdTree-RangeSearch(T.left, $R_l$, A)
  10. $\qquad$ kdTree-RangeSearch(T.right, $R_r$, A)
  11. $\quad$ else
  12. $\qquad R_{l} = R \cup \{(x,y) : y < Y\}$
  13. $\qquad R_{r} = R \cup \{(x,y) : y \ge Y\}$
  14. $\qquad$ kdTree-RangeSearch(T.left, $R_l$, A)
  15. $\qquad$ kdTree-RangeSearch(T.right, $R_r$, A)
  16. kdexample

kd-Tree Range Search Complexity

Range Trees

BST Range Search

    BST-RangeSearch(T, $k_1$, $k_2$)

    T: root of a binary search tree, $k_1$, $k_2$: search keys
    Return keys in T that are in range[$k_1,k_2$]
  1. $\quad$ if T = null then return
  2. $\quad$ if $k_1 \le key(T) \le k_2$ then
  3. $\qquad$ L = BST-RangeSearch(T.left, $k_1,k_2$)
  4. $\qquad$ R = BST-RangeSearch(T.right, $k_1,k_2$)
  5. $\qquad$ return $L\cup \{key(T)\} \cup R$
  6. $\quad$ if key(T) < $k_1$ then
  7. $\qquad$ return BST-RangeSearch(T.right, $k_1,k_2$)
  8. $\quad$ if key(T) > $k_2$ then
  9. $\qquad$ return BST-RangeSearch(T.left, $k_1,k_2$)

Note: Keys are reported in in-order, i.e. in sorted order.

range-search-demo range-search-demo range-search-demo range-search-demo range-search-demo

Range Search Summary

Range Search Analysis

Range Trees: Query Run-time

Range Trees: Higher Dimensions

Back To Top