![Page 1: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/1.jpg)
Dr. Tamara Mchedlidze · Dr. Chih-Hung Liu · Computational Geometry Lecture Range Searching
Chih-Hung Liu · Tamara Mchledidze
Computational Geometry Lecture
INSTITUT FUR THEORETISCHE INFORMATIK · FAKULTAT FUR INFORMATIK
Range Searching
20.06.2018
![Page 2: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/2.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Geometry in Databases
In a personnel database, the employees of a company areanonymized and their monthly income and birth year aresaved. We now want to perform a search: which employeeshave an income between 2,000 and 3,000 Euro and were bornbetween 1960 and 1980?
2
![Page 3: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/3.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Geometry in Databases
In a personnel database, the employees of a company areanonymized and their monthly income and birth year aresaved. We now want to perform a search: which employeeshave an income between 2,000 and 3,000 Euro and were bornbetween 1960 and 1980?
Geometric Interpretation:Entries are points: (birth year, income level) and the query isan axis-parallel rectangle
income
birth year
2000
3000
1960 1980
2
![Page 4: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/4.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Geometry in Databases
In a personnel database, the employees of a company areanonymized and their monthly income and birth year aresaved. We now want to perform a search: which employeeshave an income between 2,000 and 3,000 Euro and were bornbetween 1960 and 1980?
income
birth year
2000
3000
1960 1980
24
children
This problem can easily be generalized to d dimensions.
2
![Page 5: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/5.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Orthogonal Range Queries
Given: n points in Rd
Output: A data structure that e�ciently answers queries ofthe form [a1, b1]⇥ · · ·⇥ [ad, bd]
3
![Page 6: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/6.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Orthogonal Range Queries
Given: n points in Rd
Output: A data structure that e�ciently answers queries ofthe form [a1, b1]⇥ · · ·⇥ [ad, bd]
Problem: Design a data structure for the case d = 1.
3
![Page 7: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/7.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Orthogonal Range Queries
Given: n points in Rd
Output: A data structure that e�ciently answers queries ofthe form [a1, b1]⇥ · · ·⇥ [ad, bd]
Problem: Design a data structure for the case d = 1.
Solution: Balanced binary search tree:Stores points in the leavesInternal node v stores pivot value xv
2
5 8 12 15
17
21 33 41
58
672 93
67582112
15
17
8
5
7
7
52
33
41
52
3
![Page 8: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/8.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Orthogonal Range Queries
Given: n points in Rd
Output: A data structure that e�ciently answers queries ofthe form [a1, b1]⇥ · · ·⇥ [ad, bd]
Problem: Design a data structure for the case d = 1.
Solution: Balanced binary search tree:Stores points in the leavesInternal node v stores pivot value xv
2
5 8 12 15
17
21 33 41
58
672 93
67582112
15
Example:Search for all points in [6,50]
17
8
5
7
7
52
33
41
52
3
![Page 9: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/9.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Orthogonal Range Queries
Given: n points in Rd
Output: A data structure that e�ciently answers queries ofthe form [a1, b1]⇥ · · ·⇥ [ad, bd]
Problem: Design a data structure for the case d = 1.
Solution: Balanced binary search tree:Stores points in the leavesInternal node v stores pivot value xv
2
5 8 12 15
17
21 33 41
58
672 93
67582112
15
Example:Search for all points in [6,50]
vsplit
6 5017
8
5
7
7
52
33
41
52
3
![Page 10: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/10.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Orthogonal Range Queries
Given: n points in Rd
Output: A data structure that e�ciently answers queries ofthe form [a1, b1]⇥ · · ·⇥ [ad, bd]
Problem: Design a data structure for the case d = 1.
Solution: Balanced binary search tree:Stores points in the leavesInternal node v stores pivot value xv
2
5 8 12 15
17
21 33 41
58
672 93
67582112
15
Example:Search for all points in [6,50]
vsplit
6 5017
86
5
7
7
52
33
41
52
3
![Page 11: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/11.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Orthogonal Range Queries
Given: n points in Rd
Output: A data structure that e�ciently answers queries ofthe form [a1, b1]⇥ · · ·⇥ [ad, bd]
Problem: Design a data structure for the case d = 1.
Solution: Balanced binary search tree:Stores points in the leavesInternal node v stores pivot value xv
2
5 8 12 15
17
21 33 41
58
672 93
67582112
15
Example:Search for all points in [6,50]
vsplit
6 5017
86
5
6
7
7
52
33
41
52
3
![Page 12: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/12.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Orthogonal Range Queries
Given: n points in Rd
Output: A data structure that e�ciently answers queries ofthe form [a1, b1]⇥ · · ·⇥ [ad, bd]
Problem: Design a data structure for the case d = 1.
Solution: Balanced binary search tree:Stores points in the leavesInternal node v stores pivot value xv
2
5 8 12 15
17
21 33 41
58
672 93
67582112
15
Example:Search for all points in [6,50]
vsplit
6 5017
86
5
6
7
6
7
52
33
41
52
3
![Page 13: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/13.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Orthogonal Range Queries
Given: n points in Rd
Output: A data structure that e�ciently answers queries ofthe form [a1, b1]⇥ · · ·⇥ [ad, bd]
Problem: Design a data structure for the case d = 1.
Solution: Balanced binary search tree:Stores points in the leavesInternal node v stores pivot value xv
2
5 8 12 15
17
21 33 41
58
672 93
67582112
15
Example:Search for all points in [6,50]
vsplit
6 5017
86
5
6
7
6
7
52
33
41
52
3
![Page 14: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/14.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Orthogonal Range Queries
Given: n points in Rd
Output: A data structure that e�ciently answers queries ofthe form [a1, b1]⇥ · · ·⇥ [ad, bd]
Problem: Design a data structure for the case d = 1.
Solution: Balanced binary search tree:Stores points in the leavesInternal node v stores pivot value xv
2
5 8 12 15
17
21 33 41
58
672 93
67582112
15
Example:Search for all points in [6,50]
vsplit
6 5017
86
5
6
7
6
7
5250
33
41
52
3
![Page 15: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/15.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Orthogonal Range Queries
Given: n points in Rd
Output: A data structure that e�ciently answers queries ofthe form [a1, b1]⇥ · · ·⇥ [ad, bd]
Problem: Design a data structure for the case d = 1.
Solution: Balanced binary search tree:Stores points in the leavesInternal node v stores pivot value xv
2
5 8 12 15
17
21 33 41
58
672 93
67582112
15
Example:Search for all points in [6,50]
vsplit
6 5017
86
5
6
7
6
7
5250
3350
41
52
3
![Page 16: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/16.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Orthogonal Range Queries
Given: n points in Rd
Output: A data structure that e�ciently answers queries ofthe form [a1, b1]⇥ · · ·⇥ [ad, bd]
Problem: Design a data structure for the case d = 1.
Solution: Balanced binary search tree:Stores points in the leavesInternal node v stores pivot value xv
2
5 8 12 15
17
21 33 41
58
672 93
67582112
15
Example:Search for all points in [6,50]
vsplit
6 5017
86
5
6
7
6
7
5250
3350
4150
52
3
![Page 17: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/17.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Orthogonal Range Queries
Given: n points in Rd
Output: A data structure that e�ciently answers queries ofthe form [a1, b1]⇥ · · ·⇥ [ad, bd]
Problem: Design a data structure for the case d = 1.
Solution: Balanced binary search tree:Stores points in the leavesInternal node v stores pivot value xv
2
5 8 12 15
17
21 33 41
58
672 93
67582112
15
Example:Search for all points in [6,50]
vsplit
6 5017
86
5
6
7
6
7
5250
3350
4150
52
3
![Page 18: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/18.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Orthogonal Range Queries
Given: n points in Rd
Output: A data structure that e�ciently answers queries ofthe form [a1, b1]⇥ · · ·⇥ [ad, bd]
Problem: Design a data structure for the case d = 1.
Solution: Balanced binary search tree:Stores points in the leavesInternal node v stores pivot value xv
2
5 8 12 15
17
21 33 41
58
672 93
67582112
15
Example:Search for all points in [6,50]
vsplit
6 5017
86
5
6
7
6
7
5250
3350
4150
52
Answer:Points in the leaves between thesearch paths, (i.e.,{7,8,12,15,17,21,33,41})
3
![Page 19: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/19.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
1dRangeQuery
FindSplitNode(T, x, x0)
v root(T )while v not a leaf and (x0 xv or x > xv) do
if x0 xv then v lc(v) else v rc(v)return v
1dRangeQuery(T, x, x0)
vsplit FindSplitNode(T, x, x0)if vsplit is leaf then report vsplitelse
v lc(vsplit)while v not a leaf do
if x xv thenReportSubtree(rc(v)); v lc(v)
else v rc(v)
report v// analog. for x
0 and rc(vsplit)
2
5 8 12 15
17
21 33 41
58
672 93
67582112
15
vsplit
6 5017
86
5
6
7
6
7
5250
3350
4150
52
93
4
![Page 20: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/20.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
1dRangeQuery
FindSplitNode(T, x, x0)
v root(T )while v not a leaf and (x0 xv or x > xv) do
if x0 xv then v lc(v) else v rc(v)return v
1dRangeQuery(T, x, x0)
vsplit FindSplitNode(T, x, x0)if vsplit is leaf then report vsplitelse
v lc(vsplit)while v not a leaf do
if x xv thenReportSubtree(rc(v)); v lc(v)
else v rc(v)
report v// analog. for x
0 and rc(vsplit)
2
5 8 12 15
17
21 33 41
58
672 93
67582112
15
vsplit
6 5017
86
5
6
7
6
7
5250
3350
4150
52
Can find canonical subset inlinear time
93
4
![Page 21: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/21.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Analysis of 1dRangeQuery
Theorem 1: A set of n points in R can preprocessed inO(n log n) time and stored in O(n) space so thatwe can answer range queries in O(k + log n)time, where k is the number of reported points.
2
5 8 12 15
17
21 33 41
58
672 93
67582112
15
vsplit
6 5017
86
5
6
7
6
7
5250
3350
4150
52
1dRangeQuery(T, x, x0)
vsplit FindSplitNode(T, x, x0)if vsplit is leaf then report vsplitelse
v lc(vsplit)while v not a leaf do
if x xv thenReportSubtree(rc(v)); v lc(v)
else v rc(v)
report v// analog. for x
0 and rc(vsplit)
5
![Page 22: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/22.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Orthogonal Range Queries for d = 2
Given: Set P of n points in R2
Goal: A data structure to e�ciently answer range queries ofthe form R = [x, x0]⇥ [y, y0]
6
![Page 23: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/23.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Orthogonal Range Queries for d = 2
Given: Set P of n points in R2
Goal: A data structure to e�ciently answer range queries ofthe form R = [x, x0]⇥ [y, y0]
Ideas for generalizing the 1d case?
6
![Page 24: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/24.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Orthogonal Range Queries for d = 2
Given: Set P of n points in R2
Goal: A data structure to e�ciently answer range queries ofthe form R = [x, x0]⇥ [y, y0]
Ideas for generalizing the 1d case?
Solutions:
one search tree, alternate search for x and y coordinates
primary search tree on x-coordinates,several secondary search trees on y-coordinates
! kd-Tree
! Range Tree
6
![Page 25: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/25.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Orthogonal Range Queries for d = 2
Given: Set P of n points in R2
Goal: A data structure to e�ciently answer range queries ofthe form R = [x, x0]⇥ [y, y0]
Ideas for generalizing the 1d case?
Solutions:
one search tree, alternate search for x and y coordinates
primary search tree on x-coordinates,several secondary search trees on y-coordinates
! kd-Tree
! Range Tree
Temporary assumption: general position, that is no twopoints have the same x- or y-coordinates
6
![Page 26: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/26.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
kd-Trees: Example
p4
p1
p5
p3
p2
p7
p9
p10
p6
p8
7
![Page 27: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/27.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
kd-Trees: Example
p
`1
4
p1
p5
p3
p2
p7
p9
p10
p6
p8
7
![Page 28: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/28.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
kd-Trees: Example
p
`1 `1
4
p1
p5
p3
p2
p7
p9
p10
p6
p8
7
![Page 29: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/29.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
kd-Trees: Example
p
`1
`2
`1
4
p1
p5
p3
p2
p7
p9
p10
p6
p8
7
![Page 30: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/30.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
kd-Trees: Example
p
`1
`2
`1
`24
p1
p5
p3
p2
p7
p9
p10
p6
p8
7
![Page 31: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/31.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
kd-Trees: Example
p
`1
`2
`4
`1
`24
p1
p5
p3
p2
p7
p9
p10
p6
p8
7
![Page 32: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/32.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
kd-Trees: Example
p
`1
`2
`4
`1
`2
`4
4
p1
p5
p3
p2
p7
p9
p10
p6
p8
7
![Page 33: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/33.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
kd-Trees: Example
p
`1
`2
`8
`4
`1
`2
`4
4
p1
p5
p3
p2
p7
p9
p10
p6
p8
7
![Page 34: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/34.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
kd-Trees: Example
p
`1
`2
`8
`4
`1
`2
`8
`4
4
p1
p5
p3
p2
p7
p9
p10
p6
p8
7
![Page 35: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/35.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
kd-Trees: Example
p
`1
`2
p1
`8
`4
`1
`2
`8
`4
4
p1
p5
p3
p2
p7
p9
p10
p6
p8
7
![Page 36: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/36.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
kd-Trees: Example
p
`1
`2
p1 p2
`8
`4
`1
`2
`8
`4
4
p1
p5
p3
p2
p7
p9
p10
p6
p8
7
![Page 37: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/37.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
kd-Trees: Example
p
`1
`2
p1 p2
p3
`8
`4
`1
`2
`8
`4
4
p1
p5
p3
p2
p7
p9
p10
p6
p8
7
![Page 38: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/38.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
kd-Trees: Example
p
`1`5
`2
p1 p2
p3
`8
`4
`1
`2
`8
`4
4
p1
p5
p3
p2
p7
p9
p10
p6
p8
7
![Page 39: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/39.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
kd-Trees: Example
p
`1`5
`2
p1 p2
p3
`8
`4
`1
`2
`5
`8
`4
4
p1
p5
p3
p2
p7
p9
p10
p6
p8
7
![Page 40: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/40.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
kd-Trees: Example
p
`1`5
`2
p1 p2
p3 p4
`8
`4
`1
`2
`5
`8
`4
4
p1
p5
p3
p2
p7
p9
p10
p6
p8
7
![Page 41: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/41.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
kd-Trees: Example
p
`1`5
`2
p1 p2
p3 p4 p5
`8
`4
`1
`2
`5
`8
`4
4
p1
p5
p3
p2
p7
p9
p10
p6
p8
7
![Page 42: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/42.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
kd-Trees: Example
p
`1
`3
`5
`2
p1 p2
p3 p4 p5
`8
`4
`1
`2
`5
`8
`4
4
p1
p5
p3
p2
p7
p9
p10
p6
p8
7
![Page 43: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/43.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
kd-Trees: Example
p
`1
`3
`5
`2
p1 p2
p3 p4 p5
`8
`4
`1
`2 `3
`5
`8
`4
4
p1
p5
p3
p2
p7
p9
p10
p6
p8
7
![Page 44: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/44.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
kd-Trees: Example
p
`1
`3
`6
`5
`2
p1 p2
p3 p4 p5
`8
`4
`1
`2 `3
`5
`8
`4
4
p1
p5
p3
p2
p7
p9
p10
p6
p8
7
![Page 45: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/45.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
kd-Trees: Example
p
`1
`3
`6
`5
`2
p1 p2
p3 p4 p5
`8
`4
`1
`2 `3
`5 `6
`8
`4
4
p1
p5
p3
p2
p7
p9
p10
p6
p8
7
![Page 46: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/46.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
kd-Trees: Example
p
`1
`3
`6
`5
`2
p1 p2
p3 p4 p5
`8
`4
`1
`2 `3
`5 `6
`8
`4
4
p1
p5
p3
p2
p7
p9
p10
p6
p8
`9
7
![Page 47: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/47.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
kd-Trees: Example
p
`1
`3
`6
`5
`2
p1 p2
p3 p4 p5
`8
`4
`1
`2 `3
`5 `6
`8 `9
`4
4
p1
p5
p3
p2
p7
p9
p10
p6
p8
`9
7
![Page 48: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/48.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
kd-Trees: Example
p
`1
`3
`6
`5
`2
p1 p2
p3 p4 p5
p6
`8
`4
`1
`2 `3
`5 `6
`8 `9
`4
4
p1
p5
p3
p2
p7
p9
p10
p6
p8
`9
7
![Page 49: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/49.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
kd-Trees: Example
p
`1
`3
`6
`5
`2
p1 p2
p3 p4 p5
p6 p7
`8
`4
`1
`2 `3
`5 `6
`8 `9
`4
4
p1
p5
p3
p2
p7
p9
p10
p6
p8
`9
7
![Page 50: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/50.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
kd-Trees: Example
p
`1
`3
`6
`5
`2
p1 p2
p3 p4 p5
p6 p7
p8
`8
`4
`1
`2 `3
`5 `6
`8 `9
`4
4
p1
p5
p3
p2
p7
p9
p10
p6
p8
`9
7
![Page 51: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/51.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
kd-Trees: Example
p
`1`7
`3
`6
`5
`2
p1 p2
p3 p4 p5
p6 p7
p8
`8
`4
`1
`2 `3
`5 `6
`8 `9
`4
4
p1
p5
p3
p2
p7
p9
p10
p6
p8
`9
7
![Page 52: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/52.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
kd-Trees: Example
p
`1`7
`3
`6
`5
`2
p1 p2
p3 p4 p5
p6 p7
p8
`8
`4
`1
`2 `3
`5 `6 `7
`8 `9
`4
4
p1
p5
p3
p2
p7
p9
p10
p6
p8
`9
7
![Page 53: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/53.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
kd-Trees: Example
p
`1`7
`3
`6
`5
`2
p1 p2
p3 p4 p5
p6 p7
p8 p9
`8
`4
`1
`2 `3
`5 `6 `7
`8 `9
`4
4
p1
p5
p3
p2
p7
p9
p10
p6
p8
`9
7
![Page 54: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/54.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
kd-Trees: Example
p
`1`7
`3
`6
`5
`2
p1 p2
p3 p4 p5
p6 p7
p8 p9 p10
`8
`4
`1
`2 `3
`5 `6 `7
`8 `9
`4
4
p1
p5
p3
p2
p7
p9
p10
p6
p8
`9
7
![Page 55: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/55.jpg)
Dr. Martin Nollenburg · Vorlesung Algorithmische Geometrie Bereichsabfragen
kd-Trees: Construction
p
`
4
p1
p5
p3
p7
p9
p10
p6
p8
BuildKdTree(P, depth)
p2
![Page 56: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/56.jpg)
Dr. Martin Nollenburg · Vorlesung Algorithmische Geometrie Bereichsabfragen
kd-Trees: Construction
p
`
4
p1
p5
p3
p7
p9
p10
p6
p8
BuildKdTree(P, depth)
if |P | = 1 then
return leaf with the point in Pelse
if depth is even then
divide P vertically at` : x = xmedian(P ) in
P1 (Points left to or on `) andP2 = P \ P1
else
divide P horizontally at` : y = ymedian(P ) in
P1 (Points below or on `) undP2 = P \ P1
vleft BuildKdTree(P1, depth + 1)vright BuildKdTree(P2, depth + 1)Create node v, which stores `Make vleft und vright children of vreturn v
p2
![Page 57: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/57.jpg)
Dr. Martin Nollenburg · Vorlesung Algorithmische Geometrie Bereichsabfragen
kd-Trees: Construction
p
`
4
p1
p5
p3
p7
p9
p10
p6
p8
BuildKdTree(P, depth)
if |P | = 1 then
return leaf with the point in Pelse
if depth is even then
divide P vertically at` : x = xmedian(P ) in
P1 (Points left to or on `) andP2 = P \ P1
else
divide P horizontally at` : y = ymedian(P ) in
P1 (Points below or on `) undP2 = P \ P1
vleft BuildKdTree(P1, depth + 1)vright BuildKdTree(P2, depth + 1)Create node v, which stores `Make vleft und vright children of vreturn v
p2
![Page 58: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/58.jpg)
Dr. Martin Nollenburg · Vorlesung Algorithmische Geometrie Bereichsabfragen
kd-Trees: Construction
p
`
4
p1
p5
p3
p7
p9
p10
p6
p8
BuildKdTree(P, depth)
if |P | = 1 then
return leaf with the point in Pelse
if depth is even then
divide P vertically at` : x = xmedian(P ) in
P1 (Points left to or on `) andP2 = P \ P1
else
divide P horizontally at` : y = ymedian(P ) in
P1 (Points below or on `) undP2 = P \ P1
vleft BuildKdTree(P1, depth + 1)vright BuildKdTree(P2, depth + 1)Create node v, which stores `Make vleft und vright children of vreturn v
p2
Point d|P |/2e
![Page 59: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/59.jpg)
Dr. Martin Nollenburg · Vorlesung Algorithmische Geometrie Bereichsabfragen
kd-Trees: Construction
p
`
4
p1
p5
p3
p7
p9
p10
p6
p8
BuildKdTree(P, depth)
if |P | = 1 then
return leaf with the point in Pelse
if depth is even then
divide P vertically at` : x = xmedian(P ) in
P1 (Points left to or on `) andP2 = P \ P1
else
divide P horizontally at` : y = ymedian(P ) in
P1 (Points below or on `) undP2 = P \ P1
vleft BuildKdTree(P1, depth + 1)vright BuildKdTree(P2, depth + 1)Create node v, which stores `Make vleft und vright children of vreturn v
`0 p2
![Page 60: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/60.jpg)
Dr. Martin Nollenburg · Vorlesung Algorithmische Geometrie Bereichsabfragen
kd-Trees: Construction
p
`
4
p1
p5
p3
p7
p9
p10
p6
p8
BuildKdTree(P, depth)
if |P | = 1 then
return leaf with the point in Pelse
if depth is even then
divide P vertically at` : x = xmedian(P ) in
P1 (Points left to or on `) andP2 = P \ P1
else
divide P horizontally at` : y = ymedian(P ) in
P1 (Points below or on `) undP2 = P \ P1
vleft BuildKdTree(P1, depth + 1)vright BuildKdTree(P2, depth + 1)Create node v, which stores `Make vleft und vright children of vreturn v
p2
![Page 61: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/61.jpg)
Dr. Martin Nollenburg · Vorlesung Algorithmische Geometrie Bereichsabfragen
kd-Trees: Construction
p
`
4
p1
p5
p3
p7
p9
p10
p6
p8
BuildKdTree(P, depth)
if |P | = 1 then
return leaf with the point in Pelse
if depth is even then
divide P vertically at` : x = xmedian(P ) in
P1 (Points left to or on `) andP2 = P \ P1
else
divide P horizontally at` : y = ymedian(P ) in
P1 (Points below or on `) undP2 = P \ P1
vleft BuildKdTree(P1, depth + 1)vright BuildKdTree(P2, depth + 1)Create node v, which stores `Make vleft und vright children of vreturn v
p2
vleft vright
![Page 62: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/62.jpg)
Dr. Martin Nollenburg · Vorlesung Algorithmische Geometrie Bereichsabfragen
kd-Trees: Construction
p
`
4
p1
p5
p3
p7
p9
p10
p6
p8
BuildKdTree(P, depth)
if |P | = 1 then
return leaf with the point in Pelse
if depth is even then
divide P vertically at` : x = xmedian(P ) in
P1 (Points left to or on `) andP2 = P \ P1
else
divide P horizontally at` : y = ymedian(P ) in
P1 (Points below or on `) undP2 = P \ P1
vleft BuildKdTree(P1, depth + 1)vright BuildKdTree(P2, depth + 1)Create node v, which stores `Make vleft und vright children of vreturn v
p2
vleft vright
![Page 63: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/63.jpg)
Dr. Martin Nollenburg · Vorlesung Algorithmische Geometrie Bereichsabfragen
kd-Trees: Construction
p
`
4
p1
p5
p3
p7
p9
p10
p6
p8
BuildKdTree(P, depth)
if |P | = 1 then
return leaf with the point in Pelse
if depth is even then
divide P vertically at` : x = xmedian(P ) in
P1 (Points left to or on `) andP2 = P \ P1
else
divide P horizontally at` : y = ymedian(P ) in
P1 (Points below or on `) undP2 = P \ P1
vleft BuildKdTree(P1, depth + 1)vright BuildKdTree(P2, depth + 1)Create node v, which stores `Make vleft und vright children of vreturn v
p2
v`
vleft vright
![Page 64: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/64.jpg)
Dr. Martin Nollenburg · Vorlesung Algorithmische Geometrie Bereichsabfragen
kd-Trees: Construction
p
`
4
p1
p5
p3
p7
p9
p10
p6
p8
BuildKdTree(P, depth)
if |P | = 1 then
return leaf with the point in Pelse
if depth is even then
divide P vertically at` : x = xmedian(P ) in
P1 (Points left to or on `) andP2 = P \ P1
else
divide P horizontally at` : y = ymedian(P ) in
P1 (Points below or on `) undP2 = P \ P1
vleft BuildKdTree(P1, depth + 1)vright BuildKdTree(P2, depth + 1)Create node v, which stores `Make vleft und vright children of vreturn v
p2
v`
vleft vright
![Page 65: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/65.jpg)
Dr. Martin Nollenburg · Vorlesung Algorithmische Geometrie Bereichsabfragen
kd-Trees: Construction
p
`
4
p1
p5
p3
p7
p9
p10
p6
p8
BuildKdTree(P, depth)
if |P | = 1 then
return leaf with the point in Pelse
if depth is even then
divide P vertically at` : x = xmedian(P ) in
P1 (Points left to or on `) andP2 = P \ P1
else
divide P horizontally at` : y = ymedian(P ) in
P1 (Points below or on `) undP2 = P \ P1
vleft BuildKdTree(P1, depth + 1)vright BuildKdTree(P2, depth + 1)Create node v, which stores `Make vleft und vright children of vreturn v
p2
v`
vleft vright
![Page 66: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/66.jpg)
Dr. Martin Nollenburg · Vorlesung Algorithmische Geometrie Bereichsabfragen
kd-Trees: Construction
p
`
4
p1
p5
p3
p7
p9
p10
p6
p8
BuildKdTree(P, depth)
if |P | = 1 then
return leaf with the point in Pelse
if depth is even then
divide P vertically at` : x = xmedian(P ) in
P1 (Points left to or on `) andP2 = P \ P1
else
divide P horizontally at` : y = ymedian(P ) in
P1 (Points below or on `) undP2 = P \ P1
vleft BuildKdTree(P1, depth + 1)vright BuildKdTree(P2, depth + 1)Create node v, which stores `Make vleft und vright children of vreturn v
p2
v`
vleft vright
![Page 67: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/67.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Analysis of kd-Tree Construction
Lemma 1:A kd-tree for n points in R2 can be constructed inO(n log n) time, using O(n) space.
9
![Page 68: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/68.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Analysis of kd-Tree Construction
Lemma 1:A kd-tree for n points in R2 can be constructed inO(n log n) time, using O(n) space.
Proof sketch:Determine median:– make two lists sorted on x- and y-coordinates– at each step, determine median and divide the lists
9
![Page 69: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/69.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Analysis of kd-Tree Construction
Lemma 1:A kd-tree for n points in R2 can be constructed inO(n log n) time, using O(n) space.
Proof sketch:Determine median:– make two lists sorted on x- and y-coordinates– at each step, determine median and divide the lists
We get the following recurrence:
T (n) =
(O(1) if n = 1
O(n) + 2T (dn/2e) otherwise
9
![Page 70: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/70.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Analysis of kd-Tree Construction
Lemma 1:A kd-tree for n points in R2 can be constructed inO(n log n) time, using O(n) space.
Proof sketch:Determine median:– make two lists sorted on x- and y-coordinates– at each step, determine median and divide the lists
We get the following recurrence:
T (n) =
(O(1) if n = 1
O(n) + 2T (dn/2e) otherwise
Solves to T (n) = O(n log n) (analogous to MergeSort)
9
![Page 71: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/71.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Analysis of kd-Tree Construction
Lemma 1:A kd-tree for n points in R2 can be constructed inO(n log n) time, using O(n) space.
Proof sketch:Determine median:– make two lists sorted on x- and y-coordinates– at each step, determine median and divide the lists
We get the following recurrence:
T (n) =
(O(1) if n = 1
O(n) + 2T (dn/2e) otherwise
Solves to T (n) = O(n log n) (analogous to MergeSort)
Linear space, since we are using a binary tree with n leaves.
9
![Page 72: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/72.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Range Queries in a kd-Tree
p1
p2
p3
p4 p5
p6p7
p8
p9p10
p11
p12p13
p1 p2
p4 p5p3
p6
p7 p8 p9 p10
p11 p12 p13
10
![Page 73: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/73.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Range Queries in a kd-Tree
p1
p2
p3
p4 p5
p6p7
p8
p9p10
p11
p12p13
p1 p2
p4 p5
SearchKdTree(v,R)
if v leaf thenreport point p in v when p 2 R
elseif region(lc(v)) ✓ R then
ReportSubtree(lc(v))else
if region(lc(v))\R 6= ; thenSearchKdTree(lc(v), R)
if region(rc(v)) ✓ R thenReportSubtree(rc(v))
elseif region(rc(v))\R 6= ; thenSearchKdTree(rc(v), R)
p3
p6
p7 p8 p9 p10
p11 p12 p13
10
![Page 74: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/74.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Range Queries in a kd-Tree
p1
p2
p3
p4 p5
p6p7
p8
p9p10
p11
p12p13
p1 p2
p4 p5
SearchKdTree(v,R)
if v leaf thenreport point p in v when p 2 R
elseif region(lc(v)) ✓ R then
ReportSubtree(lc(v))else
if region(lc(v))\R 6= ; thenSearchKdTree(lc(v), R)
if region(rc(v)) ✓ R thenReportSubtree(rc(v))
elseif region(rc(v))\R 6= ; thenSearchKdTree(rc(v), R)
p3
p6
p7 p8 p9 p10
p11 p12 p13
10
![Page 75: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/75.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Range Queries in a kd-Tree
p1
p2
p3
p4 p5
p6p7
p8
p9p10
p11
p12p13
p1 p2
p4 p5
SearchKdTree(v,R)
if v leaf thenreport point p in v when p 2 R
elseif region(lc(v)) ✓ R then
ReportSubtree(lc(v))else
if region(lc(v))\R 6= ; thenSearchKdTree(lc(v), R)
if region(rc(v)) ✓ R thenReportSubtree(rc(v))
elseif region(rc(v))\R 6= ; thenSearchKdTree(rc(v), R)
p3
p6
p7 p8 p9 p10
p11 p12 p13
10
![Page 76: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/76.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Range Queries in a kd-Tree
p1
p2
p3
p4 p5
p6p7
p8
p9p10
p11
p12p13
p1 p2
p4 p5
SearchKdTree(v,R)
if v leaf thenreport point p in v when p 2 R
elseif region(lc(v)) ✓ R then
ReportSubtree(lc(v))else
if region(lc(v))\R 6= ; thenSearchKdTree(lc(v), R)
if region(rc(v)) ✓ R thenReportSubtree(rc(v))
elseif region(rc(v))\R 6= ; thenSearchKdTree(rc(v), R)
p3
p6
p7 p8 p9 p10
p11 p12 p13
10
![Page 77: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/77.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Range Queries in a kd-Tree
p1
p2
p3
p4 p5
p6p7
p8
p9p10
p11
p12p13
p1 p2
p4 p5
SearchKdTree(v,R)
if v leaf thenreport point p in v when p 2 R
elseif region(lc(v)) ✓ R then
ReportSubtree(lc(v))else
if region(lc(v))\R 6= ; thenSearchKdTree(lc(v), R)
if region(rc(v)) ✓ R thenReportSubtree(rc(v))
elseif region(rc(v))\R 6= ; thenSearchKdTree(rc(v), R)
p3
p6
p7 p8 p9 p10
p11 p12 p13
10
![Page 78: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/78.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Range Queries in a kd-Tree
p1
p2
p3
p4 p5
p6p7
p8
p9p10
p11
p12p13
p1 p2
p4 p5
SearchKdTree(v,R)
if v leaf thenreport point p in v when p 2 R
elseif region(lc(v)) ✓ R then
ReportSubtree(lc(v))else
if region(lc(v))\R 6= ; thenSearchKdTree(lc(v), R)
if region(rc(v)) ✓ R thenReportSubtree(rc(v))
elseif region(rc(v))\R 6= ; thenSearchKdTree(rc(v), R)
p3
p6
p7 p8 p9 p10
p11 p12 p13
10
![Page 79: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/79.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Range Queries in a kd-Tree
p1
p2
p3
p4 p5
p6p7
p8
p9p10
p11
p12p13
p1 p2
p4 p5
SearchKdTree(v,R)
if v leaf thenreport point p in v when p 2 R
elseif region(lc(v)) ✓ R then
ReportSubtree(lc(v))else
if region(lc(v))\R 6= ; thenSearchKdTree(lc(v), R)
if region(rc(v)) ✓ R thenReportSubtree(rc(v))
elseif region(rc(v))\R 6= ; thenSearchKdTree(rc(v), R)
p3
p6
p7 p8 p9 p10
p11 p12 p13
10
![Page 80: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/80.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Range Queries in a kd-Tree
p1
p2
p3
p4 p5
p6p7
p8
p9p10
p11
p12p13
p1 p2
p4 p5
SearchKdTree(v,R)
if v leaf thenreport point p in v when p 2 R
elseif region(lc(v)) ✓ R then
ReportSubtree(lc(v))else
if region(lc(v))\R 6= ; thenSearchKdTree(lc(v), R)
if region(rc(v)) ✓ R thenReportSubtree(rc(v))
elseif region(rc(v))\R 6= ; thenSearchKdTree(rc(v), R)
p3
p6
p7 p8 p9 p10
p11 p12 p13
10
![Page 81: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/81.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Range Queries in a kd-Tree
p1
p2
p3
p4 p5
p6p7
p8
p9p10
p11
p12p13
p1 p2
p4 p5
SearchKdTree(v,R)
if v leaf thenreport point p in v when p 2 R
elseif region(lc(v)) ✓ R then
ReportSubtree(lc(v))else
if region(lc(v))\R 6= ; thenSearchKdTree(lc(v), R)
if region(rc(v)) ✓ R thenReportSubtree(rc(v))
elseif region(rc(v))\R 6= ; thenSearchKdTree(rc(v), R)
p3
p6
p6
p7 p8 p9 p10
p11 p12 p13
10
![Page 82: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/82.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Range Queries in a kd-Tree
p1
p2
p3
p4 p5
p6p7
p8
p9p10
p11
p12p13
p1 p2
p4 p5
SearchKdTree(v,R)
if v leaf thenreport point p in v when p 2 R
elseif region(lc(v)) ✓ R then
ReportSubtree(lc(v))else
if region(lc(v))\R 6= ; thenSearchKdTree(lc(v), R)
if region(rc(v)) ✓ R thenReportSubtree(rc(v))
elseif region(rc(v))\R 6= ; thenSearchKdTree(rc(v), R)
p3
p6
p6
p7 p8 p9 p10
p7
p8
p9p10
p11 p12 p13
10
![Page 83: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/83.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Range Queries in a kd-Tree
p1
p2
p3
p4 p5
p6p7
p8
p9p10
p11
p12p13
p1 p2
p4 p5
SearchKdTree(v,R)
if v leaf thenreport point p in v when p 2 R
elseif region(lc(v)) ✓ R then
ReportSubtree(lc(v))else
if region(lc(v))\R 6= ; thenSearchKdTree(lc(v), R)
if region(rc(v)) ✓ R thenReportSubtree(rc(v))
elseif region(rc(v))\R 6= ; thenSearchKdTree(rc(v), R)
p3
p6
p6
p7 p8 p9 p10
p7
p8
p9p10
p11
p11
p12 p13
10
![Page 84: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/84.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Range Queries in a kd-Tree
p1
p2
p3
p4 p5
p6p7
p8
p9p10
p11
p12p13
p1 p2
p4 p5
SearchKdTree(v,R)
if v leaf thenreport point p in v when p 2 R
elseif region(lc(v)) ✓ R then
ReportSubtree(lc(v))else
if region(lc(v))\R 6= ; thenSearchKdTree(lc(v), R)
if region(rc(v)) ✓ R thenReportSubtree(rc(v))
elseif region(rc(v))\R 6= ; thenSearchKdTree(rc(v), R)
p3
p6
p6
p7 p8 p9 p10
p7
p8
p9p10
p11
p11
p12 p13
10
![Page 85: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/85.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Range Queries in a kd-Tree
p1
p2
p3
p4 p5
p6p7
p8
p9p10
p11
p12p13
p1 p2
p4 p5
SearchKdTree(v,R)
if v leaf thenreport point p in v when p 2 R
elseif region(lc(v)) ✓ R then
ReportSubtree(lc(v))else
if region(lc(v))\R 6= ; thenSearchKdTree(lc(v), R)
if region(rc(v)) ✓ R thenReportSubtree(rc(v))
elseif region(rc(v))\R 6= ; thenSearchKdTree(rc(v), R)
p3
p6
p6
p7 p8 p9 p10
p7
p8
p9p10
p11
p11
p12 p13
10
![Page 86: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/86.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Range Queries in a kd-Tree
p1
p2
p3
p4 p5
p6p7
p8
p9p10
p11
p12p13
p1 p2
p4 p5
SearchKdTree(v,R)
if v leaf thenreport point p in v when p 2 R
elseif region(lc(v)) ✓ R then
ReportSubtree(lc(v))else
if region(lc(v))\R 6= ; thenSearchKdTree(lc(v), R)
if region(rc(v)) ✓ R thenReportSubtree(rc(v))
elseif region(rc(v))\R 6= ; thenSearchKdTree(rc(v), R)
p3
p6
p6
p7 p8 p9 p10
p7
p8
p9p10
p11
p11
p12 p13
10
![Page 87: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/87.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Analysis of Queries in kd-Trees
Lemma 2:A range query with an axis-aligned rectangle R in akd-tree on n points may use O(
pn+ k) time,
where k is the number of reported points.
11
![Page 88: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/88.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Analysis of Queries in kd-Trees
Lemma 2:A range query with an axis-aligned rectangle R in akd-tree on n points may use O(
pn+ k) time,
where k is the number of reported points.
Proof sketch:Calls to ReportSubtree take O(k) time in total
11
![Page 89: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/89.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Analysis of Queries in kd-Trees
Lemma 2:A range query with an axis-aligned rectangle R in akd-tree on n points may use O(
pn+ k) time,
where k is the number of reported points.
Proof sketch:Calls to ReportSubtree take O(k) time in total
Still missing:Number of remaining nodes visited! Exercise
11
![Page 90: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/90.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Orthogonal Range Queries for d = 2
X
Given: Set P of n points in R2
Goal: A data structure to e�ciently answer range queries ofthe form R = [x, x0]⇥ [y, y0]
Ideas for generalizing the 1d case?
Solutions:
one search tree, alternate search for x and y coordinates
primary search tree on x-coordinates,several secondary search trees on y-coordinates
! kd-Tree
! Range TreeTemporary assumption: general position, that is no twopoints have the same x- or y-coordinates
12
![Page 91: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/91.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Range Trees
Idea: Use 1-dimensional search trees on two levels:a 1d search tree Tx on x-coordinates
v
P (v)
Tx
13
![Page 92: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/92.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Range Trees
Idea: Use 1-dimensional search trees on two levels:a 1d search tree Tx on x-coordinates
v
P (v)
Tx
in each node v of Tx a 1d search tree Ty(v) storesthe canonical subset P (v) on y-coordinates
Ty(v)
P (v)
13
![Page 93: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/93.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Range Trees
Idea: Use 1-dimensional search trees on two levels:a 1d search tree Tx on x-coordinates
v
P (v)
Tx
in each node v of Tx a 1d search tree Ty(v) storesthe canonical subset P (v) on y-coordinates
compute the points by x-query in Tx andsubsequent y-queries in the auxiliary structures Ty
for the subtrees in Tx
Ty(v)
P (v)
13
![Page 94: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/94.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Range Trees: Construction
BuildRangeTree(P )
if |P | = 1 thenCreate leaf v for the point in P
elseSplit P at xmedian into P1 = {p 2 P | px xmedian}, P2 = P \ P1
vleft BuildRangeTree(P1)vright BuildRangeTree(P2)Create node v with pivot xmedian and children vleft and vright
Ty(v) binary search tree for P w.r.t y-coordinatesreturn v
14
![Page 95: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/95.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Range Trees: Construction
BuildRangeTree(P )
if |P | = 1 thenCreate leaf v for the point in P
elseSplit P at xmedian into P1 = {p 2 P | px xmedian}, P2 = P \ P1
vleft BuildRangeTree(P1)vright BuildRangeTree(P2)Create node v with pivot xmedian and children vleft and vright
Ty(v) binary search tree for P w.r.t y-coordinatesreturn v
Problem: How much space and runtime does BuildRangeTree use?
14
![Page 96: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/96.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Range Trees: Construction
BuildRangeTree(P )
if |P | = 1 thenCreate leaf v for the point in P
elseSplit P at xmedian into P1 = {p 2 P | px xmedian}, P2 = P \ P1
vleft BuildRangeTree(P1)vright BuildRangeTree(P2)Create node v with pivot xmedian and children vleft and vright
Ty(v) binary search tree for P w.r.t y-coordinatesreturn v
Problem: How much space and runtime does BuildRangeTree use?
Lemma 3: A Range Tree for n points in R2 uses O(n log n)space and can be constructed in O(n log n) time.
14
![Page 97: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/97.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Range Queries in a Range Tree
Reminder:1dRangeQuery(T, x, x0)
vsplit FindSplitNode(T, x, x0)if vsplit is leaf then report vsplitelse
v lc(vsplit)while v not leaf do
if x xv thenReportSubtree(rc(v))v lc(v)
else v rc(v)
report v// analogous for x
0 and rc(vsplit)
15
![Page 98: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/98.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Range Queries in a Range Tree
Reminder:1dRangeQuery(T, x, x0)
vsplit FindSplitNode(T, x, x0)if vsplit is leaf then report vsplitelse
v lc(vsplit)while v not leaf do
if x xv thenReportSubtree(rc(v))v lc(v)
else v rc(v)
report v// analogous for x
0 and rc(vsplit)
2dRangeQuery(T, [x, x0]⇥ [y, y0])
1dRangeQuery(Ty(rc(v)), y, y0)
15
![Page 99: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/99.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Range Queries in a Range Tree
Reminder:1dRangeQuery(T, x, x0)
vsplit FindSplitNode(T, x, x0)if vsplit is leaf then report vsplitelse
v lc(vsplit)while v not leaf do
if x xv thenReportSubtree(rc(v))v lc(v)
else v rc(v)
report v// analogous for x
0 and rc(vsplit)
2dRangeQuery(T, [x, x0]⇥ [y, y0])
1dRangeQuery(Ty(rc(v)), y, y0)
Lemma 4:A range query in a Range Tree takes O(log2 n+ k)time, where k is the number of reported points.
15
![Page 100: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/100.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Range Queries with Fractional Cascading
Observation: Range queries in a Range Tree perform O(log n)1d queries, each taking O(log n+ kv) time.The query interval [y, y0] is always the same!
16
![Page 101: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/101.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Range Queries with Fractional Cascading
Observation: Range queries in a Range Tree perform O(log n)1d queries, each taking O(log n+ kv) time.The query interval [y, y0] is always the same!
Idea: Use this property to accelerate the 1d queries toO(1 + kv) time
16
![Page 102: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/102.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Range Queries with Fractional Cascading
Observation: Range queries in a Range Tree perform O(log n)1d queries, each taking O(log n+ kv) time.The query interval [y, y0] is always the same!
Idea: Use this property to accelerate the 1d queries toO(1 + kv) time
Example:Two sets B ✓ A ✓ R in sorted arrays
3 10 19 23 30 37 59 62 70 80 100 105
10 19 30 70 80 100
A
B 62
16
![Page 103: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/103.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Range Queries with Fractional Cascading
Observation: Range queries in a Range Tree perform O(log n)1d queries, each taking O(log n+ kv) time.The query interval [y, y0] is always the same!
Idea: Use this property to accelerate the 1d queries toO(1 + kv) time
Example:Two sets B ✓ A ✓ R in sorted arrays
3 10 19 23 30 37 59 62 70 80 100 105
10 19 30 70 80 100
A
B
Search interval [20,65]
23
30 62
16
![Page 104: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/104.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Range Queries with Fractional Cascading
Observation: Range queries in a Range Tree perform O(log n)1d queries, each taking O(log n+ kv) time.The query interval [y, y0] is always the same!
Idea: Use this property to accelerate the 1d queries toO(1 + kv) time
Example:Two sets B ✓ A ✓ R in sorted arrays
3 10 19 23 30 37 59 62 70 80 100 105
10 19 30 70 80 100
A
B
Search interval [20,65]
23
30 62
Can we do better than two binary searches?
16
![Page 105: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/105.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Range Queries with Fractional Cascading
Observation: Range queries in a Range Tree perform O(log n)1d queries, each taking O(log n+ kv) time.The query interval [y, y0] is always the same!
Idea: Use this property to accelerate the 1d queries toO(1 + kv) time
Example:Two sets B ✓ A ✓ R in sorted arrays
3 10 19 23 30 37 59 62 70 80 100 105
10 19 30 70 80 100
A
B 62
link a 2 A
with smallestb � a in B
16
![Page 106: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/106.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Range Queries with Fractional Cascading
Observation: Range queries in a Range Tree perform O(log n)1d queries, each taking O(log n+ kv) time.The query interval [y, y0] is always the same!
Idea: Use this property to accelerate the 1d queries toO(1 + kv) time
Example:Two sets B ✓ A ✓ R in sorted arrays
3 10 19 23 30 37 59 62 70 80 100 105
10 19 30 70 80 100
A
B 62
link a 2 A
with smallestb � a in B
Search interval [20,65]
23
16
![Page 107: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/107.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Range Queries with Fractional Cascading
Observation: Range queries in a Range Tree perform O(log n)1d queries, each taking O(log n+ kv) time.The query interval [y, y0] is always the same!
Idea: Use this property to accelerate the 1d queries toO(1 + kv) time
Example:Two sets B ✓ A ✓ R in sorted arrays
3 10 19 23 30 37 59 62 70 80 100 105
10 19 30 70 80 100
A
B 62
link a 2 A
with smallestb � a in B
Search interval [20,65]
23
30
Pointer yields starting point for secondsearch in O(1) time
16
![Page 108: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/108.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Speed-up with Fractional Cascading
In Range Trees we have P (lc(v)) ✓ P (v) and P (rc(v)) ✓ P (v) as thecanonical sets.
(2,19)
(5,80)
(7,10)
(8,37)(12,3)
(15,99)
(17,62) (21,49)
(33,30)
(41,95)
(52,23)
(58,59)
(67,89)
(93,70)
2
5 7 8 12 15
17
21 33 41 52
58
672 93
67584121127
5
8
15
17
52
33
Tx
17
![Page 109: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/109.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Speed-up with Fractional Cascading
In Range Trees we have P (lc(v)) ✓ P (v) and P (rc(v)) ✓ P (v) as thecanonical sets.
Define for each array element A(v)[i] two pointers into the arraysA(lc(v)) and A(rc(v))! Layered Range Tree
3 99
10 19 37 80
30 49
80 3 99 3049
9962
6210 37
10 3719
8019
99623719103 80 30 4923 59 70 89 95
30 49233 95 59 70 89
23 95 59 70 89
95 23 89 70
3 10 19 23 30 37 49 59 62 70 80 89 95 99
(2,19)
(5,80)
(7,10)
(8,37)(12,3)
(15,99)
(17,62) (21,49)
(33,30)
(41,95)
(52,23)
(58,59)
(67,89)
(93,70)
2
5 7 8 12 15
17
21 33 41 52
58
672 93
67584121127
5
8
15
17
52
33
Tx
17
![Page 110: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/110.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Speed-up with Fractional Cascading
In Range Trees we have P (lc(v)) ✓ P (v) and P (rc(v)) ✓ P (v) as thecanonical sets.
Define for each array element A(v)[i] two pointers into the arraysA(lc(v)) and A(rc(v))! Layered Range Tree
3 99
10 19 37 80
30 49
80 3 99 3049
9962
6210 37
10 3719
8019
99623719103 80 30 4923 59 70 89 95
30 49233 95 59 70 89
23 95 59 70 89
95 23 89 70
3 10 19 23 30 37 49 59 62 70 80 89 95 99
(2,19)
(5,80)
(7,10)
(8,37)(12,3)
(15,99)
(17,62) (21,49)
(33,30)
(41,95)
(52,23)
(58,59)
(67,89)
(93,70)
2
5 7 8 12 15
17
21 33 41 52
58
672 93
67584121127
5
8
15
17
52
33
Tx
In the split node a binary search takes O(log n) time,then it takes O(1) time to follow the pointers in the children
17
![Page 111: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/111.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Speed-up with Fractional Cascading
Theorem 2: A Layered Range Tree on n points in R2 can beconstructed in O(n log n) time and space. Range queriestake O(log n+ k) time, where k is the number of reportedpoints.
In Range Trees we have P (lc(v)) ✓ P (v) and P (rc(v)) ✓ P (v) as thecanonical sets.
Define for each array element A(v)[i] two pointers into the arraysA(lc(v)) and A(rc(v))! Layered Range Tree
In the split node a binary search takes O(log n) time,then it takes O(1) time to follow the pointers in the children
17
![Page 112: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/112.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Arbitrary Point Sets
Idea: Instead of R, use pairs of numbers (a|b) with totalorder $ lexicographic order
So far: Points in general position, where no two points havethe same x- or y-coordinate
18
![Page 113: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/113.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Arbitrary Point Sets
Idea: Instead of R, use pairs of numbers (a|b) with totalorder $ lexicographic order
p = (px, py)
So far: Points in general position, where no two points havethe same x- or y-coordinate
18
![Page 114: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/114.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Arbitrary Point Sets
Idea: Instead of R, use pairs of numbers (a|b) with totalorder $ lexicographic order
p = (px, py) p =�(px|py), (py|px)
�
So far: Points in general position, where no two points havethe same x- or y-coordinate
18
![Page 115: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/115.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Arbitrary Point Sets
Idea: Instead of R, use pairs of numbers (a|b) with totalorder $ lexicographic order
p = (px, py) p =�(px|py), (py|px)
�
unique coord.
So far: Points in general position, where no two points havethe same x- or y-coordinate
18
![Page 116: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/116.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Arbitrary Point Sets
Idea: Instead of R, use pairs of numbers (a|b) with totalorder $ lexicographic order
p = (px, py) p =�(px|py), (py|px)
�
unique coord.Rectangle R = [x, x0]⇥ [y, y0]
So far: Points in general position, where no two points havethe same x- or y-coordinate
18
![Page 117: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/117.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Arbitrary Point Sets
Idea: Instead of R, use pairs of numbers (a|b) with totalorder $ lexicographic order
p = (px, py) p =�(px|py), (py|px)
�
unique coord.Rectangle R = [x, x0]⇥ [y, y0]
So far: Points in general position, where no two points havethe same x- or y-coordinate
18
![Page 118: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/118.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Arbitrary Point Sets
Idea: Instead of R, use pairs of numbers (a|b) with totalorder $ lexicographic order
p = (px, py) p =�(px|py), (py|px)
�
unique coord.Rectangle R = [x, x0]⇥ [y, y0]
R = [(x|�1), (x0|+1)]⇥ [(y|�1), (y0|+1)]
So far: Points in general position, where no two points havethe same x- or y-coordinate
18
![Page 119: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/119.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Arbitrary Point Sets
Idea: Instead of R, use pairs of numbers (a|b) with totalorder $ lexicographic order
p = (px, py) p =�(px|py), (py|px)
�
unique coord.Rectangle R = [x, x0]⇥ [y, y0]
R = [(x|�1), (x0|+1)]⇥ [(y|�1), (y0|+1)]
Then:
So far: Points in general position, where no two points havethe same x- or y-coordinate
18
![Page 120: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/120.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Arbitrary Point Sets
Idea: Instead of R, use pairs of numbers (a|b) with totalorder $ lexicographic order
p = (px, py) p =�(px|py), (py|px)
�
unique coord.Rectangle R = [x, x0]⇥ [y, y0]
R = [(x|�1), (x0|+1)]⇥ [(y|�1), (y0|+1)]
p 2 R , p 2 RThen:
So far: Points in general position, where no two points havethe same x- or y-coordinate
18
![Page 121: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/121.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Summary
Given: Set P of n points in R2
Construct: Data structures with e�cient range queries of theform R = [x, x0]⇥ [y, y0]
kd-Tree Range Tree
Preprocessing
Space
Query time
! We have seen two alternatives
19
![Page 122: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/122.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Summary
Given: Set P of n points in R2
Construct: Data structures with e�cient range queries of theform R = [x, x0]⇥ [y, y0]
kd-Tree Range Tree
Preprocessing
Space
Query time
O(n log n) O(n log n)
O(n) O(n log n)
O(pn+ k) O(log2 n+ k)
! We have seen two alternatives
19
![Page 123: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/123.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Summary
Given: Set P of n points in R2
Construct: Data structures with e�cient range queries of theform R = [x, x0]⇥ [y, y0]
kd-Tree Range Tree
Preprocessing
Space
Query time
O(n log n) O(n log n)
O(n) O(n log n)
O(pn+ k) O(log2 n+ k)
! We have seen two alternatives
19
![Page 124: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/124.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Summary
Given: Set P of n points in R2
Construct: Data structures with e�cient range queries of theform R = [x, x0]⇥ [y, y0]
kd-Tree Range Tree
Preprocessing
Space
Query time
O(n log n) O(n log n)
O(n) O(n log n)
O(pn+ k) O(log2 n+ k)
! We have seen two alternatives
O(n)
O(log2 n+ k)
19
![Page 125: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/125.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Discussion
How can the data structures generalize to d-dimensions?
20
![Page 126: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/126.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Discussion
How can the data structures generalize to d-dimensions?
kd-Trees function analogously and by dividing the points alternatelyon d coordinates. Space is still O(n), construction O(n log n) and thequery time is O(n1�1/d + k).
20
![Page 127: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/127.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Discussion
How can the data structures generalize to d-dimensions?
kd-Trees function analogously and by dividing the points alternatelyon d coordinates. Space is still O(n), construction O(n log n) and thequery time is O(n1�1/d + k).
Range Trees can be built recursively: the auxiliary search tree on thefirst coordinate is a (d� 1)-dimensional Range Tree. The constructionand space takes O(n logd�1
n) time; a query takes O(logd n+ k)time, and with fractional cascading, O(logd�1
n+ k) time.
20
![Page 128: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/128.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Discussion
How can the data structures generalize to d-dimensions?
kd-Trees function analogously and by dividing the points alternatelyon d coordinates. Space is still O(n), construction O(n log n) and thequery time is O(n1�1/d + k).
Is it possible to query for other objects (e.g., polygons) with thesedata structures?
Range Trees can be built recursively: the auxiliary search tree on thefirst coordinate is a (d� 1)-dimensional Range Tree. The constructionand space takes O(n logd�1
n) time; a query takes O(logd n+ k)time, and with fractional cascading, O(logd�1
n+ k) time.
20
![Page 129: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/129.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Discussion
How can the data structures generalize to d-dimensions?
kd-Trees function analogously and by dividing the points alternatelyon d coordinates. Space is still O(n), construction O(n log n) and thequery time is O(n1�1/d + k).
Is it possible to query for other objects (e.g., polygons) with thesedata structures?
Yes, we can transform any polygon into a point in 4d space (exercise) orwe can use windowing queries (comes in a later lecture).
Range Trees can be built recursively: the auxiliary search tree on thefirst coordinate is a (d� 1)-dimensional Range Tree. The constructionand space takes O(n logd�1
n) time; a query takes O(logd n+ k)time, and with fractional cascading, O(logd�1
n+ k) time.
20
![Page 130: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/130.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Dynamic Range Queries
Question: Can we adapt these data structures for dynamicpoint sets?
Inserting pointsRemoving points
21
![Page 131: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/131.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Dynamic Range Queries
Question: Can we adapt these data structures for dynamicpoint sets?
Inserting pointsRemoving points
1) Divided kd-trees [van Kreveld, Overmars ’91]support updates in O(log n) time, but the query time isO(pn log n+ k)
21
![Page 132: Computational Geometry Lecture Range Searching - KIT](https://reader033.vdocument.in/reader033/viewer/2022051306/62794493a0593c192c2343e6/html5/thumbnails/132.jpg)
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Range Searching
Dynamic Range Queries
Question: Can we adapt these data structures for dynamicpoint sets?
Inserting pointsRemoving points
1) Divided kd-trees [van Kreveld, Overmars ’91]support updates in O(log n) time, but the query time isO(pn log n+ k)
2) Augmented dynamic range trees [Mehlhorn, Naher ’90]support updates in O(log n log log n) time and queries inO(log n log log n+ k) time
21