Computational Geometry: Range Trees
Computational Geometry: Range Trees
2D Range trees
Degenerate cases
Range trees
Computational Geometry
Database queries
G. Ometer
born: Aug 16, 1954
salary salary: $3,500
19,500,000 19,559,999
date of birth
2 Computational Geometry Lecture 8: Range trees
Introduction
2D Range trees Range queries
Degenerate cases
Result
Result
Faster queries
Faster queries
Faster queries
Faster queries
Build a tree so that the leaves correspond to the different
possible query rectangle types (corners in same cells of grid),
and with each leaf, store all answers (points) [or: the count]
Faster queries
Faster queries
Faster queries
49
23 80
10 37 62 89
3 19 30 49 59 70 89 93
3 10 19 23 30 37 59 62 70 80 93 97
49
split node
23 80
10 37 62 89
3 19 30 49 59 70 89 93
3 10 19 23 30 37 59 62 70 80 93 97
data structure
for searching on
y-coordinate
(5, 9)
(3, 8)
(6, 7)
(1, 5)
(9, 4)
(7, 3)
(4, 2)
(8, 1)
2D range trees
Construction algorithm
Algorithm Build2DRangeTree(P)
1. Construct the associated structure: Build a binary search
tree T assoc on the set Py of y-coordinates in P
2. if P contains only one point
3. then Create a leaf ν storing this point, and make
Tassoc the associated structure of ν.
4. else Split P into Pleft and Pright , the subsets ≤ and >
the median x-coordinate xmid
5. νleft ← Build2DRangeTree(Pleft )
6. νright ← Build2DRangeTree(Pright )
7. Create a node ν storing xmid , make νleft the left
child of ν, make νright the right child of ν, and
make Tassoc the associated structure of ν
8. return ν
23 Computational Geometry Lecture 8: Range trees
Construction
Introduction
Querying
2D Range trees
Higher dimensions
Degenerate cases
Fractional cascading
Efficiency of construction
T(1) = O(1)
Efficiency of construction
Efficiency of construction
T(1) = O(1)
2D range queries
2D range queries
ν
p
µ µ0 p p
Query algorithm
Algorithm 2DRangeQuery(T, [x : x0 ] × [y : y0 ])
1. νsplit ←FindSplitNode(T, x, x0 )
2. if νsplit is a leaf
3. then report the point stored at νsplit , if an answer
4. else ν ← lc(νsplit )
5. while ν is not a leaf
6. do if x ≤ xν
7. then 1DRangeQ(Tassoc (rc(ν)), [y : y0 ])
8. ν ← lc(ν)
9. else ν ← rc(ν)
10. Check if the point stored at ν must be reported.
11. Similarly, follow the path from rc(νsplit ) to x0 . . .
2D range queries
µ µ0
∑ O(log nν + kν )
ν
Result
Efficiency
√
n log n log2 n n
16 4 16 4
64 6 36 8
256 8 64 16
1024 10 100 32
4096 12 144 64
16384 14 196 128
65536 16 256 256
1M 20 400 1K
16M 24 576 4K
Storage
Query time
Result
Comparison for d = 4
1 2 3 5 8 13 21 34 55 S1
1 3 5 8 13 21 34 55 S2
1 3 13 21 34 55 S3
3 34 55 S4
1 2 3 5 8 13 21 34 55 S1
1 3 5 8 13 21 34 55 S2
1 3 13 21 34 55 S3
3 34 55 S4
1 2 3 5 8 13 21 34 55 S1
1 3 5 8 13 21 34 55 S2
1 3 13 21 34 55 S3
3 34 55 S4
1 2 3 5 8 13 21 34 55 S1
1 3 5 8 13 21 34 55 S2
1 3 13 21 34 55 S3
3 34 55 S4
1 2 3 5 8 13 21 34 55 S1
1 3 5 8 13 21 34 55 S2
1 3 13 21 34 55 S3
3 34 55 S4
[6,35]
1 2 3 5 8 13 21 34 55 S1
1 3 5 8 13 21 34 55 S2
1 3 13 21 34 55 S3
3 34 55 S4
Fractional cascading
Fractional cascading
Fractional cascading
Fractional cascading
17
8 52
5 15 33 58
2 7 12 17 21 41 58 67
2 5 7 8 12 15 21 33 41 52 67 93
(2, 19) (7, 10) (12, 3) (17, 62) (21, 49) (41, 95) (58, 59) (93, 70)
(5, 80) (8, 37) (15, 99) (33, 30) (52, 23) (67, 89)
Fractional cascading
3 10 19 23 30 37 49 59 62 70 80 89 95 99
3 10 19 37 62 80 99 23 30 49 59 70 89 95
10 19 37 80 3 62 99 23 30 49 95 59 70 89
19 80 10 37 3 99 62 30 49 23 95 59 70 89
19 80 10 37 3 99 49 30 95 23 89 70
Fractional cascading
8 52
5 15 33 58
2 7 12 17 21 41 58 67
2 5 7 8 12 15 21 33 41 52 67 93
(2, 19) (7, 10) (12, 3) (17, 62) (21, 49) (41, 95) (58, 59) (93, 70)
(5, 80) (8, 37) (15, 99) (33, 30) (52, 23) (67, 89)
Fractional cascading
3 10 19 23 30 37 49 59 62 70 80 89 95 99
3 10 19 37 62 80 99 23 30 49 59 70 89 95
10 19 37 80 3 62 99 23 30 49 95 59 70 89
19 80 10 37 3 99 62 30 49 23 95 59 70 89
19 80 10 37 3 99 49 30 95 23 89 70
Fractional cascading
3 10 19 23 30 37 49 59 62 70 80 89 95 99
3 10 19 37 62 80 99 23 30 49 59 70 89 95
10 19 37 80 3 62 99 23 30 49 95 59 70 89
19 80 10 37 3 99 62 30 49 23 95 59 70 89
19 80 10 37 3 99 49 30 95 23 89 70
Fractional cascading
Result
Degenerate cases
Degenerate cases
Degenerate cases
Degenerate cases