Orthogonal Range Searching II Carola Wenk 4/13/15 CMPS 3130/6130 - - PowerPoint PPT Presentation

orthogonal range searching ii
SMART_READER_LITE
LIVE PREVIEW

Orthogonal Range Searching II Carola Wenk 4/13/15 CMPS 3130/6130 - - PowerPoint PPT Presentation

CMPS 3130/6130 Computational Geometry Spring 2015 Orthogonal Range Searching II Carola Wenk 4/13/15 CMPS 3130/6130 Computational Geometry 1 Orthogonal range searching Input: A set P of n points in d dimensions Task: Process P into a data


slide-1
SLIDE 1

1 4/13/15

CMPS 3130/6130 Computational Geometry Spring 2015

Orthogonal Range Searching II

Carola Wenk

CMPS 3130/6130 Computational Geometry

slide-2
SLIDE 2

2 4/13/15 CMPS 3130/6130 Computational Geometry

Orthogonal range searching

Input: A set P of n points in d dimensions Task: Process P into a data structure that allows fast orthogonal range queries. Given an axis-aligned box (in 2D, a rectangle)

  • Report on the points inside the box:
  • Are there any points?
  • How many are there?
  • List the points.
slide-3
SLIDE 3

3 4/13/15 CMPS 3130/6130 Computational Geometry

Orthogonal range searching: KD-trees

Let us start in 2D: Input: A set P of n points in 2 dimensions Task: Process P into a data structure that allows fast 2D orthogonal range queries: Report all points in P that lie in the query rectangle [x,x’]  [y,y’]

x x' y y'

slide-4
SLIDE 4

4 4/13/15 CMPS 3130/6130 Computational Geometry

KD trees

Idea: Recursively split P into two sets of the same size, alternatingly along a vertical or horizontal line through the median in x- or y-coordinates.

l1 p5 p4 p2 p7 l2 l3 l4 l5 l6 p6 p9 l7 p10 p8 l8 p1 p3 l9

1

l1

2

l2

3

l3

6

l6

7

l7

4

l4

5

l5

9

l9

8

l8 p1 p2 p3 p4 p5 p6 p7 p8 p9 p10

{p1, p2, p3, p4,p5} {p6, p7, p8, p9,p10} {p1, p2, p3} {p4,p5} {p6, p7, p8} {p9,p10} {p1, p2} {p6, p7}

slide-5
SLIDE 5

5 4/13/15 CMPS 3130/6130 Computational Geometry

BuildKDTree

Idea: Recursively split P into two sets of the same size, alternatingly along a vertical or horizontal line through the median in x- or y-coordinates.

l1 p5 p4 p2 p7 l2 l3 l4 l5 l6 p6 p9 l7 p10 p8 l8 p1 p3 l9

1

l1

2

l2

3

l3

6

l6

7

l7

4

l4

5

l5

9

l9

8

l8 p1 p2 p3 p4 p5 p6 p7 p8 p9 p10

slide-6
SLIDE 6

6 4/13/15 CMPS 3130/6130 Computational Geometry

BuildKDTree Analysis

  • Sort P separately by x- and y-coordinate in advance
  • Use these two sorted lists to find the median
  • Pass sorted lists into the recursive calls
  • Runtime:
  • Storage: O(n), because it is a binary tree on n leaves
slide-7
SLIDE 7

7 4/13/15 CMPS 3130/6130 Computational Geometry

Regions

l1 l2 l3 l6 l7 l4 l5 l9 l8 p1 p2 p3 p4 p5 p6 p7 p8 p9 p10

l1 p5 p4 p2 p7 l2 l3 l4 l5 l6 p6 p9 l7 p10 p8 l8 p1 p3 l9

  • lc(v)=left_child(v)
  • region(lc(v)) = region(v)l(v)left

 Can be computed on the fly in constant time

=v region(v)

slide-8
SLIDE 8

8 4/13/15 CMPS 3130/6130 Computational Geometry

SearchKDTree

l1 l2 l3 l6 l7 l4 l5 l8 p1 p2 p3 p4 p5 p6 p11 p7 p9 p10 l9 p8

10

l10

11

l11 p12 p13

12

l12

l1 p5 p4 p2 p7 l2 l3 l4 l5 l6 p6 p9 l7 p10 p8 l8 p1 p3 l9 p11 p12 p13 l10 l11 l12

How many nodes does a search touch?

slide-9
SLIDE 9

9 4/13/15 CMPS 3130/6130 Computational Geometry

SearchKDTree Analysis

Theorem: A kd-tree for a set of n points in the plane can be constructed in O(n log n) time and uses O(n) space. A rectangular range query can be answered in time, where k = # reported points. (Generalization to d dimensions: Also O(n log n) construction time and O(n) space, but

  • query

time.)

slide-10
SLIDE 10

10 4/13/15 CMPS 3130/6130 Computational Geometry

SearchKDTree Analysis

Proof Sketch:

  • Sum of # visited vertices in ReportSubtree is O(k)
  • # visited vertices that are not in one of the reported

subtrees = O(# regions(v) intersected by a query line)  Consider intersections with a vertical line only. Let Q(n) = # intersected regions in kd-tree of n points whose root contains a vertical splitting line  Q(n) = 2 + 2Q(n/4), for n>1  Q(n) = O( )

l1 l2 l3 l4

l1 l2 l4 l3

slide-11
SLIDE 11

11 4/13/15 CMPS 3130/6130 Computational Geometry

Range trees

Query time: O(k + logd-1 n) to report k points

(uses fractional cascading in the last dimension)

Space: O(n logd – 1 n) Preprocessing time: O(n logd – 1 n)

Summary Orthogonal Range Searching KD-trees

Query time:

  • to report k points

Space: O(n) Preprocessing time: O(n log n)