Title: Multidimensional Binary Search Trees Used for Associative Searching
1Multidimensional Binary Search Trees Used for
Associative Searching
- Jon Louis Bentley
- Stanford University
- Communications of the ACM, September 1975, vol.
18, no. 9 - 1975 ACM Student Award
- Paper Second Place
2Notations
- Let P be a set of n points in the plane.
- A 2-dimensional rectangle range query on P asks
for the points from P lying inside a query
rectangle x xy y. - A point p(px,py) lies inside this rectangle if
and only if x?px?x and y?py?y.
3Construction
- Algorithm BUILDKDTREE(P,depth)
-
- //Input A set of points P and the current depth.
- //Output The root of a kd-tree storing P.
- 1. if P contains only one point then
- 2. return a leaf storing this point
- 3. else if depth is even then
- 4. Split P into two subsets with a
vertical line l through the median x-coordinate
of the points - in P. Let P1 be the set of points to the left and
P2 be the set of points to the right. Points
exactly on - the line belong to P1.
- 5. else
- 6. Split P into two subsets with a
horizontal line l through the median
y-coordinate of the points - in P. Let P1 be the set of points above l and P2
be the points below l. Points exactly on the line
belong - to P1.
- 7. Vright BUILDKDTREE(P1,depth1)
4Query
Algorithm SEARCHKDTREE(v,R) Input. The root of
a (subtree of a) kd-tree and a range R. Output.
All points at leave below v that lie in the
range. 01 if v is a leaf 02 Report the point
stored at v if it lies in R. 03 else 04 if
region(lc(v)) is fully contained in R 05
ReportSubtree(lc(v)) 06 else 07 if
region(lc(v)) intersects R 08
SEARCHKDTREE(lc(v),R) 09 if region(rc(v)) is
fully contain in R 10 ReportSubtree(rc(v)) 11
else 12 if region(rc(v)) intersects R 13
SEARCHKDTREE(rc(v),R)
5Insertion
6Demo
- http//www.rolemaker.dk/nonRoleMaker/uni/algogem/k
dtree.htm
7Discussion
- Priority search trees v.s. Kd-trees